Passed
Pull Request — master (#186)
by Alexander
02:41
created

AbstractCollectorTestCase   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 1
b 0
f 0
dl 0
loc 34
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkIndexData() 0 3 1
A testCollect() 0 17 3
A checkCollectedData() 0 3 1
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 AbstractCollectorTestCase extends TestCase
12
{
13
    public function testCollect(): void
14
    {
15
        $indexData = null;
16
        $collector = $this->getCollector();
17
18
        $collector->startup();
19
        $this->collectTestData($collector);
20
        $data = $collector->getCollected();
21
        if ($collector instanceof IndexCollectorInterface) {
22
            $indexData = $collector->getIndexData();
23
        }
24
        $collector->shutdown();
25
26
        $this->assertSame($collector::class, $collector->getName());
27
        $this->checkCollectedData($data);
28
        if ($collector instanceof IndexCollectorInterface) {
29
            $this->checkIndexData($indexData);
0 ignored issues
show
Bug introduced by
It seems like $indexData can also be of type null; however, parameter $data of Yiisoft\Yii\Debug\Tests\...tCase::checkIndexData() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
            $this->checkIndexData(/** @scrutinizer ignore-type */ $indexData);
Loading history...
30
        }
31
    }
32
33
    abstract protected function getCollector(): CollectorInterface;
34
35
    abstract protected function collectTestData(CollectorInterface $collector): void;
36
37
    protected function checkCollectedData(array $data): void
38
    {
39
        $this->assertNotEmpty($data);
40
    }
41
42
    protected function checkIndexData(array $data): void
43
    {
44
        $this->assertNotEmpty($data);
45
    }
46
}
47