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

DBAL4 changes #232

Merged
merged 2 commits into from
Jun 7, 2024
Merged
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
64 changes: 37 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
coverage: none

- name: 'Require Doctrine MongoDB dependencies'
run: composer require --no-update --ignore-platform-reqs --dev --no-interaction --ansi "doctrine/mongodb-odm:^2.4" "doctrine/mongodb-odm-bundle:^4.5.1"
run: composer require --no-update --ignore-platform-reqs --dev --no-interaction --ansi "doctrine/mongodb-odm:^2.6" "doctrine/mongodb-odm-bundle:^5.0.0"

- name: 'Install dependencies'
id: deps
Expand Down Expand Up @@ -72,12 +72,7 @@ jobs:
mongodb: true

# Previous Symfony versions
#

# Previous PHP versions
#

# Most recent versions
- name: 'Test Symfony 5.4 [Linux, PHP 8.1]'
os: 'ubuntu-latest'
php: '8.1'
Expand All @@ -86,43 +81,58 @@ jobs:
mongodb: true
mysql: true

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

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

# Previous PHP versions

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

- name: 'Test Symfony 7.0 [Linux, PHP 8.2]'
# Most recent versions

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

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

# Bleeding edge (unreleased dev versions where failures are allowed)
- name: 'Test next Symfony 7.1 [Linux, PHP 8.2] (allowed failure)'
- name: 'Test next Symfony 7.2 [Linux, PHP 8.3] (allowed failure)'
os: 'ubuntu-latest'
php: '8.2'
php: '8.3'
symfony: '7.1.*@dev'
composer-flags: '--ignore-platform-req php'
allow-unstable: true
Expand All @@ -131,10 +141,10 @@ jobs:
mongodb: true
mongodbnew: true

- name: 'Test next Symfony 7.1 [Linux, PHP 8.3] (allowed failure)'
- name: 'Test next Symfony 7.2 [Linux, PHP 8.4] (allowed failure)'
os: 'ubuntu-latest'
php: '8.3'
symfony: '7.1.*@dev'
php: '8.4'
symfony: '7.2.*@dev'
composer-flags: '--ignore-platform-req php'
allow-unstable: true
allow-failure: true
Expand Down Expand Up @@ -202,7 +212,7 @@ jobs:
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"
run: composer require --no-update ${{ matrix.composer-flags }} --dev --no-interaction --ansi "doctrine/mongodb-odm:^2.6" "doctrine/mongodb-odm-bundle:^5.0.0"
if: ${{ matrix.mongodb && matrix.mongodbnew }}

- name: 'Install dependencies'
Expand Down
23 changes: 23 additions & 0 deletions .make/try.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#######
# Try #
#######

# Execute first command (try), unconditionnaly run second command (finally), and
# exit with first command return code.
#
# @param $1 First command
# @param $2 Second command
#
# Examples:
#
# Example #1: Run tests and remove artefacts
#
# $(call try_finally, phpunit, rm -Rf artefacts)

define try_finally
( \
$(strip $(1)) \
) ; RC=$${?} \
; $(strip $(2)) \
&& exit $${RC}
endef
2 changes: 1 addition & 1 deletion .php-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.1
8.2
27 changes: 15 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include .make/help.mk
include .make/text.mk
include .make/try.mk

PHP_CS_FIXER_VERSION=v3.13.0

Expand All @@ -14,7 +15,7 @@ setup:
## Install - Install deps
install: setup
install:
rm -f symfony composer.lock
rm -f composer.lock
symfony composer config minimum-stability --unset
symfony composer update --prefer-dist --ignore-platform-req=ext-mongodb

Expand All @@ -32,13 +33,6 @@ install.54:
symfony composer config minimum-stability dev
symfony composer update --ignore-platform-req=ext-mongodb

## 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.4 deps
install.64: setup
install.64: export SYMFONY_REQUIRE = 6.4.*@dev
Expand All @@ -61,8 +55,16 @@ install.71:
symfony composer update --ignore-platform-req=ext-mongodb

## Install - Add Doctrine ODM deps
deps.odm.add:
symfony composer require --no-update --no-interaction --dev "doctrine/mongodb-odm:^2.3" "doctrine/mongodb-odm-bundle:^4.4.1"
deps.odm.add: deps.odm.add+sf64

## Install - Add Doctrine ODM deps for Symfony 6.4+
deps.odm.add+sf64:
symfony composer require --no-update --no-interaction --dev "doctrine/mongodb-odm:^2.6" "doctrine/mongodb-odm-bundle:^5.0"
@$(call log_warning, Run again appropriate install target to update dependencies. Be careful not to commit compose.json changes.)

## Install - Add Doctrine ODM deps for Symfony 5.4+
deps.odm.add+sf54:
symfony composer require --no-update --no-interaction --dev "doctrine/mongodb-odm:^2.4" "doctrine/mongodb-odm-bundle:^4.5.1"
@$(call log_warning, Run again appropriate install target to update dependencies. Be careful not to commit compose.json changes.)

