testAssertInvalidAccessToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Nord\Lumen\OAuth2\Tests;
4
5
use Helper\Unit;
6
use Illuminate\Http\JsonResponse;
7
use Illuminate\Http\Request;
8
use Nord\Lumen\OAuth2\OAuth2ServiceProvider;
9
use Nord\Lumen\OAuth2\Middleware\OAuth2Middleware;
10
11
class OAuth2MiddlewareTest extends \Codeception\Test\Unit
12
{
13
    use \Codeception\Specify;
14
15
    /**
16
     * @var MockApplication
17
     */
18
    private $app;
19
20
    /**
21
     * @var OAuth2Middleware
22
     */
23
    private $middleware;
24
25
    /**
26
     * @inheritdoc
27
     */
28
    protected function setup()
29
    {
30
        $this->app = new MockApplication();
31
        $this->app->register(MockStorageServiceProvider::class);
32
        $this->app->register(OAuth2ServiceProvider::class);
33
34
        $this->middleware = new OAuth2Middleware();
35
    }
36
37
    /**
38
     *
39
     */
40
    public function testAssertValidAccessToken()
41
    {
42
        $this->specify('verify middleware valid access token', function () {
43
            Unit::setAuthorizationHeader();
44
            verify($this->middleware->handle(new Request(), function () {
45
                return true;
46
            }))->equals(true);
47
        });
48
    }
49
50
    /**
51
     *
52
     */
53
    public function testAssertInvalidAccessToken()
54
    {
55
        $this->specify('verify middleware invalid access token', function () {
56
            $res = $this->middleware->handle(new Request(), function () {
57
                return true;
58
            });
59
            verify($res)->isInstanceOf(JsonResponse::class);
60
            verify((array)$res->getData())->equals(['message' => 'ERROR.ACCESS_DENIED']);
61
        });
62
    }
63
}
64