Skip to content

Commit

Permalink
fix: usage of deprecated DBAL type constants (#4399)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Aug 31, 2021
1 parent 0204b7a commit 86a2a4d
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 76 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -87,6 +87,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/Bridge/Doctrine/Orm/Filter/BooleanFilter.php
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 @@ -35,7 +35,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/Bridge/Doctrine/Orm/Filter/DateFilter.php
Expand Up @@ -18,6 +18,7 @@
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder;

/**
Expand All @@ -31,14 +32,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/Bridge/Doctrine/Orm/Filter/NumericFilter.php
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 @@ -39,11 +39,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 @@ -89,11 +89,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
38 changes: 16 additions & 22 deletions src/Bridge/Doctrine/Orm/Filter/SearchFilter.php
Expand Up @@ -20,7 +20,7 @@
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryBuilderHelper;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;
use Psr\Log\LoggerInterface;
Expand All @@ -38,7 +38,7 @@ class SearchFilter extends AbstractContextAwareFilter implements SearchFilterInt
{
use SearchFilterTrait;

public const DOCTRINE_INTEGER_TYPE = DBALType::INTEGER;
public const DOCTRINE_INTEGER_TYPE = Types::INTEGER;

public function __construct(ManagerRegistry $managerRegistry, ?RequestStack $requestStack, IriConverterInterface $iriConverter, PropertyAccessorInterface $propertyAccessor = null, LoggerInterface $logger = null, array $properties = null, IdentifiersExtractorInterface $identifiersExtractor = null, NameConverterInterface $nameConverter = null)
{
Expand Down Expand Up @@ -246,33 +246,27 @@ protected function createWrapCase(bool $caseSensitive): \Closure
protected function getType(string $doctrineType): string
{
switch ($doctrineType) {
case DBALType::TARRAY:
case Types::ARRAY:
return 'array';
case DBALType::BIGINT:
case DBALType::INTEGER:
case DBALType::SMALLINT:
case Types::BIGINT:
case Types::INTEGER:
case Types::SMALLINT:
return 'int';
case DBALType::BOOLEAN:
case Types::BOOLEAN:
return 'bool';
case DBALType::DATE:
case DBALType::TIME:
case DBALType::DATETIME:
case DBALType::DATETIMETZ:
case Types::DATE_MUTABLE:
case Types::TIME_MUTABLE:
case Types::DATETIME_MUTABLE:
case Types::DATETIMETZ_MUTABLE:
case Types::DATE_IMMUTABLE:
case Types::TIME_IMMUTABLE:
case Types::DATETIME_IMMUTABLE:
case Types::DATETIMETZ_IMMUTABLE:
return \DateTimeInterface::class;
case DBALType::FLOAT:
case Types::FLOAT:
return 'float';
}

if (\defined(DBALType::class.'::DATE_IMMUTABLE')) {
switch ($doctrineType) {
case DBALType::DATE_IMMUTABLE:
case DBALType::TIME_IMMUTABLE:
case DBALType::DATETIME_IMMUTABLE:
case DBALType::DATETIMETZ_IMMUTABLE:
return \DateTimeInterface::class;
}
}

return 'string';
}
}
11 changes: 6 additions & 5 deletions tests/Bridge/Doctrine/Common/Util/IdentifierManagerTraitTest.php
Expand Up @@ -26,6 +26,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 @@ -64,7 +65,7 @@ public function testSingleIdentifier()
]);
$objectManager = $this->getEntityManager(Dummy::class, [
'id' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
]);

Expand Down Expand Up @@ -104,10 +105,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 @@ -130,10 +131,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/Bridge/Doctrine/Orm/ItemDataProviderTest.php
Expand Up @@ -28,7 +28,7 @@
use ApiPlatform\Core\Tests\ProphecyTrait;
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 @@ -65,7 +65,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 @@ -74,7 +74,7 @@ public function testGetItemSingleIdentifier()
]);
$managerRegistry = $this->getManagerRegistry(Dummy::class, [
'id' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
], $queryBuilder);

Expand Down Expand Up @@ -104,8 +104,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 @@ -115,10 +115,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 @@ -144,10 +144,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 @@ -167,7 +167,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 @@ -176,7 +176,7 @@ public function testQueryResultExtension()
]);
$managerRegistry = $this->getManagerRegistry(Dummy::class, [
'id' => [
'type' => DBALType::INTEGER,
'type' => Types::INTEGER,
],
], $queryBuilder);

Expand Down Expand Up @@ -216,7 +216,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

0 comments on commit 86a2a4d

Please sign in to comment.