-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from camspiers/stemmer-exception
Added php stemmer exception + unit tests
- Loading branch information
Showing
2 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
tests/Camspiers/StatisticalClassifier/Normalizer/Token/PhpStemmerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
namespace Camspiers\StatisticalClassifier\Normalizer\Token; | ||
|
||
class PhpStemmerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var PhpStemmer | ||
*/ | ||
protected $phpStemmer; | ||
|
||
public function normalizeDataProvider() | ||
{ | ||
return array( | ||
array(array('optimization'), array('optim'), 'english', 'utf-8'), | ||
array(array('optimisation'), array('optimis'), 'french', 'utf-8'), | ||
array(array('wzhgqkx'), array('wzhgq'), 'alien', 'utf-8', 'InvalidArgumentException'), | ||
); | ||
} | ||
|
||
/** | ||
* @covers \Camspiers\StatisticalClassifier\Normalizer\Token\PhpStemmer::normalize | ||
* @dataProvider normalizeDataProvider | ||
* | ||
* @param array $words | ||
* @param array $expected | ||
* @param string $lang | ||
* @param string $charset | ||
* @param boolean $expectedException | ||
*/ | ||
public function testNormalize(array $words, array $expected, $lang, $charset, $expectedException = false) | ||
{ | ||
if (! extension_loaded('stemmer')) { | ||
$this->markTestSkipped('stemmer PHP extension not available'); | ||
} | ||
|
||
if ($expectedException) { | ||
$this->setExpectedException($expectedException); | ||
} | ||
|
||
$stemmer = new PhpStemmer($lang, $charset); | ||
$this->assertEquals($expected, $stemmer->normalize($words)); | ||
} | ||
} |