Failed Conditions
Push — master ( 01d6ae...9ca6d9 )
by Philippe
534:14 queued 469:10
created

DirectoryTest::testToTextsMatchingRegex()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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