|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the bee4/httpclient package. |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright Bee4 2015 |
|
8
|
|
|
* @author Stephane HULARD <[email protected]> |
|
9
|
|
|
* @package Bee4\Test\Transport |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Bee4\Test\Transport; |
|
13
|
|
|
|
|
14
|
|
|
use Bee4\PHPUnit\HttpClientTestCase; |
|
15
|
|
|
use Bee4\Transport\MagicHandler as SUT; |
|
16
|
|
|
use Bee4\Transport as LUT; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Check behaviour of ClientFactory helper |
|
20
|
|
|
* @package Bee4\Test\Transport |
|
21
|
|
|
*/ |
|
22
|
|
|
class MagicHandlerTest extends HttpClientTestCase |
|
23
|
|
|
{ |
|
24
|
|
|
public function retrieveParameters() |
|
25
|
|
|
{ |
|
26
|
|
|
return [ |
|
27
|
|
|
['get', 'http://localhost'], |
|
28
|
|
|
['post', 'http://localhost'], |
|
29
|
|
|
['put', 'http://localhost', ['Content-Type' => 'text/html']], |
|
30
|
|
|
['delete', 'http://localhost'], |
|
31
|
|
|
['head', 'http://localhost', ['Accept' => 'application/json']], |
|
32
|
|
|
]; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @dataProvider retrieveParameters |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testMagicCall($method, $url, $headers = []) |
|
39
|
|
|
{ |
|
40
|
|
|
$client = new LUT\Client(); |
|
41
|
|
|
$magic = new SUT($client); |
|
42
|
|
|
|
|
43
|
|
|
$result = call_user_func([$magic, $method], $url, $headers); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertInstanceOf(LUT\Message\Request\AbstractRequest::class, $result); |
|
46
|
|
|
$class = substr(get_class($result), strrpos(get_class($result), '\\')+1); |
|
47
|
|
|
$this->assertEquals(ucfirst($method), $class); |
|
48
|
|
|
|
|
49
|
|
|
foreach($headers as $name => $value) { |
|
50
|
|
|
$this->assertEquals($value, $result->getHeader($name)); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testSend() |
|
55
|
|
|
{ |
|
56
|
|
|
$config = new LUT\Configuration\Configuration; |
|
57
|
|
|
$config->url = self::getBaseUrl(); |
|
58
|
|
|
$client = new LUT\Client('', $config); |
|
59
|
|
|
$magic = new SUT($client); |
|
60
|
|
|
|
|
61
|
|
|
$request = $magic->get(self::getBaseUrl()); |
|
62
|
|
|
$response = $magic->send($request); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertInstanceOf(LUT\Message\Response::class, $response); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|