Skip to content

Commit

Permalink
Merge pull request #2 from JBZoo/develop
Browse files Browse the repository at this point in the history
New tests
  • Loading branch information
SmetDenis committed Jul 31, 2016
2 parents 6807de5 + a7fd5be commit 15f6f6c
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 45 deletions.
5 changes: 5 additions & 0 deletions Makefile
Expand Up @@ -39,6 +39,11 @@ test:
@php ./vendor/phpunit/phpunit/phpunit --configuration ./phpunit.xml.dist
@echo ""

test-x:
@echo -e "\033[0;33m>>> >>> >>> >>> >>> >>> >>> >>> \033[0;30;46m Run unit-tests with XDebug \033[0m"
@php-x ./vendor/phpunit/phpunit/phpunit --configuration ./phpunit.xml.dist --verbose
@echo ""

phpmd:
@echo -e "\033[0;33m>>> >>> >>> >>> >>> >>> >>> >>> \033[0;30;46m Check PHPmd \033[0m"
@php ./vendor/phpmd/phpmd/src/bin/phpmd ./src text \
Expand Down
8 changes: 4 additions & 4 deletions README.md
@@ -1,8 +1,8 @@
# JBZoo Http-Client [![Build Status](https://travis-ci.org/JBZoo/Http-Client.svg?branch=master)](https://travis-ci.org/JBZoo/Http-Client) [![Coverage Status](https://coveralls.io/repos/github/JBZoo/Http-Client/badge.svg?branch=master)](https://coveralls.io/github/JBZoo/Http-Client?branch=master)
# JBZoo Http Client [![Build Status](https://travis-ci.org/JBZoo/Http-Client.svg?branch=master)](https://travis-ci.org/JBZoo/Http-Client) [![Coverage Status](https://coveralls.io/repos/github/JBZoo/Http-Client/badge.svg?branch=master)](https://coveralls.io/github/JBZoo/Http-Client?branch=master)

#### Simple HTTP-client. Usefull wrapper for Guzzle and rmccue/requests
#### Useful wrapper for Guzzle and rmccue/requests

[![License](https://poser.pugx.org/JBZoo/Http-Client/license)](https://packagist.org/packages/JBZoo/Http-Client) [![Latest Stable Version](https://poser.pugx.org/JBZoo/Http-Client/v/stable)](https://packagist.org/packages/JBZoo/Http-Client) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/JBZoo/Http-Client/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/JBZoo/Http-Client/?branch=master)
[![License](https://poser.pugx.org/JBZoo/Http-Client/license)](https://packagist.org/packages/JBZoo/Http-Client) [![Latest Stable Version](https://poser.pugx.org/JBZoo/Http-Client/v/stable)](https://packagist.org/packages/JBZoo/Http-Client) [![Build Status](https://scrutinizer-ci.com/g/JBZoo/Http-Client/badges/build.png?b=master)](https://scrutinizer-ci.com/g/JBZoo/Http-Client/build-status/master)

### Install
```sh
Expand Down Expand Up @@ -31,7 +31,7 @@ $client = new HttpClient([
'driver' => 'auto', // (Auto|Guzzle5|Guzzle6|Rmccue)
'timeout' => 10, // Wait in seconds
'verify' => false, // check cert for SSL
'exceptions' => false, // Show exceptions for
'exceptions' => false, // Show exceptions for statuses 4xx and 5xx
'allow_redirects' => true, // Show real 3xx-header or result?
'max_redirects' => 10, // How much to reirect?
'user_agent' => 'JBZoo/Http-Client v1.x-dev', // Custom UA
Expand Down
8 changes: 4 additions & 4 deletions composer.json
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
4 changes: 0 additions & 4 deletions src/Driver/Auto.php
Expand Up @@ -14,7 +14,6 @@

namespace JBZoo\HttpClient\Driver;

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

Expand All @@ -37,9 +36,6 @@ public function request($url, $args, $method, Options $options)

} elseif (method_exists('\GuzzleHttp\Client', 'createRequest')) {
$client = new Guzzle5($options);

} else {
throw new Exception('JBZoo/HttpClient: Supported Guzzle version driver not found!');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Driver/Guzzle5.php
Expand Up @@ -31,10 +31,10 @@ 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 ? (array)$args : null,
'body' => 'GET' !== $method ? $args : null,
'headers' => $headers,
'exceptions' => $options->isExceptions(),
'timeout' => $options->getTimeout(),
Expand Down
14 changes: 12 additions & 2 deletions src/Driver/Guzzle6.php
Expand Up @@ -31,10 +31,20 @@ 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) {
if (is_array($args)) {
$formParams = $args;
} else {
$body = $args;
}
}

$httpResult = $client->request($method, $url, array(
'form_params' => 'GET' !== $method ? (array)$args : null,
'form_params' => $formParams,
'body' => $body,
'headers' => $headers,
'connect_timeout' => $options->getTimeout(),
'timeout' => $options->getTimeout(),
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Rmccue.php
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
2 changes: 1 addition & 1 deletion src/HttpClient.php
Expand Up @@ -64,7 +64,7 @@ public function request($url, $args = null, $method = Options::DEFAULT_METHOD, a

} catch (\Exception $e) {

if ($options->get('exceptions', Options::DEFAULT_EXCEPTIONS, 'bool')) {
if ($options->isExceptions()) {
throw new Exception($e->getMessage(), $e->getCode(), $e);

} else {
Expand Down
8 changes: 4 additions & 4 deletions src/Options.php
Expand Up @@ -35,7 +35,7 @@ class Options extends JSON
* @var array
*/
protected $_default = array(
'auth' => array('', ''),
'auth' => false,
'headers' => array(),
'driver' => self::DEFAULT_DRIVER,
'timeout' => self::DEFAULT_TIMEOUT,
Expand Down Expand Up @@ -64,7 +64,7 @@ public function __construct($data = array())
*/
public function getAuth()
{
return $this->get('auth', array('', ''));
return $this->get('auth', false);
}

/**
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})";
}
}
33 changes: 33 additions & 0 deletions tests/DriverAutoTest.php
@@ -0,0 +1,33 @@
<?php
/**
* JBZoo Http-Client
*
* This file is part of the JBZoo CCK package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Http-Client
* @license MIT
* @copyright Copyright (C) JBZoo.com, All rights reserved.
* @link https://github.com/JBZoo/Http-Client
*/

namespace JBZoo\PHPUnit;

/**
* Class DriverAutoTest
* @package JBZoo\PHPUnit
*/
class DriverAutoTest extends DriverTest
{
protected $_driver = 'Auto';

protected function setUp()
{
parent::setUp();

if ($this->_isPHP53()) {
$this->_methods = array('GET', 'POST', 'PATCH', 'PUT'); // TODO add 'DELETE'
}
}
}
26 changes: 26 additions & 0 deletions tests/DriverRmccueTest.php
@@ -0,0 +1,26 @@
<?php
/**
* JBZoo Http-Client
*
* This file is part of the JBZoo CCK package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Http-Client
* @license MIT
* @copyright Copyright (C) JBZoo.com, All rights reserved.
* @link https://github.com/JBZoo/Http-Client
*/

namespace JBZoo\PHPUnit;

/**
* Class RmccueDriverTest
* @package JBZoo\PHPUnit
*/
class RmccueDriverTest extends DriverTest
{
protected $_driver = 'Rmccue';

protected $_methods = array('GET', 'POST', 'PATCH', 'PUT'); // TODO add 'DELETE'
}

0 comments on commit 15f6f6c

Please sign in to comment.