Skip to content

Commit

Permalink
fix: usage of deprecated DBAL type constants (api-platform#4399)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored and vincentchalamon committed Oct 15, 2021
1 parent c4d72b2 commit 0a8bf0d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 54 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
},
"conflict": {
"doctrine/common": "<2.7",
"doctrine/dbal": "<2.10",
"doctrine/mongodb-odm": "<2.2",
"doctrine/persistence": "<1.3"
},
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Bridge/Doctrine/Orm/Filter/BooleanFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use ApiPlatform\Core\Bridge\Doctrine\Common\Filter\BooleanFilterTrait;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder;

/**
Expand All @@ -37,7 +37,7 @@ class BooleanFilter extends AbstractContextAwareFilter
use BooleanFilterTrait;

public const DOCTRINE_BOOLEAN_TYPES = [
DBALType::BOOLEAN => true,
Types::BOOLEAN => true,
];

/**
Expand Down
17 changes: 9 additions & 8 deletions src/Core/Bridge/Doctrine/Orm/Filter/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Exception\InvalidArgumentException;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder;

/**
Expand All @@ -33,14 +34,14 @@ class DateFilter extends AbstractContextAwareFilter implements DateFilterInterfa
use DateFilterTrait;

public const DOCTRINE_DATE_TYPES = [
DBALType::DATE => true,
DBALType::DATETIME => true,
DBALType::DATETIMETZ => true,
DBALType::TIME => true,
DBALType::DATE_IMMUTABLE => true,
DBALType::DATETIME_IMMUTABLE => true,
DBALType::DATETIMETZ_IMMUTABLE => true,
DBALType::TIME_IMMUTABLE => true,
Types::DATE_MUTABLE => true,
Types::DATETIME_MUTABLE => true,
Types::DATETIMETZ_MUTABLE => true,
Types::TIME_MUTABLE => true,
Types::DATE_IMMUTABLE => true,
Types::DATETIME_IMMUTABLE => true,
Types::DATETIMETZ_IMMUTABLE => true,
Types::TIME_IMMUTABLE => true,
];

/**
Expand Down
16 changes: 8 additions & 8 deletions src/Core/Bridge/Doctrine/Orm/Filter/NumericFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use ApiPlatform\Core\Bridge\Doctrine\Common\Filter\NumericFilterTrait;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder;

/**
Expand All @@ -41,11 +41,11 @@ class NumericFilter extends AbstractContextAwareFilter
* @see http://doctrine-orm.readthedocs.org/projects/doctrine-dbal/en/latest/reference/types.html
*/
public const DOCTRINE_NUMERIC_TYPES = [
DBALType::BIGINT => true,
DBALType::DECIMAL => true,
DBALType::FLOAT => true,
DBALType::INTEGER => true,
DBALType::SMALLINT => true,
Types::BIGINT => true,
Types::DECIMAL => true,
Types::FLOAT => true,
Types::INTEGER => true,
Types::SMALLINT => true,
];

/**
Expand Down Expand Up @@ -91,11 +91,11 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
*/
protected function getType(string $doctrineType = null): string
{
if (null === $doctrineType || DBALType::DECIMAL === $doctrineType) {
if (null === $doctrineType || Types::DECIMAL === $doctrineType) {
return 'string';
}

if (DBALType::FLOAT === $doctrineType) {
if (Types::FLOAT === $doctrineType) {
return 'float';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata as MongoDbOdmClassMetadata;
use Doctrine\ODM\MongoDB\Types\Type as MongoDbType;
Expand Down Expand Up @@ -70,7 +71,7 @@ public function testSingleIdentifier()
]);
$objectManager = $this->getEntityManager(Dummy::class, [
'id' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
]);

Expand Down Expand Up @@ -110,10 +111,10 @@ public function testCompositeIdentifier()
]);
$objectManager = $this->getEntityManager(Dummy::class, [
'ida' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
'idb' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
]);

Expand All @@ -136,10 +137,10 @@ public function testInvalidIdentifier()
]);
$objectManager = $this->getEntityManager(Dummy::class, [
'ida' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
'idb' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
]);

Expand Down
24 changes: 12 additions & 12 deletions tests/Core/Bridge/Doctrine/Orm/ItemDataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
Expand Down Expand Up @@ -68,7 +68,7 @@ public function testGetItemSingleIdentifier()
$queryBuilderProphecy->expr()->willReturn($exprProphecy->reveal())->shouldBeCalled();
$queryBuilderProphecy->andWhere($comparison)->shouldBeCalled();
$queryBuilderProphecy->getRootAliases()->shouldBeCalled()->willReturn(['o']);
$queryBuilderProphecy->setParameter(':id_id', 1, DBALType::INTEGER)->shouldBeCalled();
$queryBuilderProphecy->setParameter(':id_id', 1, Types::INTEGER)->shouldBeCalled();

