|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Buzz\Test\Functional; |
|
6
|
|
|
|
|
7
|
|
|
use Buzz\Browser; |
|
8
|
|
|
use Buzz\Client\BuzzClientInterface; |
|
9
|
|
|
use Buzz\Client\Curl; |
|
10
|
|
|
use Buzz\Client\FileGetContents; |
|
11
|
|
|
use Buzz\Client\MultiCurl; |
|
12
|
|
|
use Buzz\Exception\InvalidArgumentException; |
|
13
|
|
|
use Nyholm\Psr7\Request; |
|
14
|
|
|
use Nyholm\Psr7\Response; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
17
|
|
|
|
|
18
|
|
|
class ConfigurationTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testBrowserPassingOption() |
|
21
|
|
|
{ |
|
22
|
|
|
$request = new Request('GET', '/'); |
|
23
|
|
|
$options = ['foobar' => true, 'timeout' => 4]; |
|
24
|
|
|
|
|
25
|
|
|
$client = $this->getMockBuilder(BuzzClientInterface::class) |
|
26
|
|
|
->setMethods(['sendRequest']) |
|
27
|
|
|
->getMock(); |
|
28
|
|
|
|
|
29
|
|
|
$client->expects($this->once()) |
|
30
|
|
|
->method('sendRequest') |
|
31
|
|
|
->with($this->anything(), $this->equalTo($options)) |
|
|
|
|
|
|
32
|
|
|
->willReturn(new Response()); |
|
33
|
|
|
|
|
34
|
|
|
$browser = new Browser($client); |
|
35
|
|
|
$browser->sendRequest($request, $options); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @dataProvider clientClassProvider |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testOptionInConstructor($class) |
|
42
|
|
|
{ |
|
43
|
|
|
$client = new $class(['timeout' => 4]); |
|
44
|
|
|
$this->assertInstanceOf($class, $client); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @dataProvider clientClassProvider |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testOptionInSendRequest($class) |
|
51
|
|
|
{ |
|
52
|
|
|
if (!isset($_SERVER['BUZZ_TEST_SERVER']) || empty($_SERVER['BUZZ_TEST_SERVER'])) { |
|
53
|
|
|
$this->markTestSkipped('The test server is not configured.'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$client = new $class(); |
|
57
|
|
|
|
|
58
|
|
|
$response = $client->sendRequest(new Request('GET', $_SERVER['BUZZ_TEST_SERVER']), ['timeout' => 4]); |
|
59
|
|
|
$this->assertInstanceOf(ResponseInterface::class, $response); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @dataProvider clientClassProvider |
|
64
|
|
|
*/ |
|
65
|
|
|
public function testWrongOptionInConstructor($class) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
68
|
|
|
new $class(['foobar' => true]); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @dataProvider clientClassProvider |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testWrongOptionInSendRequest($class) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
77
|
|
|
$client = new $class(); |
|
78
|
|
|
|
|
79
|
|
|
$client->sendRequest(new Request('GET', '/'), ['foobar' => true]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function clientClassProvider() |
|
83
|
|
|
{ |
|
84
|
|
|
yield [FileGetContents::class]; |
|
85
|
|
|
yield [MultiCurl::class]; |
|
86
|
|
|
yield [Curl::class]; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|