Ver Fonte

BTTF-57 - tests

Vincent GUFFON há 4 anos atrás
pai
commit
43389047a3
1 ficheiros alterados com 48 adições e 0 exclusões
  1. 48 0
      tests/Service/Security/SwitchUserTest.php

+ 48 - 0
tests/Service/Security/SwitchUserTest.php

@@ -0,0 +1,48 @@
+<?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
+{
+    public function setUp():void
+    {
+    }
+
+    /**
+     * @see SwitchUser::isAllowedToSwitch()
+     */
+    public function testIsAllowedToSwitch(){
+        $childrenMockMock = $this->getMockBuilder(Access::class)->getMock();
+
+        $children = new ArrayCollection();
+        $children->add($childrenMockMock);
+
+        $userMockMock = $this->getMockBuilder(Access::class)->getMock();
+        $userMockMock
+            ->expects($this->once())
+            ->method('getChildren')
+            ->willReturn($children);
+
+        $switchUser = new SwitchUser();
+        $this->assertTrue($switchUser->isAllowedToSwitch($userMockMock, $childrenMockMock));
+    }
+
+    /**
+     * @see SwitchUser::isAllowedToSwitch()
+     */
+    public function testIsNotAllowedToSwitch(){
+        $childrenMockMock = $this->getMockBuilder(Access::class)->getMock();
+        $userMockMock = $this->getMockBuilder(Access::class)->getMock();
+        $userMockMock
+            ->expects($this->once())
+            ->method('getChildren')
+            ->willReturn(new ArrayCollection());
+
+        $switchUser = new SwitchUser();
+        $this->assertFalse($switchUser->isAllowedToSwitch($userMockMock, $childrenMockMock));
+    }
+}