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
|
|
|
|