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; } }