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