scoreDaoMock = $this->mock(ScoreDao::class); $this->favoritesDaoMock = $this->mock(FavoritesDao::class); $this->userDaoMock = $this->mock(UserDao::class); $this->transactionManagerMock = $this->mockTransactionManager(); $this->timeServiceMock = $this->mock(TimeService::class); } public function testSetting() { $user = new User(1); $post = new Post(2); $score = new Score(); $score->setUserId($user->getId()); $score->setPostId($post->getId()); $score->setScore(1); $this->scoreDaoMock->expects($this->once())->method('setScore')->with($user, $post)->willReturn(null); $scoreService = $this->getScoreService(); $scoreService->setScore($user, $post, 1); } public function testSettingInvalid() { $user = new User(1); $post = new Post(2); $this->setExpectedException(\Exception::class); $scoreService = $this->getScoreService(); $scoreService->setScore($user, $post, 2); } public function testGetting() { $user = new User(); $post = new Post(); $score = new Score(3); $this->scoreDaoMock->expects($this->once())->method('getScore')->with($user, $post)->willReturn($score); $scoreService = $this->getScoreService(); $retrievedScore = $scoreService->getScore($user, $post); $this->assertEquals($score, $retrievedScore); } private function getScoreService() { return new ScoreService( $this->scoreDaoMock, $this->favoritesDaoMock, $this->userDaoMock, $this->transactionManagerMock, $this->timeServiceMock); } }