getMockBuilder(Access::class)->getMock(); $children = new ArrayCollection(); $children->add($childrenMockMock); $userMockMock = $this->getMockBuilder(Access::class)->getMock(); $userMockMock ->expects($this->once()) ->method('getChildren') ->willReturn($children); $switchUser = new SwitchUser(); $this->assertTrue($switchUser->isAllowedToSwitch($userMockMock, $childrenMockMock)); } /** * @see SwitchUser::isAllowedToSwitch() */ public function testIsNotAllowedToSwitch(){ $childrenMockMock = $this->getMockBuilder(Access::class)->getMock(); $userMockMock = $this->getMockBuilder(Access::class)->getMock(); $userMockMock ->expects($this->once()) ->method('getChildren') ->willReturn(new ArrayCollection()); $switchUser = new SwitchUser(); $this->assertFalse($switchUser->isAllowedToSwitch($userMockMock, $childrenMockMock)); } }