1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Tests\Shared; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Yiisoft\Yii\Debug\Collector\CollectorInterface; |
9
|
|
|
use Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface; |
10
|
|
|
|
11
|
|
|
abstract class AbstractCollectorTestCase extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testCollect(): void |
14
|
|
|
{ |
15
|
|
|
$summaryData = null; |
16
|
|
|
$collector = $this->getCollector(); |
17
|
|
|
|
18
|
|
|
$collector->startup(); |
19
|
|
|
$this->collectTestData($collector); |
20
|
|
|
$data = $collector->getCollected(); |
21
|
|
|
if ($collector instanceof SummaryCollectorInterface) { |
22
|
|
|
$summaryData = $collector->getSummary(); |
23
|
|
|
} |
24
|
|
|
$collector->shutdown(); |
25
|
|
|
|
26
|
|
|
$this->assertSame($collector::class, $collector->getName()); |
27
|
|
|
$this->checkCollectedData($data); |
28
|
|
|
if ($collector instanceof SummaryCollectorInterface) { |
29
|
|
|
$this->checkSummaryData($summaryData); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testEmptyCollector(): void |
34
|
|
|
{ |
35
|
|
|
$collector = $this->getCollector(); |
36
|
|
|
|
37
|
|
|
$this->assertEquals([], $collector->getCollected()); |
38
|
|
|
if ($collector instanceof SummaryCollectorInterface) { |
39
|
|
|
$this->assertEquals([], $collector->getSummary()); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testInactiveCollector(): void |
44
|
|
|
{ |
45
|
|
|
$collector = $this->getCollector(); |
46
|
|
|
|
47
|
|
|
$this->collectTestData($collector); |
48
|
|
|
|
49
|
|
|
$this->assertEquals([], $collector->getCollected()); |
50
|
|
|
if ($collector instanceof SummaryCollectorInterface) { |
51
|
|
|
$this->assertEquals([], $collector->getSummary()); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
abstract protected function getCollector(): CollectorInterface; |
56
|
|
|
|
57
|
|
|
abstract protected function collectTestData(CollectorInterface $collector): void; |
58
|
|
|
|
59
|
|
|
protected function checkCollectedData(array $data): void |
60
|
|
|
{ |
61
|
|
|
$this->assertNotEmpty($data); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function checkSummaryData(array $data): void |
65
|
|
|
{ |
66
|
|
|
$this->assertNotEmpty($data); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|