Skip to content

Commit 6e83dd9

Browse files
committed
Merge 4.2
2 parents d13c247 + 1706c3c commit 6e83dd9

File tree

11 files changed

+100
-29
lines changed

11 files changed

+100
-29
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ jobs:
484484
continue-on-error: true
485485

486486
postgresql:
487-
name: Behat (PHP ${{ matrix.php }}) (PostgreSQL)
487+
name: PHPUnit + Behat (PHP ${{ matrix.php }}) (PostgreSQL)
488488
runs-on: ubuntu-latest
489489
timeout-minutes: 20
490490
strategy:
@@ -529,12 +529,16 @@ jobs:
529529
composer global link .
530530
- name: Clear test app cache
531531
run: tests/Fixtures/app/console cache:clear --ansi
532+
- name: Run PHPUnit tests
533+
run: vendor/bin/phpunit
534+
- name: Clear test app cache
535+
run: tests/Fixtures/app/console cache:clear --ansi
532536
- name: Run Behat tests
533537
run: |
534538
vendor/bin/behat --out=std --format=progress --profile=postgres --no-interaction -vv
535539
536540
mysql:
537-
name: Behat (PHP ${{ matrix.php }}) (MySQL)
541+
name: PHPUnit + Behat (PHP ${{ matrix.php }}) (MySQL)
538542
runs-on: ubuntu-latest
539543
timeout-minutes: 20
540544
strategy:
@@ -580,6 +584,10 @@ jobs:
580584
composer global link .
581585
- name: Clear test app cache
582586
run: tests/Fixtures/app/console cache:clear --ansi
587+
- name: Run PHPUnit tests
588+
run: vendor/bin/phpunit
589+
- name: Clear test app cache
590+
run: tests/Fixtures/app/console cache:clear --ansi
583591
- name: Run Behat tests
584592
run: vendor/bin/behat --out=std --format=progress --profile=default --no-interaction --tags '~@!mysql'
585593

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It natively supports popular open formats including [JSON for Linked Data (JSON-
99
Build a working and fully-featured web API in minutes. Leverage the awesome features of the tool to develop complex and
1010
high-performance API-first projects. Extend or override everything you want.
1111

12-
[![GitHub Actions](https://github.com/api-platform/core/workflows/CI/badge.svg?branch=main)](https://github.com/api-platform/core/actions?query=workflow%3ACI+branch%3Amain)
12+
[![GitHub Actions](https://github.com/api-platform/core/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/api-platform/core/actions?query=workflow%3ACI+branch%3Amain)
1313

1414
## Documentation
1515

src/Doctrine/Orm/Filter/PartialSearchFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $q
4040
$property = $parameter->getProperty();
4141
$alias = $queryBuilder->getRootAliases()[0];
4242
$field = $alias.'.'.$property;
43-
$parameterName = $queryNameGenerator->generateParameterName($property);
4443
$values = $parameter->getValue();
4544

4645
if (!is_iterable($values)) {
46+
$parameterName = $queryNameGenerator->generateParameterName($property);
4747
$queryBuilder->setParameter($parameterName, $this->formatLikeValue(strtolower($values)));
4848

4949
$likeExpression = 'LOWER('.$field.') LIKE :'.$parameterName.' ESCAPE \'\\\'';

tests/Fixtures/TestBundle/Document/FilteredOrderParameter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@
3838
'date_null_always_first' => new QueryParameter(
3939
filter: new OrderFilter(),
4040
property: 'createdAt',
41-
filterContext: OrderFilterInterface::NULLS_ALWAYS_FIRST,
41+
filterContext: ['nulls_comparison' => OrderFilterInterface::NULLS_ALWAYS_FIRST],
4242
nativeType: new BuiltinType(TypeIdentifier::STRING)
4343
),
4444
'date_null_always_first_old_way' => new QueryParameter(
45-
filter: new OrderFilter(properties: ['createdAt' => OrderFilterInterface::NULLS_ALWAYS_FIRST]),
45+
filter: new OrderFilter(properties: ['createdAt' => ['nulls_comparison' => OrderFilterInterface::NULLS_ALWAYS_FIRST]]),
4646
property: 'createdAt',
4747
nativeType: new BuiltinType(TypeIdentifier::STRING)
4848
),
4949
'order[:property]' => new QueryParameter(
5050
filter: new OrderFilter(),
51-
filterContext: OrderFilterInterface::NULLS_ALWAYS_FIRST,
51+
filterContext: ['nulls_comparison' => OrderFilterInterface::NULLS_ALWAYS_FIRST],
5252
),
5353
],
5454
)]

tests/Fixtures/TestBundle/Entity/Cart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static function handleLinks(QueryBuilder $queryBuilder, array $uriVariabl
6262
->addGroupBy(\sprintf('%s.id', $rootAlias));
6363
}
6464

65-
public ?int $totalQuantity;
65+
public int|string|null $totalQuantity;
6666

6767
#[ORM\Id]
6868
#[ORM\GeneratedValue]

tests/Fixtures/TestBundle/Entity/FilteredOrderParameter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@
3838
'date_null_always_first' => new QueryParameter(
3939
filter: new OrderFilter(),
4040
property: 'createdAt',
41-
filterContext: OrderFilterInterface::NULLS_ALWAYS_FIRST,
41+
filterContext: ['nulls_comparison' => OrderFilterInterface::NULLS_ALWAYS_FIRST],
4242
nativeType: new BuiltinType(TypeIdentifier::STRING)
4343
),
4444
'date_null_always_first_old_way' => new QueryParameter(
45-
filter: new OrderFilter(properties: ['createdAt' => OrderFilterInterface::NULLS_ALWAYS_FIRST]),
45+
filter: new OrderFilter(properties: ['createdAt' => ['nulls_comparison' => OrderFilterInterface::NULLS_ALWAYS_FIRST]]),
4646
property: 'createdAt',
4747
nativeType: new BuiltinType(TypeIdentifier::STRING)
4848
),
4949
'order[:property]' => new QueryParameter(
5050
filter: new OrderFilter(),
51-
filterContext: OrderFilterInterface::NULLS_ALWAYS_FIRST,
51+
filterContext: ['nulls_comparison' => OrderFilterInterface::NULLS_ALWAYS_FIRST],
5252
),
5353
],
5454
)]

tests/Fixtures/TestBundle/Entity/Issue6041/NumericValidated.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class NumericValidated
3232
private ?int $id = null;
3333

3434
#[Assert\Range(min: 1, max: 10)]
35-
#[ORM\Column]
35+
#[ORM\Column(name: '_range')]
3636
public int $range;
3737

3838
#[Assert\GreaterThan(value: 10)]

tests/Functional/JsonStreamerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function testJsonStreamerWriteJsonLd(): void
229229
$this->assertSame(0, $res['views']);
230230
$this->assertSame(0, $res['rating']);
231231
$this->assertFalse($res['isFeatured']);
232-
$this->assertSame('0', $res['price']);
232+
$this->assertContains($res['price'], ['0', '0.00']); // Depends on DB
233233
$this->assertStringStartsWith('/json_stream_resources/', $res['@id']);
234234
$this->assertSame('/contexts/JsonStreamResource', $res['@context']);
235235

@@ -273,7 +273,7 @@ public function testJsonStreamerWriteJson(): void
273273
$this->assertSame(0, $res['views']);
274274
$this->assertSame(0, $res['rating']);
275275
$this->assertFalse($res['isFeatured']);
276-
$this->assertSame('0', $res['price']);
276+
$this->assertContains($res['price'], ['0', '0.00']); // Depends on DB
277277
$this->assertArrayNotHasKey('@id', $res);
278278
$this->assertArrayNotHasKey('@type', $res);
279279
$this->assertArrayNotHasKey('@context', $res);

tests/Functional/Parameters/IriFilterTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ public static function getResources(): array
4040
public function testIriFilter(): void
4141
{
4242
$client = $this->createClient();
43+
4344
$res = $client->request('GET', '/chickens?chickenCoop=/chicken_coops/2')->toArray();
4445
$this->assertCount(1, $res['member']);
4546
$this->assertEquals('/chicken_coops/2', $res['member'][0]['chickenCoop']);
47+
48+
$res = $client->request('GET', '/chickens?chickenCoop=/chicken_coops/595')->toArray();
49+
$this->assertCount(0, $res['member']);
4650
}
4751

4852
public function testIriFilterMultiple(): void

tests/Functional/Parameters/OrderFilterTest.php

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace ApiPlatform\Tests\Functional\Parameters;
1515

16+
use ApiPlatform\Doctrine\Odm\Filter\OrderFilter;
1617
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
1718
use ApiPlatform\Tests\Fixtures\TestBundle\Document\FilteredOrderParameter as FilteredOrderParameterDocument;
1819
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\FilteredOrderParameter;
@@ -58,6 +59,12 @@ public function testOrderFilterResponses(string $url, array $expectedOrder): voi
5859

5960
$actualOrder = array_map(fn ($item) => $item['createdAt'] ?? null, $orderedItems);
6061

62+
// Default NULL order is different in PostgreSQL.
63+
if ($this->isPostgres()) {
64+
$actualOrder = array_values(array_filter($actualOrder));
65+
$expectedOrder = array_values(array_filter($expectedOrder));
66+
}
67+
6168
$this->assertSame($expectedOrder, $actualOrder, \sprintf('Expected order does not match for URL %s', $url));
6269
}
6370

