SwitchUserTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Test\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. $switchUser = $this->getMockBuilder(SwitchUser::class)
  15. ->setMethodsExcept(['isAllowedToSwitch'])
  16. ->getMock();
  17. $children = $this->getMockBuilder(Access::class)->getMock();
  18. $user = $this->getMockBuilder(Access::class)->getMock();
  19. $user
  20. ->expects($this->once())
  21. ->method('getChildren')
  22. ->willReturn(new ArrayCollection([$children]));
  23. $this->assertTrue($switchUser->isAllowedToSwitch($user, $children));
  24. }
  25. /**
  26. * @see SwitchUser::isAllowedToSwitch()
  27. */
  28. public function testIsNotAllowedToSwitch(): void
  29. {
  30. $switchUser = $this->getMockBuilder(SwitchUser::class)
  31. ->setMethodsExcept(['isAllowedToSwitch'])
  32. ->getMock();
  33. $children = $this->getMockBuilder(Access::class)->getMock();
  34. $user = $this->getMockBuilder(Access::class)->getMock();
  35. $user
  36. ->expects($this->once())
  37. ->method('getChildren')
  38. ->willReturn(new ArrayCollection());
  39. $this->assertFalse($switchUser->isAllowedToSwitch($user, $children));
  40. }
  41. }