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

FilesystemStreamCollectorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 36
c 0
b 0
f 0
dl 0
loc 64
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A collectTestData() 0 16 1
A checkIndexData() 0 8 1
A testCollectWithInactiveCollector() 0 7 1
A getCollector() 0 3 1
A checkCollectedData() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\Collector;
6
7
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
8
use Yiisoft\Yii\Debug\Collector\FilesystemStreamCollector;
9
10
final class FilesystemStreamCollectorTest extends AbstractCollectorTestCase
11
{
12
    /**
13
     * @param CollectorInterface|FilesystemStreamCollector $collector
14
     */
15
    protected function collectTestData(CollectorInterface $collector): void
16
    {
17
        $collector->collect(
0 ignored issues
show
Bug introduced by
The method collect() does not exist on Yiisoft\Yii\Debug\Collector\CollectorInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Yiisoft\Yii\Debug\Collector\QueueCollector. Are you sure you never get one of those? ( Ignorable by Annotation )

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

17
        $collector->/** @scrutinizer ignore-call */ 
18
                    collect(
Loading history...
18
            operation: 'read',
19
            path: __FILE__,
20
            args: ['arg1' => 'v1', 'arg2' => 'v2'],
21
        );
22
        $collector->collect(
23
            operation: 'read',
24
            path: __FILE__,
25
            args: ['arg3' => 'v3', 'arg4' => 'v4'],
26
        );
27
        $collector->collect(
28
            operation: 'mkdir',
29
            path: __DIR__,
30
            args: ['recursive'],
31
        );
32
    }
33
34
    public function testCollectWithInactiveCollector(): void
35
    {
36
        $collector = $this->getCollector();
37
        $this->collectTestData($collector);
38
39
        $collected = $collector->getCollected();
40
        $this->assertEmpty($collected);
41
    }
42
43
    protected function getCollector(): CollectorInterface
44
    {
45
        return new FilesystemStreamCollector();
46
    }
47
48
    protected function checkCollectedData(array $data): void
49
    {
50
        parent::checkCollectedData($data);
51
        $collected = $data;
52
        $this->assertCount(2, $collected);
53
54
        $this->assertCount(2, $collected['read']);
55
        $this->assertEquals([
56
            ['path' => __FILE__, 'args' => ['arg1' => 'v1', 'arg2' => 'v2']],
57
            ['path' => __FILE__, 'args' => ['arg3' => 'v3', 'arg4' => 'v4']],
58
        ], $collected['read']);
59
60
        $this->assertCount(1, $collected['mkdir']);
61
        $this->assertEquals([
62
            ['path' => __DIR__, 'args' => ['recursive']],
63
        ], $collected['mkdir']);
64
    }
65
66
    protected function checkIndexData(array $data): void
67
    {
68
        parent::checkIndexData($data);
69
        $this->assertArrayHasKey('fs_stream', $data);
70
        $this->assertEquals(
71
            ['read' => 2, 'mkdir' => 1],
72
            $data['fs_stream'],
73
            print_r($data, true),
0 ignored issues
show
Bug introduced by
It seems like print_r($data, true) can also be of type true; however, parameter $message of PHPUnit\Framework\Assert::assertEquals() does only seem to accept string, 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

73
            /** @scrutinizer ignore-type */ print_r($data, true),
Loading history...
74
        );
75
    }
76
}
77