Passed
Push — master ( bafd2f...fc0646 )
by Alexander
02:28
created

CollectorTestCase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 11
dl 0
loc 26
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkCollectedData() 0 3 1
A testCollect() 0 9 1
A checkIndexData() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\Collector;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
9
use Yiisoft\Yii\Debug\Collector\IndexCollectorInterface;
10
11
abstract class CollectorTestCase extends TestCase
12
{
13
    public function testCollect(): void
14
    {
15
        $collector = $this->getCollector();
16
        $collector->startup();
17
        $this->collectTestData($collector);
18
        $this->checkCollectedData($collector);
19
        $this->checkIndexData($collector);
20
        $collector->shutdown();
21
        $this->assertSame(get_class($collector), $collector->getName());
22
    }
23
24
    abstract protected function getCollector(): CollectorInterface;
25
26
    abstract protected function collectTestData(CollectorInterface $collector): void;
27
28
    protected function checkCollectedData(CollectorInterface $collector): void
29
    {
30
        $this->assertNotEmpty($collector->getCollected());
31
    }
32
33
    protected function checkIndexData(CollectorInterface $collector): void
34
    {
35
        if ($collector instanceof IndexCollectorInterface) {
36
            $this->assertNotEmpty($collector->getIndexData());
37
        }
38
    }
39
}
40