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
|
|
|
public function setUp(): void |
16
|
|
|
{ |
17
|
|
|
if (!extension_loaded('pspell')) { |
18
|
|
|
Assert::markTestSkipped('Pspell extension is not loaded'); |
19
|
|
|
} |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testCheck(): void |
23
|
|
|
{ |
24
|
|
|
$pspell = new PHPPspell(PSPELL_FAST); |
25
|
|
|
/** @var Misspelling[] $misspellings */ |
26
|
|
|
$misspellings = iterator_to_array($pspell->check('mispell', ['en'], ['ctx'])); |
27
|
|
|
|
28
|
|
|
$this->assertSame($misspellings[0]->getContext(), ['ctx']); |
29
|
|
|
$this->assertSame($misspellings[0]->getWord(), 'mispell'); |
30
|
|
|
$this->assertSame($misspellings[0]->getOffset(), 0); |
31
|
|
|
$this->assertSame($misspellings[0]->getLineNumber(), 1); |
32
|
|
|
$this->assertNotEmpty($misspellings[0]->getSuggestions()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testCheckWithoutEncoding(): void |
36
|
|
|
{ |
37
|
|
|
$this->expectException(\InvalidArgumentException::class); |
38
|
|
|
$pspell = new PHPPspell(PSPELL_FAST); |
39
|
|
|
/* @var Misspelling[] $misspellings */ |
40
|
|
|
iterator_to_array($pspell->check('mispell', ['en'], ['ctx'], null)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetSupportedLanguages(): void |
44
|
|
|
{ |
45
|
|
|
$this->expectException(LogicException::class); |
46
|
|
|
$pspell = new PHPPspell(PSPELL_FAST); |
47
|
|
|
$pspell->getSupportedLanguages(); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|