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

MisspellingTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

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