You are here

public function StemmerTest::testWordCache in Snowball Stemmer 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/StemmerTest.php \Drupal\Tests\snowball_stemmer\Unit\StemmerTest::testWordCache()

Test word cache.

Feels like this test could be simpler with a bit of refactoring the class.

File

tests/src/Unit/StemmerTest.php, line 100

Class

StemmerTest
Test Snowball Stemmer class wrapping.

Namespace

Drupal\Tests\snowball_stemmer\Unit

Code

public function testWordCache() {
  $testStemmer = new Stemmer();
  $reflector = new \ReflectionClass('\\Drupal\\snowball_stemmer\\Stemmer');
  $language = $reflector
    ->getProperty('language');
  $language
    ->setAccessible(TRUE);
  $stemmers = $reflector
    ->getProperty('stemmers');
  $stemmers
    ->setAccessible(TRUE);
  $prophecyGerman = $this
    ->prophesize(German::CLASS);
  $prophecyGerman
    ->stem('wordish')
    ->willReturn('word');
  $prophecyGerman
    ->stem('otherly')
    ->willReturn('other');
  $prophecyEnglish = $this
    ->prophesize(English::CLASS);
  $prophecyEnglish
    ->stem('wordish')
    ->willReturn('wordy');
  $prophecyEnglish
    ->stem('justly')
    ->willReturn('just');
  $stemmers
    ->setValue($testStemmer, [
    'de' => $prophecyGerman
      ->reveal(),
    'en' => $prophecyEnglish
      ->reveal(),
  ]);
  $language
    ->setValue($testStemmer, 'de');
  $this
    ->assertEquals($testStemmer
    ->stem('wordish'), 'word');
  $this
    ->assertEquals($testStemmer
    ->stem('otherly'), 'other');
  $language
    ->setValue($testStemmer, 'en');
  $this
    ->assertEquals($testStemmer
    ->stem('wordish'), 'wordy');
  $this
    ->assertEquals($testStemmer
    ->stem('justly'), 'just');
}