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

testGetSupportedLanguages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpSpellcheck\Tests\Spellchecker;
6
7
use PhpSpellcheck\Misspelling;
8
use PhpSpellcheck\Spellchecker\MultiSpellchecker;
9
use PhpSpellcheck\Spellchecker\SpellcheckerInterface;
10
use PhpSpellcheck\Utils\TextEncoding;
11
use PHPUnit\Framework\TestCase;
12
13
class MultipleSpellcheckersTest extends TestCase
14
{
15
16
    public function testCheckAndMergeSuggestions()
17
    {
18
        $spellChecker1 = $this->createMock(SpellcheckerInterface::class);
19
        $misspelling1 = new Misspelling('mispelling1', 1);
20
        $misspelling2a = new Misspelling('mispelling2', 2, 2, ['suggestionA']);
21
        $misspelling2b = new Misspelling('mispelling2', 2, 2, ['suggestionB']);
22
23
        $spellChecker1->method('check')
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        $spellChecker1->/** @scrutinizer ignore-call */ 
24
                        method('check')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
            ->willReturn([$misspelling1, $misspelling2a]);
25
        $spellChecker2 = $this->createMock(SpellcheckerInterface::class);
26
        $misspelling3 = new Misspelling('mispelling3', 3, 3);
27
        $spellChecker2->method('check')
28
            ->willReturn([$misspelling2b, $misspelling3]);
29
30
        $multiSpellchecker = new MultiSpellchecker([$spellChecker1, $spellChecker2]);
31
32
        $misspellings = $multiSpellchecker->check('test', ['en'], ['ctx'], TextEncoding::UTF8);
33
        $this->assertEquals(
34
            [
35
                $misspelling1->setContext(['ctx']),
36
                new Misspelling('mispelling2', 2, 2, ['suggestionA', 'suggestionB'], ['ctx']),
37
                $misspelling3->setContext(['ctx']),
38
            ],
39
            $misspellings
40
        );
41
    }
42
43
    public function testCheckAndNotMergeSuggestions()
44
    {
45
        $spellChecker1 = $this->createMock(SpellcheckerInterface::class);
46
        $misspelling1 = new Misspelling('mispelling1', 1);
47
        $misspelling2a = new Misspelling('mispelling2', 2, 2, ['suggestionA']);
48
        $misspelling2b = new Misspelling('mispelling2', 2, 2, ['suggestionB']);
49
50
        $spellChecker1->method('check')
51
            ->willReturn([$misspelling1, $misspelling2a]);
52
        $spellChecker2 = $this->createMock(SpellcheckerInterface::class);
53
        $misspelling3 = new Misspelling('mispelling3', 3, 3);
54
        $spellChecker2->method('check')
55
            ->willReturn([$misspelling2b, $misspelling3]);
56
57
        $multiSpellchecker = new MultiSpellchecker([$spellChecker1, $spellChecker2], false);
58
59
        $misspellings = $multiSpellchecker->check('test', ['en'], ['ctx'], TextEncoding::UTF8);
60
        $this->assertEquals(
61
            [
62
                $misspelling1->setContext(['ctx']),
63
                $misspelling2a->setContext(['ctx']),
64
                $misspelling2b->setContext(['ctx']),
65
                $misspelling3->setContext(['ctx']),
66
            ],
67
            iterator_to_array($misspellings)
0 ignored issues
show
Bug introduced by
$misspellings of type array is incompatible with the type Traversable expected by parameter $iterator of iterator_to_array(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
            iterator_to_array(/** @scrutinizer ignore-type */ $misspellings)
Loading history...
68
        );
69
    }
70
71
    public function testGetSupportedLanguages()
72
    {
73
        $spellChecker1 = $this->createMock(SpellcheckerInterface::class);
74
        $spellChecker1->method('getSupportedLanguages')
75
            ->willReturn(['en', 'fr']);
76
        $spellChecker2 = $this->createMock(SpellcheckerInterface::class);
77
        $spellChecker2->method('getSupportedLanguages')
78
            ->willReturn(['fr', 'ru']);
79
80
        $multipleSpellchecker = new MultiSpellchecker([$spellChecker1, $spellChecker2]);
81
82
        $this->assertSame(['en', 'fr', 'ru'], $multipleSpellchecker->getSupportedLanguages());
83
    }
84
}
85