Passed
Push — master ( 80b8b4...b2a343 )
by Anton
03:00
created

GuardedTest::testNotAllowed2()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Framework\Interceptor;
13
14
use Spiral\App\Controller\Demo2Controller;
15
use Spiral\App\Controller\DemoController;
16
use Spiral\Core\CoreInterface;
17
use Spiral\Core\Exception\ControllerException;
18
use Spiral\Core\Exception\InterceptorException;
19
use Spiral\Framework\ConsoleTest;
20
use Spiral\Security\Actor\Actor;
21
use Spiral\Security\ActorInterface;
22
23
class GuardedTest extends ConsoleTest
24
{
25
    public function testInvalidAnnotationConfiguration(): void
26
    {
27
        /** @var CoreInterface $core */
28
        $core = $this->app->get(CoreInterface::class);
29
30
        $this->expectException(InterceptorException::class);
31
        $core->callAction(DemoController::class, 'guardedButNoName', []);
32
    }
33
34
    public function testNotAllowed(): void
35
    {
36
        /** @var CoreInterface $core */
37
        $core = $this->app->get(CoreInterface::class);
38
39
        $this->expectException(ControllerException::class);
40
        $core->callAction(DemoController::class, 'do', []);
41
    }
42
43
    public function testNotAllowed2(): void
44
    {
45
        /** @var CoreInterface $core */
46
        $core = $this->app->get(CoreInterface::class);
47
48
        $this->expectException(ControllerException::class);
49
        $core->callAction(Demo2Controller::class, 'do1', []);
50
    }
51
52
    public function testNotAllowedError1(): void
53
    {
54
        /** @var CoreInterface $core */
55
        $core = $this->app->get(CoreInterface::class);
56
57
        $this->expectExceptionCode(ControllerException::FORBIDDEN);
58
        $core->callAction(Demo2Controller::class, 'do1', []);
59
    }
60
61
    public function testNotAllowedError2(): void
62
    {
63
        /** @var CoreInterface $core */
64
        $core = $this->app->get(CoreInterface::class);
65
66
        $this->expectExceptionCode(ControllerException::NOT_FOUND);
67
        $core->callAction(Demo2Controller::class, 'do2', []);
68
    }
69
70
71
    public function testNotAllowedError3(): void
72
    {
73
        /** @var CoreInterface $core */
74
        $core = $this->app->get(CoreInterface::class);
75
76
        $this->expectExceptionCode(ControllerException::ERROR);
77
        $core->callAction(Demo2Controller::class, 'do3', []);
78
    }
79
80
81
    public function testNotAllowedError4(): void
82
    {
83
        /** @var CoreInterface $core */
84
        $core = $this->app->get(CoreInterface::class);
85
86
        $this->expectExceptionCode(ControllerException::BAD_ACTION);
87
        $core->callAction(Demo2Controller::class, 'do4', []);
88
    }
89
90
    public function testAllowed(): void
91
    {
92
        /** @var CoreInterface $core */
93
        $core = $this->app->get(CoreInterface::class);
94
95
        $this->app->getContainer()->bind(ActorInterface::class, new Actor(['user']));
0 ignored issues
show
Bug introduced by
new Spiral\Security\Actor\Actor(array('user')) of type Spiral\Security\Actor\Actor is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

95
        $this->app->getContainer()->bind(ActorInterface::class, /** @scrutinizer ignore-type */ new Actor(['user']));
Loading history...
96
97
        $this->assertSame('ok', $core->callAction(DemoController::class, 'do', []));
98
    }
99
100
    public function testNotAllowed3(): void
101
    {
102
        /** @var CoreInterface $core */
103
        $core = $this->app->get(CoreInterface::class);
104
105
        $this->app->getContainer()->bind(ActorInterface::class, new Actor(['user']));
0 ignored issues
show
Bug introduced by
new Spiral\Security\Actor\Actor(array('user')) of type Spiral\Security\Actor\Actor is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

105
        $this->app->getContainer()->bind(ActorInterface::class, /** @scrutinizer ignore-type */ new Actor(['user']));
Loading history...
106
107
        $this->expectExceptionCode(ControllerException::FORBIDDEN);
108
        $this->assertSame('ok', $core->callAction(Demo2Controller::class, 'do1', []));
109
    }
110
111
    public function testAllowed2(): void
112
    {
113
        /** @var CoreInterface $core */
114
        $core = $this->app->get(CoreInterface::class);
115
116
        $this->app->getContainer()->bind(ActorInterface::class, new Actor(['demo']));
0 ignored issues
show
Bug introduced by
new Spiral\Security\Actor\Actor(array('demo')) of type Spiral\Security\Actor\Actor is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

116
        $this->app->getContainer()->bind(ActorInterface::class, /** @scrutinizer ignore-type */ new Actor(['demo']));
Loading history...
117
        $this->assertSame('ok', $core->callAction(Demo2Controller::class, 'do1', []));
118
    }
119
}
120