Passed
Push — master ( e789fa...7285b3 )
by William
02:37
created

StringReaderTest::testReadIntArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 12
rs 9.9332
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\MoTranslator\Tests;
6
7
use PhpMyAdmin\MoTranslator\StringReader;
8
use PHPUnit\Framework\TestCase;
9
10
use function file_put_contents;
11
use function sys_get_temp_dir;
12
use function tempnam;
13
use function unlink;
14
15
class StringReaderTest extends TestCase
16
{
17
    public function testReadFails(): void
18
    {
19
        $tempFile = (string) tempnam(sys_get_temp_dir(), 'phpMyAdmin_StringReaderTest');
20
        $this->assertFileExists($tempFile);
21
        $stringReader = new StringReader($tempFile);
22
        unlink($tempFile);
23
        $actual = $stringReader->read(-1, -1);
24
        $this->assertSame('', $actual);
25
    }
26
27
    public function testReadIntArray(): void
28
    {
29
        $tempFile = (string) tempnam(sys_get_temp_dir(), 'phpMyAdmin_StringReaderTest');
30
        file_put_contents($tempFile, "\0\0\0\0\0\0\0\0\0\0\0\0");
31
        $this->assertFileExists($tempFile);
32
        $stringReader = new StringReader($tempFile);
33
        unlink($tempFile);
34
        $actual = $stringReader->readintarray('V', 2, 2);
35
        $this->assertSame([
36
            1 => 0,
37
            2 => 0,
38
        ], $actual);
39
    }
40
}
41