Skip to content

Commit

Permalink
ORM3 and DBAL4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
michnovka committed Jan 5, 2024
1 parent 572f0d8 commit 6e59134
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 76 deletions.
30 changes: 7 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,22 @@ jobs:
#

# Most recent versions
- name: 'Test Symfony 5.4 [Linux, PHP 8.1]'
- name: 'Test Symfony 6.4 [Linux, PHP 8.1]'
os: 'ubuntu-latest'
php: '8.1'
symfony: '5.4.*@dev'
symfony: '6.4.*@dev'
allow-unstable: true
mongodb: true
mysql: true

- name: 'Test Symfony 5.4 [Windows, PHP 8.1]'
- name: 'Test Symfony 6.4 [Windows, PHP 8.1]'
os: 'windows-latest'
php: '8.1'
symfony: '5.4.*@dev'
mongodb: true
mysql: true
allow-unstable: true

- name: 'Test Symfony 6.3 [Linux, PHP 8.1]'
os: 'ubuntu-latest'
php: '8.1'
symfony: '6.3.*@dev'
symfony: '6.4.*@dev'
mongodb: true
mysql: true
allow-unstable: true

- name: 'Test Symfony 6.4 [Linux, PHP 8.1]'
os: 'ubuntu-latest'
php: '8.1'
symfony: '6.4.*@dev'
allow-unstable: true
mysql: true
mongodb: true

- name: 'Test Symfony 7.0 [Linux, PHP 8.2]'
os: 'ubuntu-latest'
php: '8.2'
Expand Down Expand Up @@ -188,9 +172,9 @@ jobs:
- name: 'Cache dependencies'
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-${{ hashFiles('**/composer.json') }}-flags-${{ matrix.composer-flags }}
restore-keys: ${{ runner.os }}-composer-
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-${{ hashFiles('**/composer.json') }}-flags-${{ matrix.composer-flags }}
restore-keys: ${{ runner.os }}-composer-
if: ${{ matrix.os != 'windows-latest' }}

- name: 'Allow unstable packages'
Expand Down
33 changes: 17 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,27 @@
"require-dev": {
"ext-pdo_sqlite": "*",
"composer/semver": "^3.2",
"doctrine/dbal": "^3.2",
"doctrine/doctrine-bundle": "^2.5",
"doctrine/orm": "^2.10",
"doctrine/dbal": "^4.0",
"doctrine/doctrine-bundle": "^2.11",
"doctrine/orm": "^3.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-symfony": "^1.2",
"symfony/browser-kit": "^5.4|^6.3|^7.0",
"symfony/config": "^5.4|^6.3|^7.0",
"symfony/dependency-injection": "^5.4.2|^6.3|^7.0",
"symfony/filesystem": "^5.4|^6.3|^7.0",
"symfony/form": "^5.4|^6.3|^7.0",
"symfony/framework-bundle": "^5.4|^6.3|^7.0",
"symfony/http-kernel": "^5.4.2|^6.3|^7.0",
"symfony/phpunit-bridge": "^5.4|^6.3|^7.0",
"symfony/translation": "^5.4|^6.3|^7.0",
"symfony/var-dumper": "^5.4|^6.3|^7.0",
"symfony/yaml": "^5.4|^6.3|^7.0"
"phpstan/phpstan-symfony": "^1.3",
"symfony/browser-kit": "^6.4|^7.0",
"symfony/config": "^6.4|^7.0",
"symfony/dependency-injection": "^6.4|^7.0",
"symfony/doctrine-bridge": "^6.4|^7.0",
"symfony/filesystem": "^6.4|^7.0",
"symfony/form": "^6.4|^7.0",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/http-kernel": "^6.4|^7.0",
"symfony/phpunit-bridge": "^6.4|^7.0",
"symfony/translation": "^6.4|^7.0",
"symfony/var-dumper": "^6.4|^7.0",
"symfony/yaml": "^6.4|^7.0"
},
"extra": {
"branch-alias": {
"dev-2.x": "2.x-dev"
"dev-3.x": "3.x-dev"
}
},
"config": {
Expand Down
13 changes: 3 additions & 10 deletions src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace Elao\Enum\Bridge\Doctrine\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Elao\Enum\Exception\LogicException;
Expand All @@ -25,16 +24,10 @@ abstract class AbstractEnumSQLDeclarationType extends AbstractEnumType
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if (class_exists(AbstractMySQLPlatform::class)) {
if (!$platform instanceof AbstractMySQLPlatform) {
throw new LogicException('SQL ENUM type is not supported on the current platform');
}
} elseif (class_exists(MySQLPlatform::class)) {
if (!$platform instanceof MySQLPlatform) {
throw new LogicException('SQL ENUM type is not supported on the current platform');
}
if (!$platform instanceof MySQLPlatform) {
throw new LogicException('SQL ENUM type is not supported on the current platform');
}

$values = array_map(
Expand Down
14 changes: 2 additions & 12 deletions src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,13 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st
$column['length'] = 255;
}

return method_exists($platform, 'getStringTypeDeclarationSQL') ?
$platform->getStringTypeDeclarationSQL($column) :
$platform->getVarcharTypeDeclarationSQL($column);
return $platform->getStringTypeDeclarationSQL($column);
}

/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function getBindingType(): int
public function getBindingType(): ParameterType
{
return $this->isIntBackedEnum() ? ParameterType::INTEGER : ParameterType::STRING;
}
Expand Down
13 changes: 5 additions & 8 deletions src/Bridge/Doctrine/DBAL/Types/AbstractFlagBagType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
namespace Elao\Enum\Bridge\Doctrine\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Types\Type;
use Elao\Enum\Exception\InvalidArgumentException;
use Elao\Enum\FlagBag;

abstract class AbstractFlagBagType extends IntegerType
abstract class AbstractFlagBagType extends Type
{
/**
* The enum FQCN for which we should make the DBAL conversion.
Expand Down Expand Up @@ -73,7 +73,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int
*
* @return FlagBag<\BackedEnum>|null
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
public function convertToPHPValue($value, AbstractPlatform $platform): ?FlagBag
{
$value = parent::convertToPHPValue($value, $platform);

Expand All @@ -84,12 +84,9 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
return new FlagBag($this->getEnumClass(), $value);
}

/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return true;
return $platform->getIntegerTypeDeclarationSQL($column);
}

public function getName(): string
Expand Down
7 changes: 0 additions & 7 deletions tests/Unit/Bridge/Doctrine/DBAL/Types/EnumTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ public function testConvertToPHPValueOnNull(): void
self::assertSame(Suit::Spades, $PHPValue);
}

public function testRequiresSQLCommentHintIsTrue(): void
{
self::assertTrue($this->stringType->requiresSQLCommentHint($this->platform));
self::assertTrue($this->intType->requiresSQLCommentHint($this->platform));
self::assertTrue($this->withDefaultType->requiresSQLCommentHint($this->platform));
}

public function testIntegerBindingType(): void
{
self::assertSame(ParameterType::STRING, $this->stringType->getBindingType());
Expand Down

0 comments on commit 6e59134

Please sign in to comment.