Skip to content

Commit

Permalink
fix payload conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Jul 31, 2016
1 parent 3397bce commit 4572ea3
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 18 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
}
],
"require" : {
"php" : ">=5.3",
"jbzoo/data" : "^1.4",
"rmccue/requests" : "^1.6"
"php" : ">=5.3",
"jbzoo/data" : "^1.4",
"rmccue/requests" : "^1.6"
},
"suggest": {
"suggest" : {
"guzzlehttp/guzzle" : "For PHP 5.4+ please use versions ^5.3|^6.2"
},
"require-dev" : {
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Guzzle5.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function request($url, $args, $method, Options $options)
$client = new Client();

$headers = $options->getHeaders();
$headers['User-Agent'] = $options->getUserAgent();
$headers['User-Agent'] = $options->getUserAgent('Guzzle5');

$httpRequest = $client->createRequest($method, $url, array(
'body' => 'GET' !== $method ? $args : null,
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Guzzle6.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function request($url, $args, $method, Options $options)
$client = new Client();

$headers = $options->getHeaders();
$headers['User-Agent'] = $options->getUserAgent();
$headers['User-Agent'] = $options->getUserAgent('Guzzle6');

$body = $formParams = null;
if ('GET' !== $method) {
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Rmccue.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function request($url, $args, $method, Options $options)
'verify' => $options->isVerify(),
'follow_redirects' => $options->isAllowRedirects(),
'redirects' => $options->getMaxRedirects(),
'useragent' => $options->getUserAgent(),
'useragent' => $options->getUserAgent('Rmccue'),
'auth' => $options->getAuth(),
));

Expand Down
6 changes: 3 additions & 3 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Options extends JSON
* @var array
*/
protected $_default = array(
'auth' => array('', ''),
'auth' => null,
'headers' => array(),
'driver' => self::DEFAULT_DRIVER,
'timeout' => self::DEFAULT_TIMEOUT,
Expand Down Expand Up @@ -126,8 +126,8 @@ public function getMaxRedirects()
/**
* @return string
*/
public function getUserAgent()
public function getUserAgent($suffix)
{
return $this->get('user_agent', self::DEFAULT_USER_AGENT);
return $this->get('user_agent', self::DEFAULT_USER_AGENT) . " ({$suffix})";
}
}
4 changes: 1 addition & 3 deletions tests/DriverAutoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

namespace JBZoo\PHPUnit;

use JBZoo\Utils\Env;

/**
* Class DriverAutoTest
* @package JBZoo\PHPUnit
Expand All @@ -28,7 +26,7 @@ protected function setUp()
{
parent::setUp();

if (version_compare(Env::getVersion(), '5.4', '<')) {
if ($this->_isPHP53()) {
$this->_methods = array('get', 'post', 'post', 'put');
}
}
Expand Down
27 changes: 22 additions & 5 deletions tests/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use JBZoo\HttpClient\HttpClient;
use JBZoo\HttpClient\Options;
use JBZoo\Utils\Env;
use JBZoo\Utils\Url;

/**
Expand All @@ -34,6 +35,14 @@ abstract class DriverTest extends PHPUnit
*/
protected $_methods = array('get', 'post', 'post', 'put', 'delete');

/**
* @return bool
*/
protected function _isPHP53()
{
return version_compare(Env::getVersion(), '5.4', '<');
}

/**
* @param array $options
* @return HttpClient
Expand Down Expand Up @@ -67,16 +76,24 @@ public function testBinaryData()

public function testPOSTPayload()
{
if ($this->_isPHP53()) {
skip();
}

$uniq = uniqid();
$payload = json_encode(array('key' => $uniq));
$url = 'http://httpbin.org/post?key=value';
$url = 'http://mockbin.org/request?key=value';

$result = $this->_getClient()->request($url, $payload, 'post');
$result = $this->_getClient()->request($url, $payload, 'post', array(
'headers' => array(//'Content-Type'
)
));

$body = $result->getJSON();

isSame('', $body->find('form.' . $payload));
isSame('value', $body->find('args.key'));
isSame($payload, $body->find('postData.text'));
isSame('value', $body->find('queryString.key'));
isSame('POST', $body->find('method'));
}

public function testAllMethods()
Expand Down Expand Up @@ -140,7 +157,7 @@ public function testUserAgent()

isSame(200, $result->code);
isContain('application/json', $result->getHeader('Content-Type'));
isSame(Options::DEFAULT_USER_AGENT, $body->find('user-agent'));
isContain(Options::DEFAULT_USER_AGENT . ' (', $body->find('user-agent'));
}

public function testPost()
Expand Down

0 comments on commit 4572ea3

Please sign in to comment.