| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace App\Test\Service\Security;
- use App\Entity\Access\Access;
- use App\Service\Security\SwitchUser;
- use Doctrine\Common\Collections\ArrayCollection;
- use PHPUnit\Framework\TestCase;
- class SwitchUserTest extends TestCase
- {
- /**
- * @see SwitchUser::isAllowedToSwitch()
- */
- public function testIsAllowedToSwitch(): 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([$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));
- }
- }
|