Skip to content

Commit e60cd56

Browse files
committed
DeprecationMiddlewareTest: removed testDeprecationMethodUsesRequestMethod
Signed-off-by: alexmerlin <[email protected]>
1 parent 0a84297 commit e60cd56

File tree

4 files changed

+22
-68
lines changed

4 files changed

+22
-68
lines changed

src/App/src/ConfigProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public function getHalConfig(): array
8383
return [];
8484
}
8585

86+
/**
87+
* @param class-string $collectionClass
88+
*/
8689
public static function getCollection(string $collectionClass, string $route, string $collectionRelation): array
8790
{
8891
return [
@@ -93,6 +96,9 @@ public static function getCollection(string $collectionClass, string $route, str
9396
];
9497
}
9598

99+
/**
100+
* @param class-string $resourceClass
101+
*/
96102
public static function getResource(
97103
string $resourceClass,
98104
string $route,

src/App/src/Handler/AbstractHandler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ abstract class AbstractHandler implements RequestHandlerInterface
2323
protected ?HalResponseFactory $responseFactory = null;
2424
protected ?ResourceGenerator $resourceGenerator = null;
2525

26+
abstract public function handle(ServerRequestInterface $request): ResponseInterface;
27+
2628
public function setResponseFactory(HalResponseFactory $responseFactory): self
2729
{
2830
$this->responseFactory = $responseFactory;

src/App/src/Middleware/DeprecationMiddleware.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use function implode;
3131
use function is_string;
3232
use function sprintf;
33-
use function strtoupper;
3433

3534
class DeprecationMiddleware implements MiddlewareInterface
3635
{
@@ -79,7 +78,7 @@ public function process(
7978
}
8079

8180
$this->validateAttributes($attributes);
82-
$attribute = $this->getAttribute($attributes, $request->getMethod());
81+
$attribute = $this->getAttribute($attributes);
8382
if (null === $attribute) {
8483
return $response;
8584
}
@@ -96,17 +95,22 @@ public function process(
9695
return $response;
9796
}
9897

99-
private function getAttribute(array $attributes, string $requestMethod): ?array
98+
private function getAttribute(array $attributes): ?array
10099
{
101-
$attribute = array_values(array_filter($attributes, function (array $attribute): bool {
102-
return $attribute['deprecationType'] === self::RESOURCE_DEPRECATION_ATTRIBUTE;
103-
}))[0] ?? null;
100+
$attribute = array_values(
101+
array_filter(
102+
$attributes,
103+
fn (array $attribute): bool => $attribute['deprecationType'] === self::RESOURCE_DEPRECATION_ATTRIBUTE
104+
)
105+
)[0] ?? null;
104106

105107
if (null === $attribute) {
106-
$attribute = array_values(array_filter($attributes, function (array $attr) use ($requestMethod): bool {
107-
return $attr['deprecationType'] === self::METHOD_DEPRECATION_ATTRIBUTE &&
108-
strtoupper($attr['identifier']) === strtoupper($requestMethod);
109-
}))[0] ?? null;
108+
$attribute = array_values(
109+
array_filter(
110+
$attributes,
111+
fn (array $attribute): bool => $attribute['deprecationType'] === self::METHOD_DEPRECATION_ATTRIBUTE
112+
)
113+
)[0] ?? null;
110114
}
111115

112116
return $attribute;

test/Unit/App/Middleware/DeprecationMiddlewareTest.php

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Api\App\Attribute\MethodDeprecation;
88
use Api\App\Attribute\ResourceDeprecation;
99
use Api\App\Exception\DeprecationConflictException;
10-
use Api\App\Handler\AbstractHandler;
1110
use Api\App\Middleware\DeprecationMiddleware as Subject;
1211
use Core\App\Message;
1312
use Fig\Http\Message\RequestMethodInterface;
@@ -204,63 +203,6 @@ public function process(
204203
]), $response->getHeader('link')[0]);
205204
}
206205

207-
/**
208-
* @throws ReflectionException
209-
* @throws Exception
210-
*/
211-
public function testDeprecationMethodUsesRequestMethod(): void
212-
{
213-
$handler = new class extends AbstractHandler {
214-
#[MethodDeprecation(
215-
sunset: '2038-01-01',
216-
link: 'get-test-link',
217-
deprecationReason: 'get-test-deprecation-reason',
218-
rel: 'get-rel',
219-
type: 'get-type',
220-
)]
221-
public function get(): ResponseInterface
222-
{
223-
return new EmptyResponse();
224-
}
225-
226-
#[MethodDeprecation(
227-
sunset: '2038-01-01',
228-
link: 'post-test-link',
229-
deprecationReason: 'post-test-deprecation-reason',
230-
rel: 'post-rel',
231-
type: 'post-type',
232-
)]
233-
public function post(): ResponseInterface
234-
{
235-
return new EmptyResponse();
236-
}
237-
};
238-
239-
$routeResult = $this->createMock(RouteResult::class);
240-
$route = $this->createMock(Route::class);
241-
$lazyLoadingMiddleware = new LazyLoadingMiddleware(
242-
$this->createMock(MiddlewareContainer::class),
243-
$handler::class,
244-
);
245-
246-
$route->method('getMiddleware')->willReturn($lazyLoadingMiddleware);
247-
$routeResult->method('isFailure')->willReturn(false);
248-
$routeResult->method('getMatchedRoute')->willReturn($route);
249-
$this->request->method('getAttribute')->with(RouteResult::class)->willReturn($routeResult);
250-
$this->request->method('getMethod')->willReturn(RequestMethodInterface::METHOD_POST);
251-
$this->handler->method('handle')->with($this->request)->willReturn($this->response);
252-
253-
$response = $this->subject->process($this->request, $this->handler);
254-
255-
$this->assertTrue($response->hasHeader('sunset'));
256-
$this->assertTrue($response->hasHeader('link'));
257-
$this->assertSame('2038-01-01', $response->getHeader('sunset')[0]);
258-
$this->assertSame($this->formatLink('post-test-link', [
259-
'rel' => 'post-rel',
260-
'type' => 'post-type',
261-
]), $response->getHeader('link')[0]);
262-
}
263-
264206
/**
265207
* @throws ReflectionException
266208
* @throws Exception

0 commit comments

Comments
 (0)