$queryBuilder = $queryBuilderProphecy->reveal();

Expand All @@ -77,7 +77,7 @@ public function testGetItemSingleIdentifier()
]);
$managerRegistry = $this->getManagerRegistry(Dummy::class, [
'id' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
], $queryBuilder);

Expand Down Expand Up @@ -107,8 +107,8 @@ public function testGetItemDoubleIdentifier()
$queryBuilderProphecy->andWhere($comparison)->shouldBeCalled();
$queryBuilderProphecy->getRootAliases()->shouldBeCalled()->willReturn(['o']);

$queryBuilderProphecy->setParameter(':id_ida', 1, DBALType::INTEGER)->shouldBeCalled();
$queryBuilderProphecy->setParameter(':id_idb', 2, DBALType::INTEGER)->shouldBeCalled();
$queryBuilderProphecy->setParameter(':id_ida', 1, Types::INTEGER)->shouldBeCalled();
$queryBuilderProphecy->setParameter(':id_idb', 2, Types::INTEGER)->shouldBeCalled();

$queryBuilder = $queryBuilderProphecy->reveal();

Expand All @@ -118,10 +118,10 @@ public function testGetItemDoubleIdentifier()
]);
$managerRegistry = $this->getManagerRegistry(Dummy::class, [
'ida' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
'idb' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
], $queryBuilder);

Expand All @@ -147,10 +147,10 @@ public function testGetItemWrongCompositeIdentifier()
]);
$managerRegistry = $this->getManagerRegistry(Dummy::class, [
'ida' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
'idb' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
], $this->prophesize(QueryBuilder::class)->reveal());

Expand All @@ -170,7 +170,7 @@ public function testQueryResultExtension()
$queryBuilderProphecy->expr()->willReturn($exprProphecy->reveal())->shouldBeCalled();
$queryBuilderProphecy->andWhere($comparison)->shouldBeCalled();
$queryBuilderProphecy->getRootAliases()->shouldBeCalled()->willReturn(['o']);
$queryBuilderProphecy->setParameter(':id_id', 1, DBALType::INTEGER)->shouldBeCalled();
$queryBuilderProphecy->setParameter(':id_id', 1, Types::INTEGER)->shouldBeCalled();

$queryBuilder = $queryBuilderProphecy->reveal();

Expand All @@ -179,7 +179,7 @@ public function testQueryResultExtension()
]);
$managerRegistry = $this->getManagerRegistry(Dummy::class, [
'id' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
], $queryBuilder);

Expand Down Expand Up @@ -219,7 +219,7 @@ public function testCannotCreateQueryBuilder()
$classMetadataProphecy->getIdentifier()->willReturn([
'id',
]);
$classMetadataProphecy->getTypeOfField('id')->willReturn(DBALType::INTEGER);
$classMetadataProphecy->getTypeOfField('id')->willReturn(Types::INTEGER);

$platformProphecy = $this->prophesize(AbstractPlatform::class);

Expand Down
38 changes: 19 additions & 19 deletions tests/Core/Bridge/Doctrine/Orm/SubresourceDataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\ThirdLevel;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
Expand Down Expand Up @@ -135,7 +135,7 @@ public function testGetSubresource()

