Passed
Push — master ( 45b054...06b8db )
by Sam
02:37
created

ByteCodeTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testWrite() 0 10 1
A provider() 0 6 1
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
Bug introduced by
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
}