1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Http\HttplugBundle\Tests\Unit\Collector; |
6
|
|
|
|
7
|
|
|
use Http\Client\HttpClient; |
8
|
|
|
use Http\HttplugBundle\ClientFactory\ClientFactory; |
9
|
|
|
use Http\HttplugBundle\Collector\Collector; |
10
|
|
|
use Http\HttplugBundle\Collector\Formatter; |
11
|
|
|
use Http\HttplugBundle\Collector\ProfileClient; |
12
|
|
|
use Http\HttplugBundle\Collector\ProfileClientFactory; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Symfony\Component\Stopwatch\Stopwatch; |
15
|
|
|
|
16
|
|
|
class ProfileClientFactoryTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var Collector |
20
|
|
|
*/ |
21
|
|
|
private $collector; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Formatter |
25
|
|
|
*/ |
26
|
|
|
private $formatter; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Stopwatch |
30
|
|
|
*/ |
31
|
|
|
private $stopwatch; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var HttpClient |
35
|
|
|
*/ |
36
|
|
|
private $client; |
37
|
|
|
|
38
|
|
|
public function setUp(): void |
39
|
|
|
{ |
40
|
|
|
$this->collector = $this->getMockBuilder(Collector::class)->disableOriginalConstructor()->getMock(); |
|
|
|
|
41
|
|
|
$this->formatter = $this->getMockBuilder(Formatter::class)->disableOriginalConstructor()->getMock(); |
|
|
|
|
42
|
|
|
$this->stopwatch = $this->getMockBuilder(Stopwatch::class)->getMock(); |
|
|
|
|
43
|
|
|
$this->client = $this->getMockBuilder(HttpClient::class)->getMock(); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testCreateClientFromClientFactory(): void |
47
|
|
|
{ |
48
|
|
|
$factory = $this->getMockBuilder(ClientFactory::class)->getMock(); |
49
|
|
|
$factory->method('createClient')->willReturn($this->client); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$subject = new ProfileClientFactory($factory, $this->collector, $this->formatter, $this->stopwatch); |
|
|
|
|
52
|
|
|
|
53
|
|
|
$this->assertInstanceOf(ProfileClient::class, $subject->createClient()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testCreateClientFromCallable(): void |
57
|
|
|
{ |
58
|
|
|
$factory = function ($config) { |
|
|
|
|
59
|
|
|
return $this->client; |
60
|
|
|
}; |
61
|
|
|
|
62
|
|
|
$subject = new ProfileClientFactory($factory, $this->collector, $this->formatter, $this->stopwatch); |
63
|
|
|
|
64
|
|
|
$this->assertInstanceOf(ProfileClient::class, $subject->createClient()); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..