Total Complexity | 3 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
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 | ); |
||
57 |