/** * */ public function testCanSetAffiliations() { $service = new AffiliationService(); // Create a dummy user entity $affiliation = new Affiliation(); $affiliation->setId(1); // Create a dummy user entity $affiliation2 = new Affiliation(); $affiliation2->setId(2); // Mock the repository, disabling the constructor $userRepositoryMock = $this->getMockBuilder(\Affiliation\Repository\Affiliation::class)->disableOriginalConstructor()->getMock(); $userRepositoryMock->expects($this->once())->method('findAll')->will($this->returnValue([$affiliation, $affiliation2])); // Mock the entity manager $emMock = $this->getMock('EntityManager', ['getRepository'], [], '', false); $emMock->expects($this->any())->method('getRepository')->will($this->returnValue($userRepositoryMock)); $service->setEntityManager($emMock); $this->assertEquals(2, sizeof($service->findAll('affiliation'))); }