Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 0 additions & 118 deletions features/doctrine/order_filter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -241,65 +241,6 @@ Feature: Order filter on collections
}
"""

Scenario: Get collection ordered by default configured order on a string property and on which order filter has been enabled in whitelist mode with default descending order
When I send a "GET" request to "/dummies?order[name]"
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be valid according to this schema:
"""
{
"type": "object",
"properties": {
"@context": {"pattern": "^/contexts/Dummy$"},
"@id": {"pattern": "^/dummies$"},
"@type": {"pattern": "^hydra:Collection$"},
"hydra:member": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"@id": {
"type": "string",
"pattern": "^/dummies/9$"
}
}
},
{
"type": "object",
"properties": {
"@id": {
"type": "string",
"pattern": "^/dummies/8$"
}
}
},
{
"type": "object",
"properties": {
"@id": {
"type": "string",
"pattern": "^/dummies/7$"
}
}
}
],
"additionalItems": false,
"maxItems": 3,
"minItems": 3
},
"hydra:view": {
"type": "object",
"properties": {
"@id": {"pattern": "^/dummies\\?order%5Bname%5D="},
"@type": {"pattern": "^hydra:PartialCollectionView$"}
}
}
}
}
"""

Scenario: Get collection ordered collection on several property keep the order
# Adding 30 more data with the same name
Given there are 30 dummy objects
Expand Down Expand Up @@ -539,65 +480,6 @@ Feature: Order filter on collections
}
"""

Scenario: Get a collection even if the order parameter is not well-formed
When I send a "GET" request to "/dummies?sort=id&order=asc"
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be valid according to this schema:
"""
{
"type": "object",
"properties": {
"@context": {"pattern": "^/contexts/Dummy$"},
"@id": {"pattern": "^/dummies$"},
"@type": {"pattern": "^hydra:Collection$"},
"hydra:member": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"@id": {
"type": "string",
"pattern": "^/dummies/1$"
}
}
},
{
"type": "object",
"properties": {
"@id": {
"type": "string",
"pattern": "^/dummies/2$"
}
}
},
{
"type": "object",
"properties": {
"@id": {
"type": "string",
"pattern": "^/dummies/3$"
}
}
}
],
"additionalItems": false,
"maxItems": 3,
"minItems": 3
},
"hydra:view": {
"type": "object",
"properties": {
"@id": {"pattern": "^/dummies"},
"@type": {"pattern": "^hydra:PartialCollectionView$"}
}
}
}
}
"""

Scenario: Get collection ordered by a non valid properties and on which order filter has been enabled in whitelist mode
When I send a "GET" request to "/dummies?order[alias]=asc"
Then the response status code should be 200
Expand Down
2 changes: 1 addition & 1 deletion src/State/Provider/ParameterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
unset($parameter->getExtraProperties()['_api_values']);
}

if (($default = $parameter->getSchema()['default'] ?? false) && ($value instanceof ParameterNotFound || !$value)) {
if (null !== ($default = $parameter->getSchema()['default'] ?? true) && $value instanceof ParameterNotFound) {
$value = $default;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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\Issue7354;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\QueryParameter;

#[ApiResource(
operations: [
new Get(
normalizationContext: ['hydra_prefix' => false],
uriTemplate: '/issue7354_boolean_query_parameters',
parameters: [
'booleanParameter' => new QueryParameter(
schema: [

Check failure on line 28 in tests/Fixtures/TestBundle/ApiResource/Issue7354/BooleanQueryParameter.php

View workflow job for this annotation

GitHub Actions / PHPStan (PHP 8.4)

Parameter $schema of class ApiPlatform\Metadata\QueryParameter constructor expects array{type?: string, default?: string}|null, array{type: 'boolean', default: true} given.
'type' => 'boolean',
'default' => true,
],
castToNativeType: true,
),
],
provider: [self::class, 'provide'],
),
]
)]
class BooleanQueryParameter
{
public function __construct(public bool $booleanParameter)
{
}

public static function provide(Operation $operation): self
{
return new self($operation->getParameters()->get('booleanParameter')->getValue());
}
}
54 changes: 54 additions & 0 deletions tests/Functional/Issue7354Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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;

use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue7354\BooleanQueryParameter;
use ApiPlatform\Tests\SetupClassResourcesTrait;

final class Issue7354Test extends ApiTestCase
{
use SetupClassResourcesTrait;

protected static ?bool $alwaysBootKernel = false;

/**
* @return class-string[]
*/
public static function getResources(): array
{
return [BooleanQueryParameter::class];
}

public function testBooleanQueryParameterDefaultOverride(): void
{
self::createClient()->request('GET', '/issue7354_boolean_query_parameters?booleanParameter=false');
$this->assertResponseIsSuccessful();
$this->assertJsonContains(['booleanParameter' => false]);
}

public function testBooleanQueryParameterDefaultNotOverride(): void
{
self::createClient()->request('GET', '/issue7354_boolean_query_parameters?booleanParameter=true');
$this->assertResponseIsSuccessful();
$this->assertJsonContains(['booleanParameter' => true]);
}

public function testBooleanQueryParameterDefaultValue(): void
{
self::createClient()->request('GET', '/issue7354_boolean_query_parameters');
$this->assertResponseIsSuccessful();
$this->assertJsonContains(['booleanParameter' => true]);
}
}
Loading