Passed
Push — master ( 7bc6a4...bace86 )
by Dmitriy
06:54 queued 04:27
created

Unit/Collector/FilesystemStreamCollectorTest.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\Unit\Collector;
6
7
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
8
use Yiisoft\Yii\Debug\Collector\Stream\FilesystemStreamCollector;
9
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;
10
11
final class FilesystemStreamCollectorTest extends AbstractCollectorTestCase
12
{
13
    /**
14
     * @param CollectorInterface|FilesystemStreamCollector $collector
15
     */
16
    protected function collectTestData(CollectorInterface $collector): void
17
    {
18
        $collector->collect(
0 ignored issues
show
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\Collec...mmaryCollectorInterface. 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

18
        $collector->/** @scrutinizer ignore-call */ 
19
                    collect(
Loading history...
19
            operation: 'read',
20
            path: __FILE__,
21
            args: ['arg1' => 'v1', 'arg2' => 'v2'],
22
        );
23
        $collector->collect(
24
            operation: 'read',
25
            path: __FILE__,
26
            args: ['arg3' => 'v3', 'arg4' => 'v4'],
27
        );
28
        $collector->collect(
29
            operation: 'mkdir',
30
            path: __DIR__,
31
            args: ['recursive'],
32
        );
33
    }
34
35
    public function testCollectWithInactiveCollector(): void
36
    {
37
        $collector = $this->getCollector();
38
        $this->collectTestData($collector);
39
40
        $collected = $collector->getCollected();
41
        $this->assertEmpty($collected);
42
    }
43
44
    protected function getCollector(): CollectorInterface
45
    {
46
        return new FilesystemStreamCollector();
47
    }
48
49
    protected function checkCollectedData(array $data): void
50
    {
51
        parent::checkCollectedData($data);
52
        $collected = $data;
53
        $this->assertCount(2, $collected);
54
55
        $this->assertCount(2, $collected['read']);
56
        $this->assertEquals([
57
            ['path' => __FILE__, 'args' => ['arg1' => 'v1', 'arg2' => 'v2']],
58
            ['path' => __FILE__, 'args' => ['arg3' => 'v3', 'arg4' => 'v4']],
59
        ], $collected['read']);
60
61
        $this->assertCount(1, $collected['mkdir']);
62
        $this->assertEquals([
63
            ['path' => __DIR__, 'args' => ['recursive']],
64
        ], $collected['mkdir']);
65
    }
66
67
    protected function checkSummaryData(array $data): void
68
    {
69
        parent::checkSummaryData($data);
70
        $this->assertArrayHasKey('fs_stream', $data);
71
        $this->assertEquals(
72
            ['read' => 2, 'mkdir' => 1],
73
            $data['fs_stream'],
74
            print_r($data, true),
75
        );
76
    }
77
}
78