Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: DBAL4 and ORM3 support #228

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 31 additions & 55 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
vendor/bin/simple-phpunit install
echo "::endgroup::"
env:
SYMFONY_REQUIRE: "6.2*dev"
SYMFONY_REQUIRE: "6.4*dev"

- name: 'Lint - PHP CS Fixer'
if: always() && steps.deps.outcome == 'success'
Expand Down Expand Up @@ -78,76 +78,54 @@ 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'
symfony: '6.4.*@dev'
mongodb: true
mongodbnew: true
mysql: true
allow-unstable: true

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

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

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

# Bleeding edge (unreleased dev versions where failures are allowed)
- name: 'Test next Symfony [Linux, PHP 8.1] (allowed failure)'
os: 'ubuntu-latest'
php: '8.1'
symfony: '6.3.*@dev'
composer-flags: '--ignore-platform-req php'
allow-unstable: true
allow-failure: true
mysql: true
mongodb: true

- name: 'Test next Symfony [Linux, PHP 8.2] (allowed failure)'
- name: 'Test next Symfony 7.1 [Linux, PHP 8.2] (allowed failure)'
os: 'ubuntu-latest'
php: '8.2'
symfony: '6.3.*@dev'
symfony: '7.1.*@dev'
composer-flags: '--ignore-platform-req php'
allow-unstable: true
allow-failure: true
mysql: true
mongodb: true
mongodbnew: true

- name: 'Test next Symfony [Linux, PHP 8.3] (allowed failure)'
- name: 'Test next Symfony 7.1 [Linux, PHP 8.3] (allowed failure)'
os: 'ubuntu-latest'
php: '8.3'
symfony: '6.3.*@dev'
symfony: '7.1.*@dev'
composer-flags: '--ignore-platform-req php'
allow-unstable: true
allow-failure: true
mysql: true
mongodb: true
mongodbnew: true

steps:
- name: 'Set git to use LF'
Expand All @@ -167,19 +145,13 @@ jobs:
tools: 'composer:v2,flex'

- name: 'Start MongoDB (Linux)'
uses: supercharge/mongodb-github-action@1.8.0
uses: supercharge/mongodb-github-action@1.10.0
if: ${{ matrix.mongodb && matrix.os == 'ubuntu-latest' }}

- name: 'Remove MongoDB (Windows)'
uses: crazy-max/ghaction-chocolatey@v2
with:
args: uninstall mongodb mongodb.install -y --all-versions
if: ${{ matrix.mongodb && matrix.os == 'windows-latest' }}

- name: 'Start MongoDB (Windows)'
uses: crazy-max/ghaction-chocolatey@v2
uses: crazy-max/ghaction-chocolatey@v3
with:
args: install mongodb.install --version=5.0.14 --allow-downgrade
args: install mongodb.install --version=7.0.4 --allow-downgrade
if: ${{ matrix.mongodb && matrix.os == 'windows-latest' }}

- name: 'Shutdown Default Ubuntu MySQL'
Expand All @@ -189,7 +161,7 @@ jobs:
- name: 'Setup MySQL'
uses: ankane/setup-mysql@v1
with:
mysql-version: '8.0'
mysql-version: '8.0.35'
database: doctrine_tests
if: ${{ matrix.mysql }}

Expand All @@ -201,18 +173,22 @@ 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'
run: composer config minimum-stability dev
if: ${{ matrix.allow-unstable }}

- name: 'Require Doctrine MongoDB dependencies'
- name: 'Require Doctrine MongoDB dependencies for old symfony'
run: composer require --no-update ${{ matrix.composer-flags }} --dev --no-interaction --ansi "doctrine/mongodb-odm:^2.4" "doctrine/mongodb-odm-bundle:^4.5.1"
if: ${{ matrix.mongodb }}
if: ${{ matrix.mongodb && !matrix.mongodbnew }}

- name: 'Require Doctrine MongoDB dependencies for new symfony'
run: composer require --no-update ${{ matrix.composer-flags }} --dev --no-interaction --ansi "doctrine/mongodb-odm:^2.6" "doctrine/mongodb-odm-bundle:5.0.x-dev"
if: ${{ matrix.mongodb && matrix.mongodbnew }}

- name: 'Install dependencies'
run: |
Expand All @@ -227,11 +203,11 @@ jobs:
SYMFONY_REQUIRE: "${{ matrix.symfony }}"

