Passed
Push — master ( 33d5ac...775805 )
by Dmitriy
03:03
created

tests/Collector/FilesystemStreamCollectorTest.php (1 issue)

Labels
Severity
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
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),
74
        );
75
    }
76
}
77