Skip to content

Commit fe8ee5a

Browse files
aaa2000soyuka
authored andcommitted
test: add nested property test for uuidfilter
@see api-platform#7628 (comment)
1 parent f5f72c4 commit fe8ee5a

File tree

9 files changed

+72
-4
lines changed

9 files changed

+72
-4
lines changed

tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidBinaryDevice.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ class RamseyUuidBinaryDevice
4141
#[ORM\Column(type: 'uuid_binary', unique: true)]
4242
public UuidInterface $id;
4343

44-
public function __construct(?UuidInterface $id = null)
44+
#[ORM\Column(type: 'uuid_binary')]
45+
public UuidInterface $externalId;
46+
47+
public function __construct(?UuidInterface $id = null, ?UuidInterface $externalId = null)
4548
{
4649
$this->id = $id ?? Uuid::uuid7();
50+
$this->externalId = $externalId ?? Uuid::uuid7();
4751
}
4852
}

tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidBinaryDeviceEndpoint.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
'myDevice' => new QueryParameter(
3434
filter: new UuidBinaryFilter(),
3535
),
36+
'myDeviceExternalIdAlias' => new QueryParameter(
37+
filter: new UuidBinaryFilter(),
38+
property: 'myDevice.externalId',
39+
),
3640
]
3741
),
3842
new Post(),

tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidDevice.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ class RamseyUuidDevice
4141
#[ORM\Column(type: 'uuid', unique: true)]
4242
public UuidInterface $id;
4343

44-
public function __construct(?UuidInterface $id = null)
44+
#[ORM\Column(type: 'uuid')]
45+
public UuidInterface $externalId;
46+
47+
public function __construct(?UuidInterface $id = null, ?UuidInterface $externalId = null)
4548
{
4649
$this->id = $id ?? Uuid::uuid7();
50+
$this->externalId = $externalId ?? Uuid::uuid7();
4751
}
4852
}

tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidDeviceEndpoint.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
'myDevice' => new QueryParameter(
3434
filter: new UuidFilter(),
3535
),
36+
'myDeviceExternalIdAlias' => new QueryParameter(
37+
filter: new UuidFilter(),
38+
property: 'myDevice.externalId',
39+
),
3640
]
3741
),
3842
new Post(),

tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUlidDevice.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ class SymfonyUlidDevice
4040
#[ORM\Column(type: 'ulid', unique: true)]
4141
public Ulid $id;
4242

43-
public function __construct(?Ulid $id = null)
43+
#[ORM\Column(type: 'ulid')]
44+
public Ulid $externalId;
45+
46+
public function __construct(?Ulid $id = null, ?Ulid $externalId = null)
4447
{
4548
$this->id = $id ?? new Ulid();
49+
$this->externalId = $externalId ?? new Ulid();
4650
}
4751
}

tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUlidDeviceEndpoint.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
'myDevice' => new QueryParameter(
3434
filter: new UlidFilter(),
3535
),
36+
'myDeviceExternalIdAlias' => new QueryParameter(
37+
filter: new UlidFilter(),
38+
property: 'myDevice.externalId',
39+
),
3640
]
3741
),
3842
new Post(),

tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUuidDevice.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ class SymfonyUuidDevice
4040
#[ORM\Column(type: 'symfony_uuid', unique: true)]
4141
public Uuid $id;
4242

43-
public function __construct(?Uuid $id = null)
43+
#[ORM\Column(type: 'symfony_uuid')]
44+
public Uuid $externalId;
45+
46+
public function __construct(?Uuid $id = null, ?Uuid $externalId = null)
4447
{
4548
$this->id = $id ?? Uuid::v7();
49+
$this->externalId = $externalId ?? Uuid::v7();
4650
}
4751
}

tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUuidDeviceEndpoint.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
'myDevice' => new QueryParameter(
3333
filter: new UuidFilter(),
3434
),
35+
'myDeviceExternalIdAlias' => new QueryParameter(
36+
filter: new UuidFilter(),
37+
property: 'myDevice.externalId',
38+
),
3539
]
3640
),
3741
new Post(),

tests/Functional/Uuid/UuidFilterBaseTestCase.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
1717
use ApiPlatform\Tests\RecreateSchemaTrait;
1818
use ApiPlatform\Tests\SetupClassResourcesTrait;
19+
use Doctrine\ORM\EntityManagerInterface;
1920
use Symfony\Component\HttpFoundation\Response;
2021

2122
abstract class UuidFilterBaseTestCase extends ApiTestCase
@@ -314,6 +315,41 @@ public function testGetOpenApiDescription(): void
314315
);
315316
}
316317

318+
public function testSearchFilterByUuidNested(): void
319+
{
320+
$this->recreateSchema(static::getResources());
321+
322+
$manager = $this->getManager();
323+
$manager->persist($fooDevice = $this->createDevice());
324+
$manager->persist($barDevice = $this->createDevice());
325+
$manager->persist($this->createDeviceEndpoint(null, $fooDevice));
326+
$manager->persist($expectedDeviceEndpoint = $this->createDeviceEndpoint(null, $barDevice));
327+
$manager->flush();
328+
329+
$response = self::createClient()->request('GET', '/'.$this->getUrlPrefix().'_device_endpoints', [
330+
'query' => [
331+
'myDeviceExternalIdAlias' => (string) $expectedDeviceEndpoint->myDevice->externalId,
332+
],
333+
]);
334+
335+
self::assertResponseIsSuccessful();
336+
$json = $response->toArray();
337+
338+
self::assertArraySubset(['hydra:totalItems' => 1], $json);
339+
self::assertArraySubset(
340+
[
341+
'hydra:member' => [
342+
[
343+
'@id' => '/'.$this->getUrlPrefix().'_device_endpoints/'.$expectedDeviceEndpoint->id,
344+
'@type' => $this->geTypePrefix().'DeviceEndpoint',
345+
'id' => (string) $expectedDeviceEndpoint->id,
346+
],
347+
],
348+
],
349+
$json
350+
);
351+
}
352+
317353
protected function tearDown(): void
318354
{
319355
if ($this->isMongoDB()) {

0 commit comments

Comments
 (0)