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