|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Profiler\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Profiler\Target; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @group profile |
|
11
|
|
|
*/ |
|
12
|
|
|
final class TargetTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Data provider for {@see testFilterMessages()} |
|
16
|
|
|
* @return array test data |
|
17
|
|
|
*/ |
|
18
|
|
|
public function dataProviderFilterMessages(): array |
|
19
|
|
|
{ |
|
20
|
|
|
return [ |
|
21
|
|
|
[ |
|
22
|
|
|
[['category' => 'foo']], |
|
23
|
|
|
[], |
|
24
|
|
|
[], |
|
25
|
|
|
[['category' => 'foo']], |
|
26
|
|
|
], |
|
27
|
|
|
[ |
|
28
|
|
|
[['category' => 'foo']], |
|
29
|
|
|
['foo'], |
|
30
|
|
|
[], |
|
31
|
|
|
[['category' => 'foo']], |
|
32
|
|
|
], |
|
33
|
|
|
[ |
|
34
|
|
|
[['category' => 'foo']], |
|
35
|
|
|
['some'], |
|
36
|
|
|
[], |
|
37
|
|
|
[], |
|
38
|
|
|
], |
|
39
|
|
|
[ |
|
40
|
|
|
[['category' => 'foo']], |
|
41
|
|
|
[], |
|
42
|
|
|
['foo'], |
|
43
|
|
|
[], |
|
44
|
|
|
], |
|
45
|
|
|
[ |
|
46
|
|
|
[['category' => 'foo']], |
|
47
|
|
|
[], |
|
48
|
|
|
['some'], |
|
49
|
|
|
[['category' => 'foo']], |
|
50
|
|
|
], |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @dataProvider dataProviderFilterMessages |
|
56
|
|
|
* |
|
57
|
|
|
* @covers \Yiisoft\Profiler\Target::filterMessages() |
|
58
|
|
|
* |
|
59
|
|
|
* @param array $messages |
|
60
|
|
|
* @param array $categories |
|
61
|
|
|
* @param array $except |
|
62
|
|
|
* @param array $expected |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testFilterMessages(array $messages, array $categories, array $except, array $expected): void |
|
65
|
|
|
{ |
|
66
|
|
|
/* @var $target Target|\PHPUnit_Framework_MockObject_MockObject */ |
|
67
|
|
|
$target = $this->getMockBuilder(Target::class)->getMockForAbstractClass(); |
|
68
|
|
|
|
|
69
|
|
|
$target->categories = $categories; |
|
70
|
|
|
$target->except = $except; |
|
71
|
|
|
|
|
72
|
|
|
$this->assertEquals($expected, $this->invokeMethod($target, 'filterMessages', [$messages])); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @depends testFilterMessages |
|
77
|
|
|
*/ |
|
78
|
|
|
public function testEnabled(): void |
|
79
|
|
|
{ |
|
80
|
|
|
/* @var $target Target|\PHPUnit_Framework_MockObject_MockObject */ |
|
81
|
|
|
$target = $this->getMockBuilder(Target::class) |
|
82
|
|
|
->setMethods(['export']) |
|
83
|
|
|
->getMock(); |
|
84
|
|
|
|
|
85
|
|
|
$target->expects($this->exactly(0))->method('export'); |
|
86
|
|
|
|
|
87
|
|
|
$target->enabled = false; |
|
88
|
|
|
|
|
89
|
|
|
$target->collect([['category' => 'foo']]); |
|
90
|
|
|
|
|
91
|
|
|
$target = $this->getMockBuilder(Target::class) |
|
92
|
|
|
->setMethods(['export']) |
|
93
|
|
|
->getMock(); |
|
94
|
|
|
|
|
95
|
|
|
$target->expects($this->once())->method('export'); |
|
96
|
|
|
|
|
97
|
|
|
$target->enabled = true; |
|
98
|
|
|
|
|
99
|
|
|
$target->collect([['category' => 'foo']]); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|