Passed
Push — master ( b2b167...7e189a )
by Philippe
01:56
created

FileTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 3
1
<?php
2
3
declare(strict_types=1);
4
5
use PhpSpellcheck\Source\File;
6
use PhpSpellcheck\Text;
7
use PhpSpellcheck\Utils\TextEncoding;
8
use PHPUnit\Framework\TestCase;
9
use Safe\Exceptions\FilesystemException;
10
11
class FileTest extends TestCase
12
{
13
    private const TEXT_FIXTURE_FILE_PATH = __DIR__ . '/../Fixtures/Text/mispelling1.txt';
14
15
    public function testToTexts(): void
16
    {
17
        $texts = (new File(self::TEXT_FIXTURE_FILE_PATH))->toTexts(['ctx' => 'in tests']);
18
        $this->assertEquals(
19
            [
20
                new Text(
21
                    "mispelling1\n",
22
                    TextEncoding::ASCII,
23
                    [
24
                        'ctx' => 'in tests',
25
                        'filePath' => realpath(self::TEXT_FIXTURE_FILE_PATH),
26
                    ]
27
                ),
28
            ],
29
            iterator_to_array($texts)
30
        );
31
    }
32
33
    public function testInvalidPath(): void
34
    {
35
        $this->expectException(FilesystemException::class);
36
        iterator_to_array((new File('invalidPath'))->toTexts());
37
    }
38
39
    public function testToTextsWithEncoding(): void
40
    {
41
        $texts = (new File(self::TEXT_FIXTURE_FILE_PATH, TextEncoding::UTF8))->toTexts(['ctx' => 'in tests']);
42
        $this->assertEquals(
43
            [
44
                new Text(
45
                    "mispelling1\n",
46
                    TextEncoding::UTF8,
47
                    [
48
                        'ctx' => 'in tests',
49
                        'filePath' => realpath(self::TEXT_FIXTURE_FILE_PATH),
50
                    ]
51
                ),
52
            ],
53
            iterator_to_array($texts)
54
        );
55
    }
56
}
57