Code Duplication    Length = 12-14 lines in 3 locations

module/Rest/test/Middleware/CheckAuthenticationMiddlewareTest.php 3 locations

@@ 97-108 (lines=12) @@
94
    /**
95
     * @test
96
     */
97
    public function provideAnAuthorizationWithoutTypeReturnsError()
98
    {
99
        $authToken = 'ABC-abc';
100
        $request = ServerRequestFactory::fromGlobals()->withAttribute(
101
            RouteResult::class,
102
            RouteResult::fromRouteMatch('bar', 'foo', [])
103
        )->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, $authToken);
104
105
        $response = $this->middleware->__invoke($request, new Response());
106
        $this->assertEquals(401, $response->getStatusCode());
107
        $this->assertTrue(strpos($response->getBody()->getContents(), 'You need to provide the Bearer type') > 0);
108
    }
109
110
    /**
111
     * @test
@@ 113-126 (lines=14) @@
110
    /**
111
     * @test
112
     */
113
    public function provideAnAuthorizationWithWrongTypeReturnsError()
114
    {
115
        $authToken = 'ABC-abc';
116
        $request = ServerRequestFactory::fromGlobals()->withAttribute(
117
            RouteResult::class,
118
            RouteResult::fromRouteMatch('bar', 'foo', [])
119
        )->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'Basic ' . $authToken);
120
121
        $response = $this->middleware->__invoke($request, new Response());
122
        $this->assertEquals(401, $response->getStatusCode());
123
        $this->assertTrue(
124
            strpos($response->getBody()->getContents(), 'Provided authorization type Basic is not supported') > 0
125
        );
126
    }
127
128
    /**
129
     * @test
@@ 131-142 (lines=12) @@
128
    /**
129
     * @test
130
     */
131
    public function provideAnExpiredTokenReturnsError()
132
    {
133
        $authToken = 'ABC-abc';
134
        $request = ServerRequestFactory::fromGlobals()->withAttribute(
135
            RouteResult::class,
136
            RouteResult::fromRouteMatch('bar', 'foo', [])
137
        )->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'Bearer ' . $authToken);
138
        $this->jwtService->verify($authToken)->willReturn(false)->shouldBeCalledTimes(1);
139
140
        $response = $this->middleware->__invoke($request, new Response());
141
        $this->assertEquals(401, $response->getStatusCode());
142
    }
143
144
    /**
145
     * @test