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

PHPPspellTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 2
A testCheckWithoutEnconding() 0 6 1
A testCheck() 0 11 1
A testGetSupportedLanguages() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpSpellcheck\Tests\Spellchecker;
6
7
use PhpSpellcheck\Exception\LogicException;
8
use PhpSpellcheck\Misspelling;
9
use PhpSpellcheck\Spellchecker\PHPPspell;
10
use PHPUnit\Framework\Assert;
11
use PHPUnit\Framework\TestCase;
12
13
class PHPPspellTest extends TestCase
14
{
15
16
    public function setUp()
17
    {
18
        if (!extension_loaded('pspell')) {
19
            Assert::markTestSkipped('Pspell extension is not loaded');
20
        }
21
    }
22
23
    public function testCheck()
24
    {
25
        $pspell = new PHPPspell(PSPELL_FAST);
26
        /** @var Misspelling[] $misspellings */
27
        $misspellings = iterator_to_array($pspell->check('mispell', ['en'], ['ctx']));
28
29
        $this->assertSame($misspellings[0]->getContext(), ['ctx']);
30
        $this->assertSame($misspellings[0]->getWord(), 'mispell');
31
        $this->assertSame($misspellings[0]->getOffset(), 0);
32
        $this->assertSame($misspellings[0]->getLineNumber(), 1);
33
        $this->assertNotEmpty($misspellings[0]->getSuggestions());
34
    }
35
36
    public function testCheckWithoutEnconding()
37
    {
38
        $this->expectException(\InvalidArgumentException::class);
39
        $pspell = new PHPPspell(PSPELL_FAST);
40
        /** @var Misspelling[] $misspellings */
41
        iterator_to_array($pspell->check('mispell', ['en'], ['ctx'], null));
42
    }
43
44
    public function testGetSupportedLanguages()
45
    {
46
        $this->expectException(LogicException::class);
47
        $pspell = new PHPPspell(PSPELL_FAST);
48
        $pspell->getSupportedLanguages();
49
    }
50
}
51