From c003f17ea4cb4e485a7b9daec2221eafcb5cc310 Mon Sep 17 00:00:00 2001 From: aaa2000 Date: Sun, 11 Jan 2026 00:04:02 +0100 Subject: [PATCH] test: add nested property test for uuidfilter @see https://github.com/api-platform/core/pull/7628#issuecomment-3731040848 --- .../Entity/Uuid/RamseyUuidBinaryDevice.php | 6 +++- .../Uuid/RamseyUuidBinaryDeviceEndpoint.php | 4 +++ .../Entity/Uuid/RamseyUuidDevice.php | 6 +++- .../Entity/Uuid/RamseyUuidDeviceEndpoint.php | 4 +++ .../Entity/Uuid/SymfonyUlidDevice.php | 6 +++- .../Entity/Uuid/SymfonyUlidDeviceEndpoint.php | 4 +++ .../Entity/Uuid/SymfonyUuidDevice.php | 6 +++- .../Entity/Uuid/SymfonyUuidDeviceEndpoint.php | 4 +++ .../Uuid/UuidFilterBaseTestCase.php | 35 +++++++++++++++++++ 9 files changed, 71 insertions(+), 4 deletions(-) diff --git a/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidBinaryDevice.php b/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidBinaryDevice.php index 8674dc8495..68e229c502 100644 --- a/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidBinaryDevice.php +++ b/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidBinaryDevice.php @@ -41,8 +41,12 @@ class RamseyUuidBinaryDevice #[ORM\Column(type: 'uuid_binary', unique: true)] public UuidInterface $id; - public function __construct(?UuidInterface $id = null) + #[ORM\Column(type: 'uuid_binary')] + public UuidInterface $externalId; + + public function __construct(?UuidInterface $id = null, ?UuidInterface $externalId = null) { $this->id = $id ?? Uuid::uuid7(); + $this->externalId = $externalId ?? Uuid::uuid7(); } } diff --git a/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidBinaryDeviceEndpoint.php b/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidBinaryDeviceEndpoint.php index a096728272..b75a87eb70 100644 --- a/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidBinaryDeviceEndpoint.php +++ b/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidBinaryDeviceEndpoint.php @@ -33,6 +33,10 @@ 'myDevice' => new QueryParameter( filter: new UuidBinaryFilter(), ), + 'myDeviceExternalIdAlias' => new QueryParameter( + filter: new UuidBinaryFilter(), + property: 'myDevice.externalId', + ), ] ), new Post(), diff --git a/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidDevice.php b/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidDevice.php index 96b0a6e0b4..d68d880cfe 100644 --- a/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidDevice.php +++ b/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidDevice.php @@ -41,8 +41,12 @@ class RamseyUuidDevice #[ORM\Column(type: 'uuid', unique: true)] public UuidInterface $id; - public function __construct(?UuidInterface $id = null) + #[ORM\Column(type: 'uuid')] + public UuidInterface $externalId; + + public function __construct(?UuidInterface $id = null, ?UuidInterface $externalId = null) { $this->id = $id ?? Uuid::uuid7(); + $this->externalId = $externalId ?? Uuid::uuid7(); } } diff --git a/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidDeviceEndpoint.php b/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidDeviceEndpoint.php index e2c1f14690..82632d4173 100644 --- a/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidDeviceEndpoint.php +++ b/tests/Fixtures/TestBundle/Entity/Uuid/RamseyUuidDeviceEndpoint.php @@ -33,6 +33,10 @@ 'myDevice' => new QueryParameter( filter: new UuidFilter(), ), + 'myDeviceExternalIdAlias' => new QueryParameter( + filter: new UuidFilter(), + property: 'myDevice.externalId', + ), ] ), new Post(), diff --git a/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUlidDevice.php b/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUlidDevice.php index 19d39ef8c9..20a4c865ae 100644 --- a/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUlidDevice.php +++ b/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUlidDevice.php @@ -40,8 +40,12 @@ class SymfonyUlidDevice #[ORM\Column(type: 'ulid', unique: true)] public Ulid $id; - public function __construct(?Ulid $id = null) + #[ORM\Column(type: 'ulid')] + public Ulid $externalId; + + public function __construct(?Ulid $id = null, ?Ulid $externalId = null) { $this->id = $id ?? new Ulid(); + $this->externalId = $externalId ?? new Ulid(); } } diff --git a/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUlidDeviceEndpoint.php b/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUlidDeviceEndpoint.php index 8f717b0e6a..f6e2ce562e 100644 --- a/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUlidDeviceEndpoint.php +++ b/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUlidDeviceEndpoint.php @@ -33,6 +33,10 @@ 'myDevice' => new QueryParameter( filter: new UlidFilter(), ), + 'myDeviceExternalIdAlias' => new QueryParameter( + filter: new UlidFilter(), + property: 'myDevice.externalId', + ), ] ), new Post(), diff --git a/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUuidDevice.php b/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUuidDevice.php index 04d85978ab..f61100fa76 100644 --- a/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUuidDevice.php +++ b/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUuidDevice.php @@ -40,8 +40,12 @@ class SymfonyUuidDevice #[ORM\Column(type: 'symfony_uuid', unique: true)] public Uuid $id; - public function __construct(?Uuid $id = null) + #[ORM\Column(type: 'symfony_uuid')] + public Uuid $externalId; + + public function __construct(?Uuid $id = null, ?Uuid $externalId = null) { $this->id = $id ?? Uuid::v7(); + $this->externalId = $externalId ?? Uuid::v7(); } } diff --git a/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUuidDeviceEndpoint.php b/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUuidDeviceEndpoint.php index af9cc3ffa2..2790cf67f5 100644 --- a/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUuidDeviceEndpoint.php +++ b/tests/Fixtures/TestBundle/Entity/Uuid/SymfonyUuidDeviceEndpoint.php @@ -32,6 +32,10 @@ 'myDevice' => new QueryParameter( filter: new UuidFilter(), ), + 'myDeviceExternalIdAlias' => new QueryParameter( + filter: new UuidFilter(), + property: 'myDevice.externalId', + ), ] ), new Post(), diff --git a/tests/Functional/Uuid/UuidFilterBaseTestCase.php b/tests/Functional/Uuid/UuidFilterBaseTestCase.php index c6227b33c9..f319ee97c9 100644 --- a/tests/Functional/Uuid/UuidFilterBaseTestCase.php +++ b/tests/Functional/Uuid/UuidFilterBaseTestCase.php @@ -314,6 +314,41 @@ public function testGetOpenApiDescription(): void ); } + public function testSearchFilterByUuidNested(): void + { + $this->recreateSchema(static::getResources()); + + $manager = $this->getManager(); + $manager->persist($fooDevice = $this->createDevice()); + $manager->persist($barDevice = $this->createDevice()); + $manager->persist($this->createDeviceEndpoint(null, $fooDevice)); + $manager->persist($expectedDeviceEndpoint = $this->createDeviceEndpoint(null, $barDevice)); + $manager->flush(); + + $response = self::createClient()->request('GET', '/'.$this->getUrlPrefix().'_device_endpoints', [ + 'query' => [ + 'myDeviceExternalIdAlias' => (string) $expectedDeviceEndpoint->myDevice->externalId, + ], + ]); + + self::assertResponseIsSuccessful(); + $json = $response->toArray(); + + self::assertArraySubset(['hydra:totalItems' => 1], $json); + self::assertArraySubset( + [ + 'hydra:member' => [ + [ + '@id' => '/'.$this->getUrlPrefix().'_device_endpoints/'.$expectedDeviceEndpoint->id, + '@type' => $this->geTypePrefix().'DeviceEndpoint', + 'id' => (string) $expectedDeviceEndpoint->id, + ], + ], + ], + $json + ); + } + protected function tearDown(): void { if ($this->isMongoDB()) {