Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shulard committed Aug 31, 2016
1 parent 930c0fd commit 68d0e6d
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
*/
class ClientFactory
{
protected function __construct()
{
//Just a factory helper, can't be instantiated
}

/**
* Create a new client instance
* @param string $url The root URL used by the client
Expand Down
28 changes: 28 additions & 0 deletions test/units/Transport/ClientFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* This file is part of the bee4/httpclient package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Bee4 2015
* @author Stephane HULARD <[email protected]>
* @package Bee4\Test\Transport
*/

namespace Bee4\Test\Transport;

use Bee4\Transport\ClientFactory as SUT;
use Bee4\Transport as LUT;

/**
* Check behaviour of ClientFactory helper
* @package Bee4\Test\Transport
*/
class ClientFactoryTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
$client = SUT::create();
$this->assertInstanceOf(LUT\MagicHandler::class, $client);
}
}
66 changes: 66 additions & 0 deletions test/units/Transport/MagicHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* This file is part of the bee4/httpclient package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Bee4 2015
* @author Stephane HULARD <[email protected]>
* @package Bee4\Test\Transport
*/

namespace Bee4\Test\Transport;

use Bee4\PHPUnit\HttpClientTestCase;
use Bee4\Transport\MagicHandler as SUT;
use Bee4\Transport as LUT;

/**
* Check behaviour of ClientFactory helper
* @package Bee4\Test\Transport
*/
class MagicHandlerTest extends HttpClientTestCase
{
public function retrieveParameters()
{
return [
['get', 'http://localhost'],
['post', 'http://localhost'],
['put', 'http://localhost', ['Content-Type' => 'text/html']],
['delete', 'http://localhost'],
['head', 'http://localhost', ['Accept' => 'application/json']],
];
}

/**
* @dataProvider retrieveParameters
*/
public function testMagicCall($method, $url, $headers = [])
{
$client = new LUT\Client();
$magic = new SUT($client);

$result = call_user_func([$magic, $method], $url, $headers);

$this->assertInstanceOf(LUT\Message\Request\AbstractRequest::class, $result);
$class = substr(get_class($result), strrpos(get_class($result), '\\')+1);
$this->assertEquals(ucfirst($method), $class);

foreach($headers as $name => $value) {
$this->assertEquals($value, $result->getHeader($name));
}
}

public function testSend()
{
$config = new LUT\Configuration\Configuration;
$config->url = self::getBaseUrl();
$client = new LUT\Client('', $config);
$magic = new SUT($client);

$request = $magic->get(self::getBaseUrl());
$response = $magic->send($request);

$this->assertInstanceOf(LUT\Message\Response::class, $response);
}
}

0 comments on commit 68d0e6d

Please sign in to comment.