| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- /**
- * Created by PhpStorm.
- * User: charles
- * Date: 25/04/2018
- * Time: 15:24
- */
- namespace Tests\AppBundle\Game;
- use AppBundle\Game\Loader\LoaderInterface;
- use AppBundle\Game\WordList;
- use PHPUnit\Framework\TestCase;
- class WordListTest extends TestCase
- {
- public function testGettingWord() {
- $stub = $this->provideLoaderInterface(array('word'));
- $wordList = new WordList(['filename.abc']);
- $wordList->addLoader($stub);
- $word = $wordList->getRandomWord();
- $this->assertSame($word, 'word');
- }
- public function testAddWord() {
- $stub = $this->provideLoaderInterface();
- $wordList = new WordList(['filename.abc']);
- $wordList->addLoader($stub);
- $wordList->addWord('word');
- $word = $wordList->getRandomWord();
- $this->assertSame($word, 'word');
- }
- /**
- * @expectedException \AppBundle\Game\Exception\RuntimeException
- */
- public function testWrongDictionaryType() {
- $stub = $this->provideLoaderInterface(array('word'));
- $wordList = new WordList(['filename.xxx']);
- $wordList->addLoader($stub);
- $word = $wordList->getRandomWord();
- }
- private function provideLoaderInterface($wordlist = array()) {
- $stub = $this->createMock(LoaderInterface::class);
- $stub
- ->method('getType')
- ->willReturn('abc');
- $stub
- ->method('load')
- ->willReturn($wordlist);
- return $stub;
- }
- }
|