Skip to content

Commit c003f17

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

File tree

9 files changed

+71
-4
lines changed

9 files changed

+71
-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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,41 @@ public function testGetOpenApiDescription(): void
314314
);
315315
}
316316

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

0 commit comments

Comments
 (0)