Skip to content

Commit 01d1a1e

Browse files
committed
update tests to reflect query changes with UUID work
1 parent bf34b36 commit 01d1a1e

File tree

5 files changed

+84
-16
lines changed

5 files changed

+84
-16
lines changed

src/Bridge/Doctrine/Orm/Filter/SearchFilter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryBuilderHelper;
2121
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
2222
use ApiPlatform\Core\Exception\InvalidArgumentException;
23+
use Doctrine\Common\Collections\ArrayCollection;
2324
use Doctrine\DBAL\Types\Type as DBALType;
2425
use Doctrine\ORM\Query\Parameter;
2526
use Doctrine\ORM\QueryBuilder;
@@ -151,11 +152,9 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
151152
$inQuery[] = ':'.$valueParameter;
152153
$args[] = new Parameter($valueParameter, $caseSensitive ? $values[$i] : strtolower($values[$i]), $type);
153154
}
154-
155155
$queryBuilder
156156
->andWhere(sprintf($wrapCase('%s.%s').' IN (%s)', $alias, $field, implode(',', $inQuery)))
157-
->setParameters($args);
158-
157+
->setParameters(new ArrayCollection($args));
159158
}
160159

161160
// metadata doesn't have the field, nor an association on the field
@@ -207,13 +206,14 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
207206
*
208207
* @throws InvalidArgumentException If strategy does not exist
209208
*/
210-
protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $value, bool $caseSensitive, ClassMetadata $metadata = null)
209+
protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $value, bool $caseSensitive/*, ClassMetadata $metadata = null*/)
211210
{
212211
// check if we have metadata
213-
if ($metadata instanceof ClassMetadata) {
212+
if (\func_num_args() > 7) {
213+
$metadata = func_get_arg(7);
214214
$type = $metadata->getTypeOfField($field);
215215
} else {
216-
@trigger_error('addWhereByStrategy() will require argument ClassMetadata in 3.0.', E_USER_DEPRECATED);
216+
@trigger_error(sprintf('Method %s() will have a 8th argument `$metadata` in version API Platform 3.0.', __FUNCTION__), E_USER_DEPRECATED);
217217
$type = null; // default setParameter() value
218218
}
219219
$wrapCase = $this->createWrapCase($caseSensitive);

src/Test/DoctrineOrmFilterTestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ protected function setUp(): void
6262
$manager = DoctrineTestHelper::createTestEntityManager();
6363
$this->managerRegistry = self::$kernel->getContainer()->get('doctrine');
6464
$this->repository = $manager->getRepository(Dummy::class);
65+
66+
if (!\Doctrine\DBAL\Types\Type::hasType('uuid')) {
67+
\Doctrine\DBAL\Types\Type::addType('uuid', \Ramsey\Uuid\Doctrine\UuidType::class);
68+
}
6569
}
6670

6771
/**

tests/Bridge/Doctrine/Common/Filter/SearchFilterTestTrait.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function testGetDescription()
2727
'alias' => null,
2828
'dummy' => null,
2929
'dummyDate' => null,
30+
'dummyUuid' => null,
3031
'jsonData' => null,
3132
'arrayData' => null,
3233
'nameConverted' => null,
@@ -106,6 +107,20 @@ public function testGetDescription()
106107
'strategy' => 'exact',
107108
'is_collection' => true,
108109
],
110+
/*'dummyUuid' => [
111+
'property' => 'dummyUuid',
112+
'type' => 'uuid_binary',
113+
'required' => false,
114+
'strategy' => 'exact',
115+
'is_collection' => false,
116+
],
117+
'dummyUuid[]' => [
118+
'property' => 'dummyUuid',
119+
'type' => 'uuid_binary',
120+
'required' => false,
121+
'strategy' => 'exact',
122+
'is_collection' => true,
123+
],*/
109124
'jsonData' => [
110125
'property' => 'jsonData',
111126
'type' => 'string',
@@ -212,6 +227,18 @@ private function provideApplyTestArguments(): array
212227
],
213228
],
214229
],
230+
/*'exact (multiple UUID values)' => [
231+
[
232+
'id' => null,
233+
'dummyUuid' => 'exact',
234+
],
235+
[
236+
'dummyUuid' => [
237+
'ab69abc6-434a-4942-83b7-20d301e794e7',
238+
'aed95394-a50d-4aba-a233-df0ecc2218a0',
239+
],
240+
],
241+
],*/
215242
'exact (multiple values; case insensitive)' => [
216243
[
217244
'id' => null,

tests/Bridge/Doctrine/Orm/Filter/SearchFilterTest.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use ApiPlatform\Core\Tests\ProphecyTrait;
2727
use Doctrine\Persistence\ManagerRegistry;
2828
use Prophecy\Argument;
29+
//use Ramsey\Uuid\Uuid;
2930
use Symfony\Component\HttpFoundation\Request;
3031
use Symfony\Component\HttpFoundation\RequestStack;
3132

@@ -158,6 +159,20 @@ public function testGetDescriptionDefaultFields()
158159
'strategy' => 'exact',
159160
'is_collection' => true,
160161
],
162+
/*'dummyUuid' => [
163+
'property' => 'dummyUuid',
164+
'type' => 'uuid',
165+
'required' => false,
166+
'strategy' => 'exact',
167+
'is_collection' => false,
168+
],
169+
'dummyUuid[]' => [
170+
'property' => 'dummyUuid',
171+
'type' => 'uuid',
172+
'required' => false,
173+
'strategy' => 'exact',
174+
'is_collection' => true,
175+
],*/
161176
'jsonData' => [
162177
'property' => 'jsonData',
163178
'type' => 'string',
@@ -385,22 +400,26 @@ public function provideApplyTestData(): array
385400
$filterFactory,
386401
],
387402
'exact (multiple values)' => [
388-
sprintf('SELECT %s FROM %s %1$s WHERE %1$s.name IN (:name_p1)', $this->alias, Dummy::class),
403+
sprintf('SELECT %s FROM %s %1$s WHERE %1$s.name IN (:name_p1,:name_p2)', $this->alias, Dummy::class),
389404
[
390-
'name_p1' => [
391-
'CaSE',
392-
'SENSitive',
393-
],
405+
'name_p1' => 'CaSE',
406+
'name_p2' => 'SENSitive',
394407
],
395408
$filterFactory,
396409
],
410+
/*'exact (multiple UUID values)' => [
411+
sprintf('SELECT %s FROM %s %1$s WHERE %1$s.dummyUuid IN (:dummyUuid_p1,:dummyUuid_p2)', $this->alias, Dummy::class),
412+
[
413+
'dummyUuid_p1' => Uuid::fromString('ab69abc6-434a-4942-83b7-20d301e794e7'),
414+
'dummyUuid_p2' => Uuid::fromString('aed95394-a50d-4aba-a233-df0ecc2218a0'),
415+
],
416+
$filterFactory,
417+
],*/
397418
'exact (multiple values; case insensitive)' => [
398-
sprintf('SELECT %s FROM %s %1$s WHERE LOWER(%1$s.name) IN (:name_p1)', $this->alias, Dummy::class),
419+
sprintf('SELECT %s FROM %s %1$s WHERE LOWER(%1$s.name) IN (:name_p1,:name_p2)', $this->alias, Dummy::class),
399420
[
400-
'name_p1' => [
401-
'case',
402-
'insensitive',
403-
],
421+
'name_p1' => 'case',
422+
'name_p2' => 'insensitive',
404423
],
405424
$filterFactory,
406425
],

tests/Fixtures/TestBundle/Entity/Dummy.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Doctrine\Common\Collections\ArrayCollection;
2020
use Doctrine\ORM\Mapping as ORM;
2121
use Symfony\Component\Validator\Constraints as Assert;
22+
use Ramsey\Uuid\UuidInterface;
2223

2324
/**
2425
* Dummy.
@@ -116,6 +117,13 @@ class Dummy
116117
*/
117118
public $dummyPrice;
118119

120+
/**
121+
* @var UuidInterface A dummy uuid
122+
*
123+
* @ORM\Column(type="uuid", nullable=true)
124+
*/
125+
// private $dummyUuid;
126+
119127
/**
120128
* @var RelatedDummy A related dummy
121129
*
@@ -198,6 +206,16 @@ public function getName(): string
198206
return $this->name;
199207
}
200208

209+
public function setDummyUuid(UuidInterface $uuid)
210+
{
211+
$this->DummyUuid = $uuid;
212+
}
213+
214+
public function getDummyUuid()
215+
{
216+
return $this->DummyUuid;
217+
}
218+
201219
public function setAlias($alias)
202220
{
203221
$this->alias = $alias;

0 commit comments

Comments
 (0)