Passed
Pull Request — master (#306)
by Tobias
02:05
created

ConfigurationTest::testWrongOptionInSendRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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))
0 ignored issues
show
Bug introduced by
$this->anything() of type PHPUnit\Framework\Constraint\IsAnything is incompatible with the type array expected by parameter $arguments of PHPUnit\Framework\MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
            ->with(/** @scrutinizer ignore-type */ $this->anything(), $this->equalTo($options))
Loading history...
Bug introduced by
$this->equalTo($options) of type PHPUnit\Framework\Constraint\IsEqual is incompatible with the type array expected by parameter $arguments of PHPUnit\Framework\MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
            ->with($this->anything(), /** @scrutinizer ignore-type */ $this->equalTo($options))
Loading history...
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