1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Http\HttplugBundle\Tests\Unit\Discovery; |
6
|
|
|
|
7
|
|
|
use Http\Client\HttpAsyncClient; |
8
|
|
|
use Http\Client\HttpClient; |
9
|
|
|
use Http\HttplugBundle\Discovery\ConfiguredClientsStrategy; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
class ConfiguredClientsStrategyTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testGetCandidates(): void |
15
|
|
|
{ |
16
|
|
|
$httpClient = $this->getMockBuilder(HttpClient::class)->getMock(); |
17
|
|
|
$httpAsyncClient = $this->getMockBuilder(HttpAsyncClient::class)->getMock(); |
18
|
|
|
$strategy = new ConfiguredClientsStrategy($httpClient, $httpAsyncClient); |
|
|
|
|
19
|
|
|
|
20
|
|
|
$candidates = $strategy::getCandidates(HttpClient::class); |
21
|
|
|
$candidate = array_shift($candidates); |
22
|
|
|
$this->assertEquals($httpClient, $candidate['class']()); |
23
|
|
|
|
24
|
|
|
$candidates = $strategy::getCandidates(HttpAsyncClient::class); |
25
|
|
|
$candidate = array_shift($candidates); |
26
|
|
|
$this->assertEquals($httpAsyncClient, $candidate['class']()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testGetCandidatesEmpty(): void |
30
|
|
|
{ |
31
|
|
|
$strategy = new ConfiguredClientsStrategy(null, null); |
32
|
|
|
|
33
|
|
|
$candidates = $strategy::getCandidates(HttpClient::class); |
34
|
|
|
$this->assertEquals([], $candidates); |
35
|
|
|
|
36
|
|
|
$candidates = $strategy::getCandidates(HttpAsyncClient::class); |
37
|
|
|
$this->assertEquals([], $candidates); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
public function testGetCandidatesEmptyAsync(): void |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
$httpClient = $this->getMockBuilder(HttpClient::class)->getMock(); |
43
|
|
|
$strategy = new ConfiguredClientsStrategy($httpClient, null); |
|
|
|
|
44
|
|
|
|
45
|
|
|
$candidates = $strategy::getCandidates(HttpClient::class); |
46
|
|
|
$candidate = array_shift($candidates); |
47
|
|
|
$this->assertEquals($httpClient, $candidate['class']()); |
48
|
|
|
|
49
|
|
|
$candidates = $strategy::getCandidates(HttpAsyncClient::class); |
50
|
|
|
$this->assertEquals([], $candidates); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function testGetCandidatesEmptySync(): void |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$httpAsyncClient = $this->getMockBuilder(HttpAsyncClient::class)->getMock(); |
56
|
|
|
$strategy = new ConfiguredClientsStrategy(null, $httpAsyncClient); |
|
|
|
|
57
|
|
|
|
58
|
|
|
$candidates = $strategy::getCandidates(HttpClient::class); |
59
|
|
|
$this->assertEquals([], $candidates); |
60
|
|
|
|
61
|
|
|
$candidates = $strategy::getCandidates(HttpAsyncClient::class); |
62
|
|
|
$candidate = array_shift($candidates); |
63
|
|
|
$this->assertEquals($httpAsyncClient, $candidate['class']()); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: