Passed
Push — master ( e7ebae...ecc5ac )
by Valentin
04:51 queued 11s
created

testInvalidAnnotationConfigurationIfEmptyGuarded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 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\Tests\Framework\Interceptor;
13
14
use Spiral\App\Controller\Demo2Controller;
15
use Spiral\App\Controller\Demo3Controller;
16
use Spiral\App\Controller\DemoController;
17
use Spiral\Core\CoreInterface;
18
use Spiral\Core\Exception\ControllerException;
19
use Spiral\Core\Exception\InterceptorException;
20
use Spiral\Security\Actor\Actor;
21
use Spiral\Security\ActorInterface;
22
use Spiral\Tests\Framework\ConsoleTest;
23
24
class GuardedTest extends ConsoleTest
25
{
26
    public function testInvalidAnnotationConfiguration(): void
27
    {
28
        /** @var CoreInterface $core */
29
        $core = $this->app->get(CoreInterface::class);
30
31
        $this->expectException(InterceptorException::class);
32
        $core->callAction(DemoController::class, 'guardedButNoName', []);
33
    }
34
35
    public function testInvalidAnnotationConfigurationIfEmptyGuarded(): void
36
    {
37
        /** @var CoreInterface $core */
38
        $core = $this->app->get(CoreInterface::class);
39
40
        $this->expectException(InterceptorException::class);
41
        $core->callAction(Demo3Controller::class, 'do', []);
42
    }
43
44
    public function testNotAllowed(): void
45
    {
46
        /** @var CoreInterface $core */
47
        $core = $this->app->get(CoreInterface::class);
48
49
        $this->expectException(ControllerException::class);
50
        $core->callAction(DemoController::class, 'do', []);
51
    }
52
53
    public function testNotAllowed2(): void
54
    {
55
        /** @var CoreInterface $core */
56
        $core = $this->app->get(CoreInterface::class);
57
58
        $this->expectException(ControllerException::class);
59
        $core->callAction(Demo2Controller::class, 'do1', []);
60
    }
61
62
    public function testNotAllowedError1(): void
63
    {
64
        /** @var CoreInterface $core */
65
        $core = $this->app->get(CoreInterface::class);
66
67
        $this->expectExceptionCode(ControllerException::FORBIDDEN);
68
        $core->callAction(Demo2Controller::class, 'do1', []);
69
    }
70
71
    public function testNotAllowedError2(): void
72
    {
73
        /** @var CoreInterface $core */
74
        $core = $this->app->get(CoreInterface::class);
75
76
        $this->expectExceptionCode(ControllerException::NOT_FOUND);
77
        $core->callAction(Demo2Controller::class, 'do2', []);
78
    }
79
80
81
    public function testNotAllowedError3(): void
82
    {
83
        /** @var CoreInterface $core */
84
        $core = $this->app->get(CoreInterface::class);
85
86
        $this->expectExceptionCode(ControllerException::ERROR);
87
        $core->callAction(Demo2Controller::class, 'do3', []);
88
    }
89
90
91
    public function testNotAllowedError4(): void
92
    {
93
        /** @var CoreInterface $core */
94
        $core = $this->app->get(CoreInterface::class);
95
96
        $this->expectExceptionCode(ControllerException::BAD_ACTION);
97
        $core->callAction(Demo2Controller::class, 'do4', []);
98
    }
99
100
    public function testAllowed(): 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->assertSame('ok', $core->callAction(DemoController::class, 'do', []));
108
    }
109
110
    public function testNotAllowed3(): void
111
    {
112
        /** @var CoreInterface $core */
113
        $core = $this->app->get(CoreInterface::class);
114
115
        $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

115
        $this->app->getContainer()->bind(ActorInterface::class, /** @scrutinizer ignore-type */ new Actor(['user']));
Loading history...
116
117
        $this->expectExceptionCode(ControllerException::FORBIDDEN);
118
        $this->assertSame('ok', $core->callAction(Demo2Controller::class, 'do1', []));
119
    }
120
121
    public function testAllowed2(): void
122
    {
123
        /** @var CoreInterface $core */
124
        $core = $this->app->get(CoreInterface::class);
125
126
        $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

126
        $this->app->getContainer()->bind(ActorInterface::class, /** @scrutinizer ignore-type */ new Actor(['demo']));
Loading history...
127
        $this->assertSame('ok', $core->callAction(Demo2Controller::class, 'do1', []));
128
    }
129
}
130