yarhon /
RouteGuardBundle
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * |
||
| 5 | * (c) Yaroslav Honcharuk <[email protected]> |
||
| 6 | * |
||
| 7 | * For the full copyright and license information, please view the LICENSE |
||
| 8 | * file that was distributed with this source code. |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Yarhon\RouteGuardBundle\Tests\Security\AuthorizationChecker; |
||
| 12 | |||
| 13 | use PHPUnit\Framework\TestCase; |
||
| 14 | use Yarhon\RouteGuardBundle\Routing\RouteContext; |
||
| 15 | use Yarhon\RouteGuardBundle\Security\Test\TestInterface; |
||
| 16 | use Yarhon\RouteGuardBundle\Security\Test\SymfonyAccessControlTest; |
||
| 17 | use Yarhon\RouteGuardBundle\Security\AuthorizationChecker\AuthorizationCheckerInterface; |
||
| 18 | use Yarhon\RouteGuardBundle\Security\AuthorizationChecker\DelegatingAuthorizationChecker; |
||
| 19 | use Yarhon\RouteGuardBundle\Exception\RuntimeException; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @author Yaroslav Honcharuk <[email protected]> |
||
| 23 | */ |
||
| 24 | class DelegatingAuthorizationCheckerTest extends TestCase |
||
| 25 | { |
||
| 26 | public function testSupports() |
||
| 27 | { |
||
| 28 | $delegatingChecker = new DelegatingAuthorizationChecker(); |
||
| 29 | |||
| 30 | $test = $this->createMock(TestInterface::class); |
||
| 31 | |||
| 32 | $this->assertTrue($delegatingChecker->supports($test)); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function testIsGranted() |
||
| 36 | { |
||
| 37 | $checkers = [ |
||
| 38 | $this->createMock(AuthorizationCheckerInterface::class), |
||
| 39 | $this->createMock(AuthorizationCheckerInterface::class), |
||
| 40 | ]; |
||
| 41 | |||
| 42 | $checkers[0]->method('supports') |
||
|
0 ignored issues
–
show
|
|||
| 43 | ->willReturn(false); |
||
| 44 | |||
| 45 | $checkers[1]->method('supports') |
||
| 46 | ->willReturn(true); |
||
| 47 | |||
| 48 | $delegatingChecker = new DelegatingAuthorizationChecker($checkers); |
||
| 49 | |||
| 50 | $test = new SymfonyAccessControlTest(['ROLE_USER']); |
||
| 51 | $routeContext = new RouteContext('index'); |
||
| 52 | |||
| 53 | $checkers[1]->expects($this->once()) |
||
| 54 | ->method('isGranted') |
||
| 55 | ->with($test, $routeContext) |
||
| 56 | ->willReturn(true); |
||
| 57 | |||
| 58 | $this->assertTrue($delegatingChecker->isGranted($test, $routeContext)); |
||
| 59 | } |
||
| 60 | |||
| 61 | public function testIsGrantedException() |
||
| 62 | { |
||
| 63 | $checkers = [ |
||
| 64 | $this->createMock(AuthorizationCheckerInterface::class), |
||
| 65 | ]; |
||
| 66 | |||
| 67 | $checkers[0]->method('supports') |
||
| 68 | ->willReturn(false); |
||
| 69 | |||
| 70 | $delegatingChecker = new DelegatingAuthorizationChecker($checkers); |
||
| 71 | |||
| 72 | $test = new SymfonyAccessControlTest(['ROLE_USER']); |
||
| 73 | $routeContext = new RouteContext('index'); |
||
| 74 | |||
| 75 | $this->expectException(RuntimeException::class); |
||
| 76 | $this->expectExceptionMessage(sprintf('No authorization checker exists for test instance of "%s".', SymfonyAccessControlTest::class)); |
||
| 77 | |||
| 78 | $delegatingChecker->isGranted($test, $routeContext); |
||
| 79 | } |
||
| 80 | } |
||
| 81 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.