Skip to content

Commit

Permalink
#6: Can't open affix or dictionary files for dictionary named "default".
Browse files Browse the repository at this point in the history
Fixed.
  • Loading branch information
mekras committed Mar 22, 2017
1 parent 8916031 commit dffc8a0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixed

- #6: Failed to execute "hunspell -i UTF-8 -a": Can't open affix or dictionary files for dictionary
named "default".
- FileSource throws SourceException when using "php://stdin".

### Changed
Expand Down
2 changes: 1 addition & 1 deletion examples/spellcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function showHelp()
}

/* Source language. */
$languages = [locale_get_default()];
$languages = [];
if (array_key_exists('l', $options)) {
$languages = explode(',', $options['l']);
}
Expand Down
1 change: 1 addition & 0 deletions src/ExternalSpeller.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ protected function createProcess($args = null)
} catch (RuntimeException $e) {
throw new ExternalProgramFailedException($command, $e->getMessage(), 0, $e);
}
$process->inheritEnvironmentVariables(true);
$process->setTimeout($this->timeout);

return $process;
Expand Down
14 changes: 12 additions & 2 deletions tests/Hunspell/HunspellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testArgumentEscaping()
*/
public function testGetSupportedLanguages()
{
$hunspell = new Hunspell(__DIR__ . '/fixtures/hunspell.sh');
$hunspell = new Hunspell($this->getBinary());
static::assertEquals(
['de_BE', 'de_DE', 'de_LU', 'en-GB', 'en_AU', 'en_GB', 'en_US', 'en_ZA', 'ru_RU'],
$hunspell->getSupportedLanguages()
Expand All @@ -52,7 +52,7 @@ public function testGetSupportedLanguages()
*/
public function testCheckText()
{
$hunspell = new Hunspell(__DIR__ . '/fixtures/hunspell.sh');
$hunspell = new Hunspell($this->getBinary());
$source = new StringSource('<will be ignored and loaded from fixtures/check.txt>');
$issues = $hunspell->checkText($source, ['en']);
static::assertCount(6, $issues);
Expand All @@ -72,4 +72,14 @@ public function testCheckText()
static::assertEquals('CCould', $issues[5]->word);
static::assertEquals(4, $issues[5]->line);
}

/**
* Return hunspell binary stub.
*
* @return string
*/
private function getBinary()
{
return __DIR__ . '/fixtures/bin/hunspell.php';
}
}
25 changes: 25 additions & 0 deletions tests/Hunspell/fixtures/bin/hunspell.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env php
<?php
/*
* hunspell binary stub
*/

$options = getopt('aDd::i:');

if (array_key_exists('D', $options)) {
fprintf(STDERR, file_get_contents(__DIR__ . '/../dicts.txt'));
exit(0);
}

if (array_key_exists('a', $options)) {
$language = array_key_exists('d', $options) ? $options['d'] : false;
if (!$language && !getenv('LANG')) {
echo 'Can\'t open affix or dictionary files for dictionary named "default".' . PHP_EOL;
exit(1);
}
echo file_get_contents(__DIR__ . '/../check.txt');
exit(0);
}

echo 'Invalid call' . PHP_EOL;
exit(1);
16 changes: 0 additions & 16 deletions tests/Hunspell/fixtures/hunspell.sh

This file was deleted.

0 comments on commit dffc8a0

Please sign in to comment.