Failed Conditions
Push — master ( 01d6ae...9ca6d9 )
by Philippe
534:14 queued 469:10
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

3 Methods

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