- name: 'Set Doctrine MySQL DSN (Linux)'
run: echo "DOCTRINE_DBAL_URL=pdo-mysql://root@127.0.0.1:3306/doctrine_tests?serverVersion=8.0" >> $GITHUB_ENV
run: echo "DOCTRINE_DBAL_URL=pdo-mysql://root@127.0.0.1:3306/doctrine_tests?serverVersion=8.0.35" >> $GITHUB_ENV
if: ${{ matrix.mysql && matrix.os == 'ubuntu-latest' }}

- name: 'Set Doctrine MySQL DSN (Windows)'
run: echo "DOCTRINE_DBAL_URL=pdo-mysql://root@127.0.0.1:3306/doctrine_tests?serverVersion=8.0" >> $env:GITHUB_ENV
run: echo "DOCTRINE_DBAL_URL=pdo-mysql://root@127.0.0.1:3306/doctrine_tests?serverVersion=8.0.35" >> $env:GITHUB_ENV
if: ${{ matrix.mysql && matrix.os == 'windows-latest' }}

- name: 'Run PHPUnit tests'
Expand Down
31 changes: 19 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,31 @@ install.54:
symfony composer config minimum-stability dev
symfony composer update --ignore-platform-req=ext-mongodb

## Install - Install Symfony 6.0 deps
install.60: setup
install.60: export SYMFONY_REQUIRE = 6.0.*@dev
install.60:
## Install - Install Symfony 6.3 deps
install.63: setup
install.63: export SYMFONY_REQUIRE = 6.3.*@dev
install.63:
symfony composer config minimum-stability dev
symfony composer update --ignore-platform-req=ext-mongodb

## Install - Install Symfony 6.1 deps
install.61: setup
install.61: export SYMFONY_REQUIRE = 6.1.*@dev
install.61:
## Install - Install Symfony 6.4 deps
install.64: setup
install.64: export SYMFONY_REQUIRE = 6.4.*@dev
install.64:
symfony composer config minimum-stability dev
symfony composer update --ignore-platform-req=ext-mongodb

## Install - Install Symfony 6.2 deps
install.62: setup
install.62: export SYMFONY_REQUIRE = 6.2.*@dev
install.62:
## Install - Install Symfony 7.0 deps
install.70: setup
install.70: export SYMFONY_REQUIRE = 7.0.*@dev
install.70:
symfony composer config minimum-stability dev
symfony composer update --ignore-platform-req=ext-mongodb

## Install - Install Symfony 7.1 deps
install.71: setup
install.71: export SYMFONY_REQUIRE = 7.1.*@dev
install.71:
symfony composer config minimum-stability dev
symfony composer update --ignore-platform-req=ext-mongodb

Expand Down
36 changes: 19 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,34 @@
"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.0",
"symfony/config": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4.2|^6.0.1",
"symfony/filesystem": "^5.4|^6.0",
"symfony/form": "^5.4|^6.0",
"symfony/framework-bundle": "^5.4|^6.0",
"symfony/http-kernel": "^5.4.2|^6.0.1",
"symfony/phpunit-bridge": "^5.4|^6.0",
"symfony/translation": "^5.4|^6.0",
"symfony/var-dumper": "^5.4|^6.0",
"symfony/yaml": "^5.4|^6.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": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
}
},
"minimum-stability": "dev"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

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 @@ -24,9 +24,9 @@ abstract class AbstractEnumSQLDeclarationType extends AbstractEnumType
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if (!$platform instanceof AbstractMySQLPlatform) {
if (!$platform instanceof MySQLPlatform) {
throw new LogicException('SQL ENUM type is not supported on the current platform');
}

Expand Down
25 changes: 9 additions & 16 deletions src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,21 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?\BackedE
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return $this->isIntBackedEnum()
? $platform->getIntegerTypeDeclarationSQL($column)
: (
method_exists($platform, 'getStringTypeDeclarationSQL') ?
$platform->getStringTypeDeclarationSQL($column) :
$platform->getVarcharTypeDeclarationSQL($column)
)
;
}
if ($this->isIntBackedEnum()) {
return $platform->getIntegerTypeDeclarationSQL($column);
}

/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
if (empty($column['length'])) {
$column['length'] = 255;
}

return $platform->getStringTypeDeclarationSQL($column);
}

/**
* {@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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
framework:
router:
resource: '%kernel.project_dir%/config/routing-annotation.yaml'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
framework:
annotations:
enabled: false
router:
resource: '%kernel.project_dir%/config/routing.yaml'
Loading