## Install - Remove back Doctrine ODM deps
Expand Down Expand Up @@ -108,10 +110,12 @@ lint.update:
make php-cs-fixer.phar

lint.php-cs-fixer.fix: php-cs-fixer.phar
lint.php-cs-fixer.fix: export PHP_CS_FIXER_IGNORE_ENV = 1
lint.php-cs-fixer.fix:
symfony php ./php-cs-fixer.phar fix --no-interaction

lint.php-cs-fixer: php-cs-fixer.phar
lint.php-cs-fixer: export PHP_CS_FIXER_IGNORE_ENV = 1
lint.php-cs-fixer:
symfony php ./php-cs-fixer.phar fix --no-interaction --dry-run --diff -vvv

Expand All @@ -121,5 +125,4 @@ php-cs-fixer.phar:

lint.phpstan:
@make deps.odm.add install >> /dev/null 2>&1
./vendor/bin/phpstan
@make deps.odm.rm install >> /dev/null 2>&1
$(call try_finally, ./vendor/bin/phpstan, make deps.odm.rm install >> /dev/null 2>&1)
31 changes: 15 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@
"require-dev": {
"ext-pdo_sqlite": "*",
"composer/semver": "^3.2",
"doctrine/dbal": "^3.2",
"doctrine/doctrine-bundle": "^2.5",
"doctrine/orm": "^2.10",
"doctrine/dbal": "^3.8|^4.0",
"doctrine/doctrine-bundle": "^2.11",
"doctrine/orm": "^2.20|^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"
"symfony/browser-kit": "^5.4.40|^6.4|^7.0",
"symfony/config": "^5.4.40|^6.4|^7.0",
"symfony/dependency-injection": "^5.4.40|^6.4|^7.0",
"symfony/filesystem": "^5.4.40|^6.4|^7.0",
"symfony/form": "^5.4.40|^6.4|^7.0",
"symfony/framework-bundle": "^5.4.40|^6.4|^7.0",
"symfony/http-kernel": "^5.4.40|^6.4|^7.0",
"symfony/phpunit-bridge": "^5.4.40|^6.4|^7.0",
"symfony/translation": "^5.4.40|^6.4|^7.0",
"symfony/var-dumper": "^5.4.40|^6.4|^7.0",
"symfony/yaml": "^5.4.40|^6.4|^7.0"
},
"extra": {
"branch-alias": {
Expand All @@ -68,6 +68,5 @@
"*": "dist"
},
"sort-packages": true
},
"minimum-stability": "dev"
}
}
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.3'

services:
db:
image: mysql:8.0
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon.dist → phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ parameters:
paths:
- src

checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false

ignoreErrors:
- identifier: missingType.iterableValue
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<env name="DOCTRINE_DBAL_URL" value="sqlite:///%kernel.cache_dir%/db.sqlite" />
<!--<env name="DOCTRINE_DBAL_URL" value="pdo-mysql://root@localhost:3306/doctrine_tests" />-->
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0&amp;max[self]=0&amp;max[total]=9999&amp;verbose=1&amp;baselineFile=./tests/allowed-deprecations.json&amp;generateBaseline=0"/>
<env name="SYMFONY_PHPUNIT_REQUIRE" value="phpspec/prophecy-phpunit"/>
<env name="SYMFONY_PHPUNIT_REQUIRE" value=""/>
<env name="SYMFONY_PHPUNIT_VERSION" value="9.5"/>
</php>
<testsuites>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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) {
Expand Down
48 changes: 37 additions & 11 deletions src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,44 @@
use Doctrine\DBAL\Types\Type;
use Elao\Enum\Exception\InvalidArgumentException;

if (enum_exists(ParameterType::class)) {
/**
* For doctrine/dbal 4
*
* @internal
*/
trait DbalVersionEnumTypeTrait
{
/**
* {@inheritdoc}
*/
public function getBindingType(): ParameterType
{
return $this->isIntBackedEnum() ? ParameterType::INTEGER : ParameterType::STRING;
}
}
} else {
/**
* For doctrine/dbal 3
*
* @internal
*/
trait DbalVersionEnumTypeTrait
{
/**
* {@inheritdoc}
*/
public function getBindingType(): int
{
return $this->isIntBackedEnum() ? ParameterType::INTEGER : ParameterType::STRING;
}
}
}

abstract class AbstractEnumType extends Type
{
use DbalVersionEnumTypeTrait;

private bool $isIntBackedEnum;

/**
Expand Down Expand Up @@ -103,9 +139,7 @@ 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);
}

/**
Expand All @@ -116,14 +150,6 @@ public function requiresSQLCommentHint(AbstractPlatform $platform): bool
return true;
}

/**
* {@inheritdoc}
*/
public function getBindingType(): int
{
return $this->isIntBackedEnum() ? ParameterType::INTEGER : ParameterType::STRING;
}

/**
* Cast the value from database to proper enumeration internal type.
*/
Expand Down
Loading
Loading