$identifiers = ['id'];
$queryBuilder = $this->prophesize(QueryBuilder::class);
$queryBuilder->setParameter('id_p1', 1, DBALType::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->setParameter('id_p1', 1, Types::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$funcProphecy = $this->prophesize(Func::class);
$func = $funcProphecy->reveal();

Expand All @@ -153,7 +153,7 @@ public function testGetSubresource()
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
$classMetadataProphecy->hasAssociation('relatedDummies')->willReturn(true)->shouldBeCalled();
$classMetadataProphecy->getAssociationMapping('relatedDummies')->shouldBeCalled()->willReturn(['type' => ClassMetadata::MANY_TO_MANY]);
$classMetadataProphecy->getTypeOfField('id')->willReturn(DBALType::INTEGER)->shouldBeCalled();
$classMetadataProphecy->getTypeOfField('id')->willReturn(Types::INTEGER)->shouldBeCalled();

$managerProphecy->getClassMetadata(Dummy::class)->shouldBeCalled()->willReturn($classMetadataProphecy->reveal());

Expand Down Expand Up @@ -212,7 +212,7 @@ public function testGetSubSubresourceItem()
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
$classMetadataProphecy->hasAssociation('relatedDummies')->willReturn(true)->shouldBeCalled();
$classMetadataProphecy->getAssociationMapping('relatedDummies')->shouldBeCalled()->willReturn(['type' => ClassMetadata::MANY_TO_MANY]);
$classMetadataProphecy->getTypeOfField('id')->willReturn(DBALType::INTEGER)->shouldBeCalled();
$classMetadataProphecy->getTypeOfField('id')->willReturn(Types::INTEGER)->shouldBeCalled();

$dummyManagerProphecy = $this->prophesize(EntityManager::class);
$dummyManagerProphecy->createQueryBuilder()->shouldBeCalled()->willReturn($qb->reveal());
Expand All @@ -239,7 +239,7 @@ public function testGetSubSubresourceItem()
$rClassMetadataProphecy = $this->prophesize(ClassMetadata::class);
$rClassMetadataProphecy->hasAssociation('thirdLevel')->shouldBeCalled()->willReturn(true);
$rClassMetadataProphecy->getAssociationMapping('thirdLevel')->shouldBeCalled()->willReturn(['type' => ClassMetadata::MANY_TO_ONE]);
$rClassMetadataProphecy->getTypeOfField('id')->willReturn(DBALType::INTEGER)->shouldBeCalled();
$rClassMetadataProphecy->getTypeOfField('id')->willReturn(Types::INTEGER)->shouldBeCalled();

$rDummyManagerProphecy = $this->prophesize(EntityManager::class);
$rDummyManagerProphecy->createQueryBuilder()->shouldBeCalled()->willReturn($rqb->reveal());
Expand All @@ -258,8 +258,8 @@ public function testGetSubSubresourceItem()
$queryBuilder->andWhere($func)->shouldBeCalled()->willReturn($queryBuilder);

$queryBuilder->getQuery()->shouldBeCalled()->willReturn($queryProphecy->reveal());
$queryBuilder->setParameter('id_p1', 1, DBALType::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->setParameter('id_p2', 1, DBALType::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->setParameter('id_p1', 1, Types::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->setParameter('id_p2', 1, Types::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);

$repositoryProphecy = $this->prophesize(EntityRepository::class);
$repositoryProphecy->createQueryBuilder('o')->shouldBeCalled()->willReturn($queryBuilder->reveal());
Expand Down Expand Up @@ -288,7 +288,7 @@ public function testGetSubresourceOneToOneOwningRelation()

$identifiers = ['id'];
$queryBuilder = $this->prophesize(QueryBuilder::class);
$queryBuilder->setParameter('id_p1', 1, DBALType::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->setParameter('id_p1', 1, Types::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$funcProphecy = $this->prophesize(Func::class);
$func = $funcProphecy->reveal();
$queryBuilder->andWhere($func)->shouldBeCalled()->willReturn($queryBuilder);
Expand All @@ -304,7 +304,7 @@ public function testGetSubresourceOneToOneOwningRelation()
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
$classMetadataProphecy->hasAssociation('ownedDummy')->willReturn(true)->shouldBeCalled();
$classMetadataProphecy->getAssociationMapping('ownedDummy')->shouldBeCalled()->willReturn(['type' => ClassMetadata::ONE_TO_ONE]);
$classMetadataProphecy->getTypeOfField('id')->willReturn(DBALType::INTEGER)->shouldBeCalled();
$classMetadataProphecy->getTypeOfField('id')->willReturn(Types::INTEGER)->shouldBeCalled();

$managerProphecy->getClassMetadata(Dummy::class)->shouldBeCalled()->willReturn($classMetadataProphecy->reveal());

Expand Down Expand Up @@ -340,7 +340,7 @@ public function testQueryResultExtension()

$identifiers = ['id'];
$queryBuilder = $this->prophesize(QueryBuilder::class);
$queryBuilder->setParameter('id_p1', 1, DBALType::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->setParameter('id_p1', 1, Types::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$funcProphecy = $this->prophesize(Func::class);
$func = $funcProphecy->reveal();

Expand All @@ -356,7 +356,7 @@ public function testQueryResultExtension()
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
$classMetadataProphecy->hasAssociation('relatedDummies')->willReturn(true)->shouldBeCalled();
$classMetadataProphecy->getAssociationMapping('relatedDummies')->shouldBeCalled()->willReturn(['type' => ClassMetadata::MANY_TO_MANY]);
$classMetadataProphecy->getTypeOfField('id')->willReturn(DBALType::INTEGER)->shouldBeCalled();
$classMetadataProphecy->getTypeOfField('id')->willReturn(Types::INTEGER)->shouldBeCalled();

$managerProphecy->getClassMetadata(Dummy::class)->shouldBeCalled()->willReturn($classMetadataProphecy->reveal());
$this->assertIdentifierManagerMethodCalls($managerProphecy);
Expand Down Expand Up @@ -461,7 +461,7 @@ public function testGetSubSubresourceItemLegacy()
$classMetadataProphecy->getIdentifier()->shouldBeCalled()->willReturn($identifiers);
$classMetadataProphecy->hasAssociation('relatedDummies')->willReturn(true)->shouldBeCalled();
$classMetadataProphecy->getAssociationMapping('relatedDummies')->shouldBeCalled()->willReturn(['type' => ClassMetadata::MANY_TO_MANY]);
$classMetadataProphecy->getTypeOfField('id')->shouldBeCalled()->willReturn(DBALType::INTEGER);
$classMetadataProphecy->getTypeOfField('id')->shouldBeCalled()->willReturn(Types::INTEGER);

$dummyManagerProphecy = $this->prophesize(EntityManager::class);
$dummyManagerProphecy->createQueryBuilder()->shouldBeCalled()->willReturn($qb->reveal());
Expand All @@ -487,7 +487,7 @@ public function testGetSubSubresourceItemLegacy()

$rClassMetadataProphecy = $this->prophesize(ClassMetadata::class);
$rClassMetadataProphecy->getIdentifier()->shouldBeCalled()->willReturn($identifiers);
$rClassMetadataProphecy->getTypeOfField('id')->shouldBeCalled()->willReturn(DBALType::INTEGER);
$rClassMetadataProphecy->getTypeOfField('id')->shouldBeCalled()->willReturn(Types::INTEGER);
$rClassMetadataProphecy->hasAssociation('thirdLevel')->shouldBeCalled()->willReturn(true);
$rClassMetadataProphecy->getAssociationMapping('thirdLevel')->shouldBeCalled()->willReturn(['type' => ClassMetadata::MANY_TO_ONE]);

Expand All @@ -508,8 +508,8 @@ public function testGetSubSubresourceItemLegacy()
$queryBuilder->andWhere($func)->shouldBeCalled()->willReturn($queryBuilder);

$queryBuilder->getQuery()->shouldBeCalled()->willReturn($queryProphecy->reveal());
$queryBuilder->setParameter('id_p1', 1, DBALType::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->setParameter('id_p2', 1, DBALType::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->setParameter('id_p1', 1, Types::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->setParameter('id_p2', 1, Types::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);

$repositoryProphecy = $this->prophesize(EntityRepository::class);
$repositoryProphecy->createQueryBuilder('o')->shouldBeCalled()->willReturn($queryBuilder->reveal());
Expand Down Expand Up @@ -556,7 +556,7 @@ public function testGetSubresourceCollectionItem()
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
$classMetadataProphecy->hasAssociation('relatedDummies')->willReturn(true)->shouldBeCalled();
$classMetadataProphecy->getAssociationMapping('relatedDummies')->shouldBeCalled()->willReturn(['type' => ClassMetadata::MANY_TO_MANY]);
$classMetadataProphecy->getTypeOfField('id')->shouldBeCalled()->willReturn(DBALType::INTEGER);
$classMetadataProphecy->getTypeOfField('id')->shouldBeCalled()->willReturn(Types::INTEGER);

$dummyManagerProphecy = $this->prophesize(EntityManager::class);
$dummyManagerProphecy->createQueryBuilder()->shouldBeCalled()->willReturn($qb->reveal());
Expand All @@ -583,7 +583,7 @@ public function testGetSubresourceCollectionItem()
$rClassMetadataProphecy = $this->prophesize(ClassMetadata::class);
$rClassMetadataProphecy->hasAssociation('id')->shouldBeCalled()->willReturn(false);
$rClassMetadataProphecy->isIdentifier('id')->shouldBeCalled()->willReturn(true);
$rClassMetadataProphecy->getTypeOfField('id')->shouldBeCalled()->willReturn(DBALType::INTEGER);
$rClassMetadataProphecy->getTypeOfField('id')->shouldBeCalled()->willReturn(Types::INTEGER);

$rDummyManagerProphecy = $this->prophesize(EntityManager::class);
$rDummyManagerProphecy->createQueryBuilder()->shouldBeCalled()->willReturn($rqb->reveal());
Expand All @@ -601,8 +601,8 @@ public function testGetSubresourceCollectionItem()
$queryBuilder->andWhere($func)->shouldBeCalled()->willReturn($queryBuilder);

$queryBuilder->getQuery()->shouldBeCalled()->willReturn($queryProphecy->reveal());
$queryBuilder->setParameter('id_p1', 2, DBALType::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->setParameter('id_p2', 1, DBALType::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->setParameter('id_p1', 2, Types::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->setParameter('id_p2', 1, Types::INTEGER)->shouldBeCalled()->willReturn($queryBuilder);

$repositoryProphecy = $this->prophesize(EntityRepository::class);
$repositoryProphecy->createQueryBuilder('o')->shouldBeCalled()->willReturn($queryBuilder->reveal());
Expand Down

0 comments on commit 0a8bf0d

Please sign in to comment.