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. public function setUp():void
  10. {
  11. }
  12. /**
  13. * @see SwitchUser::isAllowedToSwitch()
  14. */
  15. public function testIsAllowedToSwitch(){
  16. $childrenMockMock = $this->getMockBuilder(Access::class)->getMock();
  17. $children = new ArrayCollection();
  18. $children->add($childrenMockMock);
  19. $userMockMock = $this->getMockBuilder(Access::class)->getMock();
  20. $userMockMock
  21. ->expects($this->once())
  22. ->method('getChildren')
  23. ->willReturn($children);
  24. $switchUser = new SwitchUser();
  25. $this->assertTrue($switchUser->isAllowedToSwitch($userMockMock, $childrenMockMock));
  26. }
  27. /**
  28. * @see SwitchUser::isAllowedToSwitch()
  29. */
  30. public function testIsNotAllowedToSwitch(){
  31. $childrenMockMock = $this->getMockBuilder(Access::class)->getMock();
  32. $userMockMock = $this->getMockBuilder(Access::class)->getMock();
  33. $userMockMock
  34. ->expects($this->once())
  35. ->method('getChildren')
  36. ->willReturn(new ArrayCollection());
  37. $switchUser = new SwitchUser();
  38. $this->assertFalse($switchUser->isAllowedToSwitch($userMockMock, $childrenMockMock));
  39. }
  40. }