1 | <?php |
||
25 | class ProfilingTest extends TestCase |
||
26 | { |
||
27 | /** |
||
28 | * @var Collector |
||
29 | */ |
||
30 | private $collector; |
||
31 | |||
32 | /** |
||
33 | * @var Formatter |
||
34 | */ |
||
35 | private $formatter; |
||
36 | |||
37 | /** |
||
38 | * @var Stopwatch |
||
39 | */ |
||
40 | private $stopwatch; |
||
41 | |||
42 | public function setUp(): void |
||
43 | { |
||
44 | $this->collector = new Collector([]); |
||
|
|||
45 | $this->formatter = new Formatter(new FullHttpMessageFormatter(), new CurlCommandFormatter()); |
||
46 | $this->stopwatch = new Stopwatch(); |
||
47 | } |
||
48 | |||
49 | public function testProfilingWithCachePlugin(): void |
||
50 | { |
||
51 | $client = $this->createClient([ |
||
52 | new Plugin\CachePlugin(new ArrayAdapter(), StreamFactoryDiscovery::find(), [ |
||
53 | 'respect_response_cache_directives' => [], |
||
54 | 'default_ttl' => 86400, |
||
55 | ]), |
||
56 | ]); |
||
57 | |||
58 | $client->sendRequest(new Request('GET', 'https://example.com')); |
||
59 | $client->sendRequest(new Request('GET', 'https://example.com')); |
||
60 | |||
61 | $this->assertCount(2, $this->collector->getStacks()); |
||
62 | $stack = $this->collector->getStacks()[1]; |
||
63 | $this->assertEquals('GET', $stack->getRequestMethod()); |
||
64 | $this->assertEquals('https', $stack->getRequestScheme()); |
||
65 | $this->assertEquals('/', $stack->getRequestTarget()); |
||
66 | $this->assertEquals('example.com', $stack->getRequestHost()); |
||
67 | } |
||
68 | |||
69 | public function testProfilingWhenPluginThrowException(): void |
||
70 | { |
||
71 | $client = $this->createClient([ |
||
72 | new ExceptionThrowerPlugin(), |
||
73 | ]); |
||
74 | |||
75 | try { |
||
76 | $this->expectException(\Exception::class); |
||
77 | $client->sendRequest(new Request('GET', 'https://example.com')); |
||
78 | } finally { |
||
79 | $this->assertCount(1, $this->collector->getStacks()); |
||
80 | $stack = $this->collector->getStacks()[0]; |
||
81 | $this->assertEquals('GET', $stack->getRequestMethod()); |
||
82 | $this->assertEquals('https', $stack->getRequestScheme()); |
||
83 | $this->assertEquals('/', $stack->getRequestTarget()); |
||
84 | $this->assertEquals('example.com', $stack->getRequestHost()); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | public function testProfiling(): void |
||
106 | |||
107 | private function createClient(array $plugins, $clientName = 'Acme', array $clientOptions = []) |
||
121 | } |
||
122 | |||
123 | class ExceptionThrowerPlugin implements Plugin |
||
124 | { |
||
132 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.