forked from api-platform/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
128 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\State\Exception; | ||
|
||
use ApiPlatform\Metadata\Exception\ProblemExceptionInterface; | ||
use ApiPlatform\Metadata\Exception\RuntimeException; | ||
|
||
final class ParameterNotSupportedException extends RuntimeException implements ProblemExceptionInterface | ||
{ | ||
public function __construct(private readonly string $parameter, string $message = "Parameter not supported", int $code = 0, \Throwable|null $previous = null) { | ||
public function __construct(private readonly string $parameter, string $message = 'Parameter not supported', int $code = 0, ?\Throwable $previous = null) | ||
{ | ||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
|
@@ -28,7 +40,7 @@ public function getStatus(): ?int | |
|
||
public function getDetail(): ?string | ||
{ | ||
return sprintf('Parameter "%s" not supported', $this->parameter); | ||
return \sprintf('Parameter "%s" not supported', $this->parameter); | ||
} | ||
|
||
public function getInstance(): ?string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/Fixtures/TestBundle/ApiResource/StrictParameters.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource; | ||
|
||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\QueryParameter; | ||
|
||
#[Get( | ||
uriTemplate: 'strict_query_parameters', | ||
strictQueryParameterValidation: true, | ||
parameters: [ | ||
'foo' => new QueryParameter(), | ||
], | ||
provider: [self::class, 'provider'] | ||
)] | ||
class StrictParameters | ||
{ | ||
public string $id; | ||
|
||
public static function provider() | ||
{ | ||
return new self(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Functional\Parameters; | ||
|
||
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\StrictParameters; | ||
use ApiPlatform\Tests\SetupClassResourcesTrait; | ||
|
||
final class StrictParametersTest extends ApiTestCase | ||
{ | ||
use SetupClassResourcesTrait; | ||
|
||
/** | ||
* @return class-string[] | ||
*/ | ||
public static function getResources(): array | ||
{ | ||
return [StrictParameters::class]; | ||
} | ||
|
||
public function testErrorAsParameterIsNotAllowed(): void | ||
{ | ||
self::createClient()->request('GET', 'strict_query_parameters?bar=test'); | ||
$this->assertJsonContains(['detail' => 'Parameter not supported']); | ||
$this->assertResponseStatusCodeSame(400); | ||
} | ||
|
||
public function testCorrectParameters(): void | ||
{ | ||
self::createClient()->request('GET', 'strict_query_parameters'); | ||
$this->assertResponseStatusCodeSame(200); | ||
self::createClient()->request('GET', 'strict_query_parameters?foo=test'); | ||
$this->assertResponseStatusCodeSame(200); | ||
} | ||
} |