1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
use PhpSpellcheck\Source\Directory; |
6
|
|
|
use PhpSpellcheck\Text; |
7
|
|
|
use PhpSpellcheck\Utils\TextEncoding; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
class DirectoryTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
private const TEXT_FIXTURES_PATH = __DIR__ . '/../Fixtures/Text/Directory'; |
13
|
|
|
|
14
|
|
|
public function testToTexts(): void |
15
|
|
|
{ |
16
|
|
|
$textsFromDirectory = (new Directory(self::TEXT_FIXTURES_PATH))->toTexts(['ctx' => 'in tests']); |
17
|
|
|
$expectedValues = [ |
18
|
|
|
new Text( |
19
|
|
|
"mispélling3\n", |
20
|
|
|
TextEncoding::UTF8, |
21
|
|
|
['ctx' => 'in tests', 'filePath' => realpath(self::TEXT_FIXTURES_PATH . '/mispelling3.txt')] |
22
|
|
|
), |
23
|
|
|
new Text( |
24
|
|
|
"mispelling2\n", |
25
|
|
|
TextEncoding::ASCII, |
26
|
|
|
['ctx' => 'in tests', 'filePath' => realpath(self::TEXT_FIXTURES_PATH . '/mispelling2.txt')] |
27
|
|
|
), |
28
|
|
|
new Text( |
29
|
|
|
"mispelling4\n", |
30
|
|
|
TextEncoding::ASCII, |
31
|
|
|
[ |
32
|
|
|
'ctx' => 'in tests', |
33
|
|
|
'filePath' => realpath(self::TEXT_FIXTURES_PATH . '/SubDirectory/mispelling4.txt'), |
34
|
|
|
] |
35
|
|
|
), |
36
|
|
|
]; |
37
|
|
|
$realValues = iterator_to_array($textsFromDirectory); |
38
|
|
|
|
39
|
|
|
foreach ($expectedValues as $value) { |
40
|
|
|
$this->assertContains($value, $realValues, '', false, false); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testToTextsMatchingRegex(): void |
45
|
|
|
{ |
46
|
|
|
$textsFromDirectory = (new Directory(self::TEXT_FIXTURES_PATH, '/^((?!mispelling3\.txt).)*$/')) |
47
|
|
|
->toTexts(['ctx' => 'in tests']); |
48
|
|
|
|
49
|
|
|
$expectedValues = [ |
50
|
|
|
new Text( |
51
|
|
|
"mispelling2\n", |
52
|
|
|
TextEncoding::ASCII, |
53
|
|
|
['ctx' => 'in tests', 'filePath' => realpath(self::TEXT_FIXTURES_PATH . '/mispelling2.txt')] |
54
|
|
|
), |
55
|
|
|
new Text("mispelling4\n", TextEncoding::ASCII, [ |
56
|
|
|
'ctx' => 'in tests', |
57
|
|
|
'filePath' => realpath(self::TEXT_FIXTURES_PATH . '/SubDirectory/mispelling4.txt'), |
58
|
|
|
]), |
59
|
|
|
]; |
60
|
|
|
$realValues = iterator_to_array($textsFromDirectory); |
61
|
|
|
|
62
|
|
|
foreach ($expectedValues as $value) { |
63
|
|
|
$this->assertContains($value, $realValues, '', false, false); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|