Test sending body with Client
This commit is contained in:
parent
832e849875
commit
3d44d1a3f5
|
|
@ -21,6 +21,7 @@
|
||||||
"php": ">=5.3.0"
|
"php": ">=5.3.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"fzaninotto/faker": "1.5.*@dev",
|
||||||
"phpunit/phpunit": "4.1.*",
|
"phpunit/phpunit": "4.1.*",
|
||||||
"pjdietz/shamserver": "dev-master"
|
"pjdietz/shamserver": "dev-master"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,59 @@
|
||||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"hash": "51e65a31711f28ae591ec9f4efb2bfac",
|
"hash": "5f2174a14a32c9abc7bca48bc8557cb1",
|
||||||
"packages": [],
|
"packages": [],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
|
{
|
||||||
|
"name": "fzaninotto/faker",
|
||||||
|
"version": "dev-master",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/fzaninotto/Faker.git",
|
||||||
|
"reference": "c48f30549b1ec508a74141a833757ca1e0d9ca53"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/c48f30549b1ec508a74141a833757ca1e0d9ca53",
|
||||||
|
"reference": "c48f30549b1ec508a74141a833757ca1e0d9ca53",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "~4.0",
|
||||||
|
"squizlabs/php_codesniffer": "~1.5"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.5.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-0": {
|
||||||
|
"Faker": "src/",
|
||||||
|
"Faker\\PHPUnit": "test/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "François Zaninotto"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Faker is a PHP library that generates fake data for you.",
|
||||||
|
"keywords": [
|
||||||
|
"data",
|
||||||
|
"faker",
|
||||||
|
"fixtures"
|
||||||
|
],
|
||||||
|
"time": "2014-07-17 07:25:43"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/php-code-coverage",
|
"name": "phpunit/php-code-coverage",
|
||||||
"version": "2.0.9",
|
"version": "2.0.9",
|
||||||
|
|
@ -756,6 +806,7 @@
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"stability-flags": {
|
"stability-flags": {
|
||||||
|
"fzaninotto/faker": 20,
|
||||||
"pjdietz/shamserver": 20
|
"pjdietz/shamserver": 20
|
||||||
},
|
},
|
||||||
"platform": {
|
"platform": {
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ class Request extends Message implements RequestInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://www.php.net/manual/en/function.getallheaders.php#84262
|
// http://www.php.net/manual/en/function.getallheaders.php#84262
|
||||||
$headers = '';
|
$headers = [];
|
||||||
foreach ($_SERVER as $name => $value) {
|
foreach ($_SERVER as $name => $value) {
|
||||||
if (substr($name, 0, 5) === 'HTTP_') {
|
if (substr($name, 0, 5) === 'HTTP_') {
|
||||||
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
|
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace pjdietz\WellRESTed\Test;
|
namespace pjdietz\WellRESTed\Test;
|
||||||
|
|
||||||
|
use Faker\Factory;
|
||||||
use pjdietz\ShamServer\ShamServer;
|
use pjdietz\ShamServer\ShamServer;
|
||||||
use pjdietz\WellRESTed\Client;
|
use pjdietz\WellRESTed\Client;
|
||||||
|
|
||||||
|
|
@ -10,7 +11,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* @dataProvider httpMethodProvider
|
* @dataProvider httpMethodProvider
|
||||||
*/
|
*/
|
||||||
public function testCheckHttpMethod($method)
|
public function testSendHttpMethod($method)
|
||||||
{
|
{
|
||||||
$host = "localhost";
|
$host = "localhost";
|
||||||
$port = 8080;
|
$port = 8080;
|
||||||
|
|
@ -18,7 +19,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$server = new ShamServer($host, $port, $script);
|
$server = new ShamServer($host, $port, $script);
|
||||||
|
|
||||||
$rqst = $this->getMockBuilder('pjdietz\WellRESTed\Request')->getMock();
|
$rqst = $this->getMockBuilder('pjdietz\WellRESTed\Interfaces\RequestInterface')->getMock();
|
||||||
$rqst->expects($this->any())
|
$rqst->expects($this->any())
|
||||||
->method("getUri")
|
->method("getUri")
|
||||||
->will($this->returnValue("http://$host:$port"));
|
->will($this->returnValue("http://$host:$port"));
|
||||||
|
|
@ -55,7 +56,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* @dataProvider httpHeaderProvider
|
* @dataProvider httpHeaderProvider
|
||||||
*/
|
*/
|
||||||
public function testCheckHttpHeaders($headerKey, $headerValue)
|
public function testSendHttpHeaders($headerKey, $headerValue)
|
||||||
{
|
{
|
||||||
$host = "localhost";
|
$host = "localhost";
|
||||||
$port = 8080;
|
$port = 8080;
|
||||||
|
|
@ -63,7 +64,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$server = new ShamServer($host, $port, $script);
|
$server = new ShamServer($host, $port, $script);
|
||||||
|
|
||||||
$rqst = $this->getMockBuilder('pjdietz\WellRESTed\Request')->getMock();
|
$rqst = $this->getMockBuilder('pjdietz\WellRESTed\Interfaces\RequestInterface')->getMock();
|
||||||
$rqst->expects($this->any())
|
$rqst->expects($this->any())
|
||||||
->method("getUri")
|
->method("getUri")
|
||||||
->will($this->returnValue("http://$host:$port"));
|
->will($this->returnValue("http://$host:$port"));
|
||||||
|
|
@ -93,4 +94,47 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||||
["Accept-Charset", "utf-8"]
|
["Accept-Charset", "utf-8"]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider bodyProvider
|
||||||
|
*/
|
||||||
|
public function testSendBody($body)
|
||||||
|
{
|
||||||
|
$host = "localhost";
|
||||||
|
$port = 8080;
|
||||||
|
$script = realpath(__DIR__ . "/sham-routers/body.php");
|
||||||
|
$server = new ShamServer($host, $port, $script);
|
||||||
|
|
||||||
|
$rqst = $this->getMockBuilder('pjdietz\WellRESTed\Interfaces\RequestInterface')->getMock();
|
||||||
|
$rqst->expects($this->any())
|
||||||
|
->method("getUri")
|
||||||
|
->will($this->returnValue("http://$host:$port"));
|
||||||
|
$rqst->expects($this->any())
|
||||||
|
->method("getMethod")
|
||||||
|
->will($this->returnValue("POST"));
|
||||||
|
$rqst->expects($this->any())
|
||||||
|
->method("getPort")
|
||||||
|
->will($this->returnValue($port));
|
||||||
|
$rqst->expects($this->any())
|
||||||
|
->method("getHeaders")
|
||||||
|
->will($this->returnValue(array()));
|
||||||
|
$rqst->expects($this->any())
|
||||||
|
->method("getBody")
|
||||||
|
->will($this->returnValue($body));
|
||||||
|
|
||||||
|
$client = new Client();
|
||||||
|
$resp = $client->request($rqst);
|
||||||
|
$this->assertEquals($body, $resp->getBody());
|
||||||
|
$server->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function bodyProvider()
|
||||||
|
{
|
||||||
|
$faker = Factory::create();
|
||||||
|
return [
|
||||||
|
[$faker->text()],
|
||||||
|
[$faker->text()],
|
||||||
|
[$faker->text()]
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
print file_get_contents("php://input");
|
||||||
|
exit;
|
||||||
Loading…
Reference in New Issue