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

MisspellingTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 7
1
<?php
2
3
declare(strict_types=1);
4
5
use PhpSpellcheck\Exception\InvalidArgumentException;
6
use PhpSpellcheck\Misspelling;
7
use PHPUnit\Framework\TestCase;
8
9
class MisspellingTest extends TestCase
10
{
11
    public function testMergeSuggestions(): void
12
    {
13
        $misspelling = new Misspelling('mispelled', 1, 0, ['misspelled']);
14
        $misspelling->mergeSuggestions(['misspelling', 'misspelled']);
15
16
        $this->assertSame(['misspelled', 'misspelling'], $misspelling->getSuggestions());
17
    }
18
19
    /**
20
     * @dataProvider nonDeterminableUniqueIdentityMisspellings
21
     */
22
    public function testCanDeterminateUniqueIdentity(Misspelling $misspelling): void
23
    {
24
        $this->assertFalse($misspelling->canDeterminateUniqueIdentity());
25
    }
26
27
    public function nonDeterminableUniqueIdentityMisspellings(): array
28
    {
29
        return [
30
            [new Misspelling('mispelled')],
31
            [new Misspelling('mispelled', 1)],
32
            [new Misspelling('mispelled', null, 1)],
33
        ];
34
    }
35
36
    public function testContextOverridingMerge(): void
37
    {
38
        $misspelling = (new Misspelling('mispelled', 1, 0, [], ['idx' => '1']))->mergeContext([
39
            'idx' => 'foo',
40
            'idx2' => '2',
41
        ]);
42
43
        $this->assertEquals(new Misspelling('mispelled', 1, 0, [], ['idx' => 'foo', 'idx2' => '2']), $misspelling);
44
    }
45
46
    public function testContextNonOverridingMerge(): void
47
    {
48
        $misspelling = (new Misspelling('mispelled', 1, 0, [], ['idx' => '1']))->mergeContext([
49
            'idx' => 'foo',
50
            'idx2' => '2',
51
        ], false);
52
53
        $this->assertEquals(new Misspelling('mispelled', 1, 0, [], ['idx' => '1', 'idx2' => '2']), $misspelling);
54
    }
55
56
    public function testExceptionWhenMergingEmptyContext(): void
57
    {
58
        $this->expectException(InvalidArgumentException::class);
59
        (new Misspelling('mispelled', 1, 0, [], []))->mergeContext([]);
60
    }
61
62
    public function testImmutableSetContext(): void
63
    {
64
        $misspelling = new Misspelling('mispelled', 1, 0, [], []);
65
        $misspellingAfterSettingContext = $misspelling->setContext(['test']);
66
67
        $this->assertNotSame($misspelling, $misspellingAfterSettingContext);
68
    }
69
}
70