WordListTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: charles
  5. * Date: 25/04/2018
  6. * Time: 15:24
  7. */
  8. namespace Tests\AppBundle\Game;
  9. use AppBundle\Game\Loader\LoaderInterface;
  10. use AppBundle\Game\WordList;
  11. use PHPUnit\Framework\TestCase;
  12. class WordListTest extends TestCase
  13. {
  14. public function testGettingWord() {
  15. $stub = $this->provideLoaderInterface(array('word'));
  16. $wordList = new WordList(['filename.abc']);
  17. $wordList->addLoader($stub);
  18. $word = $wordList->getRandomWord();
  19. $this->assertSame($word, 'word');
  20. }
  21. public function testAddWord() {
  22. $stub = $this->provideLoaderInterface();
  23. $wordList = new WordList(['filename.abc']);
  24. $wordList->addLoader($stub);
  25. $wordList->addWord('word');
  26. $word = $wordList->getRandomWord();
  27. $this->assertSame($word, 'word');
  28. }
  29. /**
  30. * @expectedException \AppBundle\Game\Exception\RuntimeException
  31. */
  32. public function testWrongDictionaryType() {
  33. $stub = $this->provideLoaderInterface(array('word'));
  34. $wordList = new WordList(['filename.xxx']);
  35. $wordList->addLoader($stub);
  36. $word = $wordList->getRandomWord();
  37. }
  38. private function provideLoaderInterface($wordlist = array()) {
  39. $stub = $this->createMock(LoaderInterface::class);
  40. $stub
  41. ->method('getType')
  42. ->willReturn('abc');
  43. $stub
  44. ->method('load')
  45. ->willReturn($wordlist);
  46. return $stub;
  47. }
  48. }