SwitchUserTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Tests\Service\Security;
  3. use App\Entity\Access\Access;
  4. use App\Service\Security\SwitchUser;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use PHPUnit\Framework\TestCase;
  7. class SwitchUserTest extends TestCase
  8. {
  9. /**
  10. * @see SwitchUser::isAllowedToSwitch()
  11. */
  12. public function testIsAllowedToSwitch(): void
  13. {
  14. // Cannot mock SwitchUser because of https://github.com/sebastianbergmann/phpunit/issues/3886
  15. $switchUser = new SwitchUser();
  16. $children = $this->getMockBuilder(Access::class)->getMock();
  17. $user = $this->getMockBuilder(Access::class)->getMock();
  18. $user->method('getChildren')
  19. ->willReturn(new ArrayCollection([$children]));
  20. $this->assertTrue($switchUser->isAllowedToSwitch($user, $children));
  21. }
  22. /**
  23. * @see SwitchUser::isAllowedToSwitch()
  24. */
  25. public function testIsNotAllowedToSwitch(): void
  26. {
  27. // Cannot mock SwitchUser because of https://github.com/sebastianbergmann/phpunit/issues/3886
  28. $switchUser = new SwitchUser();
  29. $children = $this->getMockBuilder(Access::class)->getMock();
  30. $user = $this->getMockBuilder(Access::class)->getMock();
  31. $user
  32. ->expects($this->once())
  33. ->method('getChildren')
  34. ->willReturn(new ArrayCollection());
  35. $this->assertFalse($switchUser->isAllowedToSwitch($user, $children));
  36. }
  37. }