@@ -79,29 +86,51 @@ public static function orderFilterScenariosProvider(): \Generator
7986
'/filtered_order_parameters?date=desc',
8087
['2024-12-25T00:00:00+00:00', '2024-06-15T00:00:00+00:00', '2024-01-01T00:00:00+00:00', null],
8188
];
82-
yield 'date_null_always_first_alias_nulls_first' => [
89+
}
90+
91+
#[DataProvider('orderFilterNullsComparisonScenariosProvider')]
92+
public function testOrderFilterNullsComparisonResponses(string $url, array $expectedOrder): void
93+
{
94+
if ($this->isMongoDB()) {
95+
$this->markTestSkipped(\sprintf('Not implemented in %s', OrderFilter::class));
96+
}
97+
98+
$response = self::createClient()->request('GET', $url);
99+
$this->assertResponseIsSuccessful();
100+
101+
$responseData = $response->toArray();
102+
$orderedItems = $responseData['hydra:member'];
103+
104+
$actualOrder = array_map(fn ($item) => $item['createdAt'] ?? null, $orderedItems);
105+
106+
$this->assertSame($expectedOrder, $actualOrder, \sprintf('Expected order does not match for URL %s', $url));
107+
}
108+
109+
public static function orderFilterNullsComparisonScenariosProvider(): \Generator
110+
{
111+
yield 'date_null_always_first_alias_asc' => [
83112
'/filtered_order_parameters?date_null_always_first=asc',
84113
[null, '2024-01-01T00:00:00+00:00', '2024-06-15T00:00:00+00:00', '2024-12-25T00:00:00+00:00'],
85114
];
86-
yield 'date_null_always_first_alias_nulls_last' => [
115+
yield 'date_null_always_first_alias_desc' => [
87116
'/filtered_order_parameters?date_null_always_first=desc',
88-
['2024-12-25T00:00:00+00:00', '2024-06-15T00:00:00+00:00', '2024-01-01T00:00:00+00:00', null],
117+
[null, '2024-12-25T00:00:00+00:00', '2024-06-15T00:00:00+00:00', '2024-01-01T00:00:00+00:00'],
89118
];
90-
yield 'date_null_always_first_old_way_alias_nulls_first' => [
119+
yield 'date_null_always_first_old_way_alias_asc' => [
91120
'/filtered_order_parameters?date_null_always_first_old_way=asc',
92121
[null, '2024-01-01T00:00:00+00:00', '2024-06-15T00:00:00+00:00', '2024-12-25T00:00:00+00:00'],
93122
];
94-
yield 'date_null_always_first_old_way_alias_nulls_last' => [
123+
yield 'date_null_always_first_old_way_alias_desc' => [
95124
'/filtered_order_parameters?date_null_always_first_old_way=desc',
96-
['2024-12-25T00:00:00+00:00', '2024-06-15T00:00:00+00:00', '2024-01-01T00:00:00+00:00', null],
125+
[null, '2024-12-25T00:00:00+00:00', '2024-06-15T00:00:00+00:00', '2024-01-01T00:00:00+00:00'],
97126
];
98-
yield 'order_property_created_at_nulls_first' => [
127+
yield 'order_property_created_at_null_first_asc' => [
99128
'/filtered_order_parameters?order[createdAt]=asc',
100129
[null, '2024-01-01T00:00:00+00:00', '2024-06-15T00:00:00+00:00', '2024-12-25T00:00:00+00:00'],
101130
];
102-
yield 'order_property_created_at_nulls_last' => [
131+
yield 'order_property_created_at_null_first_desc' => [
103132
'/filtered_order_parameters?order[createdAt]=desc',
104-
['2024-12-25T00:00:00+00:00', '2024-06-15T00:00:00+00:00', '2024-01-01T00:00:00+00:00', null],
133+
[null, '2024-12-25T00:00:00+00:00', '2024-06-15T00:00:00+00:00', '2024-01-01T00:00:00+00:00'],
105134
];
106135
}
107136

0 commit comments

Comments
 (0)