Issues (63)

tests/ByteCodeTest.php (1 issue)

Labels
Severity
1
<?php
2
declare(strict_types=1);
3
4
namespace SPSS\Tests;
5
6
7
use SPSS\Buffer;
8
use SPSS\ByteCodeReader;
9
use SPSS\ByteCodeWriter;
10
11
class ByteCodeTest extends TestCase
12
{
13
14
    public function provider()
15
    {
16
        return [
17
            ['test'],
18
            [str_repeat('abcdf', 1000)],
19
            ['ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ']
20
21
        ];
22
    }
23
24
    /**
25
     * @param $data
26
     * @throws \Exception
27
     * @dataProvider provider
28
     */
29
    public function testWrite($data)
30
    {
31
        $stream = fopen('php://memory', 'r+');
32
        $buffer = Buffer::factory($stream);
0 ignored issues
show
It seems like $stream can also be of type false; however, parameter $resource of SPSS\Buffer::factory() does only seem to accept resource|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

32
        $buffer = Buffer::factory(/** @scrutinizer ignore-type */ $stream);
Loading history...
33
        $writer = new ByteCodeWriter($buffer);
34
        $writer->append($data);
35
        $writer->flush();
36
        $buffer->rewind();
37
        $reader = new ByteCodeReader($buffer);
38
        $this->assertSame($data, trim($reader->read(strlen($data))));
39
    }
40
}