Skip to content

Commit

Permalink
-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alexndlm committed Sep 19, 2024
1 parent 5435e13 commit d748c7f
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace EonX\EasyApiPlatform\Common\StateProvider;

use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Post;
use ApiPlatform\State\ProviderInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

Expand All @@ -19,7 +18,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
{
$data = $this->decorated->provide($operation, $uriVariables, $context);

if ($data === null && $operation instanceof Post && \count($uriVariables) > 0) {
if ($data === null && $operation->canRead()) {
throw new NotFoundHttpException('Not Found');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,27 @@ public function testItSucceeds(): void
self::assertSame(404, $response->getStatusCode());
}

public function testItSucceedsWhenOperationWithoutRead(): void
{
$this->initDatabase();

$response = self::$client->request(
'POST',
'/incoming-webhooks/some-value',
[
'headers' => [
'content-type' => 'application/json',
],
'json' => [],
]
);

self::assertSame(204, $response->getStatusCode());
}

public function testItSucceedsWhenReturn404OnPostDisabled(): void
{
self::setUpClient(['environment' => 'return_404_on_post', 'debug' => true]);
self::setUpClient(['environment' => 'return_404_on_post']);
$this->initDatabase();

$response = self::$client->request(
Expand All @@ -40,7 +58,6 @@ public function testItSucceedsWhenReturn404OnPostDisabled(): void
);
self::assertSame(500, $response->getStatusCode());
$responseData = \json_decode($response->getContent(false), true);
dump($responseData);
self::assertSame(403, $responseData['custom_code']);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);

namespace EonX\EasyApiPlatform\Tests\Fixture\App\Return404OnPost\ApiResource;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Post;
use EonX\EasyApiPlatform\Tests\Fixture\App\Return404OnPost\Controller\IncomingWebhookController;

#[ApiResource(
operations: [
new Post(
uriTemplate: '/incoming-webhooks/{someExtraVariable}',
status: 204,
controller: IncomingWebhookController::class,
openapiContext: [
'parameters' => [
[
'description' => 'Some extra variable',
'in' => 'path',
'name' => 'someExtraVariable',
'required' => true,
'schema' => ['type' => 'string'],
],
],
'responses' => [
204 => [
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
],
],
],
],
],
],
read: false,
),
]
)]
final class IncomingWebhook
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);

namespace EonX\EasyApiPlatform\Tests\Fixture\App\Return404OnPost\Controller;

use stdClass;
use Symfony\Component\HttpKernel\Attribute\AsController;

#[AsController]
final class IncomingWebhookController
{
public function __invoke(string $someExtraVariable): stdClass
{
return new stdClass();
}
}

0 comments on commit d748c7f

Please sign in to comment.