Test sending body with Client
This commit is contained in:
parent
832e849875
commit
3d44d1a3f5
|
|
@ -21,6 +21,7 @@
|
|||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"fzaninotto/faker": "1.5.*@dev",
|
||||
"phpunit/phpunit": "4.1.*",
|
||||
"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",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "51e65a31711f28ae591ec9f4efb2bfac",
|
||||
"hash": "5f2174a14a32c9abc7bca48bc8557cb1",
|
||||
"packages": [],
|
||||
"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",
|
||||
"version": "2.0.9",
|
||||
|
|
@ -756,6 +806,7 @@
|
|||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {
|
||||
"fzaninotto/faker": 20,
|
||||
"pjdietz/shamserver": 20
|
||||
},
|
||||
"platform": {
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ class Request extends Message implements RequestInterface
|
|||
}
|
||||
|
||||
// http://www.php.net/manual/en/function.getallheaders.php#84262
|
||||
$headers = '';
|
||||
$headers = [];
|
||||
foreach ($_SERVER as $name => $value) {
|
||||
if (substr($name, 0, 5) === 'HTTP_') {
|
||||
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace pjdietz\WellRESTed\Test;
|
||||
|
||||
use Faker\Factory;
|
||||
use pjdietz\ShamServer\ShamServer;
|
||||
use pjdietz\WellRESTed\Client;
|
||||
|
||||
|
|
@ -10,7 +11,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* @dataProvider httpMethodProvider
|
||||
*/
|
||||
public function testCheckHttpMethod($method)
|
||||
public function testSendHttpMethod($method)
|
||||
{
|
||||
$host = "localhost";
|
||||
$port = 8080;
|
||||
|
|
@ -18,7 +19,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$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())
|
||||
->method("getUri")
|
||||
->will($this->returnValue("http://$host:$port"));
|
||||
|
|
@ -55,7 +56,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* @dataProvider httpHeaderProvider
|
||||
*/
|
||||
public function testCheckHttpHeaders($headerKey, $headerValue)
|
||||
public function testSendHttpHeaders($headerKey, $headerValue)
|
||||
{
|
||||
$host = "localhost";
|
||||
$port = 8080;
|
||||
|
|
@ -63,7 +64,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$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())
|
||||
->method("getUri")
|
||||
->will($this->returnValue("http://$host:$port"));
|
||||
|
|
@ -93,4 +94,47 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||
["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