From eb1fa1a8aa404bc09bff83fe55b507fc8924985d Mon Sep 17 00:00:00 2001 From: Thibault Buathier Date: Thu, 18 Apr 2024 17:54:38 +0200 Subject: [PATCH 1/4] feat: compatibility with doctrine orm 3.0 minimum --- README.md | 4 -- UPGRADE.md | 7 ++ composer.json | 7 +- src/Oro/DBAL/Types/ArrayType.php | 31 -------- src/Oro/DBAL/Types/MoneyType.php | 4 +- src/Oro/DBAL/Types/ObjectType.php | 31 -------- src/Oro/DBAL/Types/PercentType.php | 4 +- .../AbstractPlatformAwareFunctionNode.php | 2 +- src/Oro/ORM/Query/AST/Functions/Cast.php | 28 ++++---- .../AST/Functions/DateTime/ConvertTz.php | 14 ++-- .../ORM/Query/AST/Functions/Numeric/Pow.php | 12 ++-- .../ORM/Query/AST/Functions/Numeric/Round.php | 14 ++-- .../ORM/Query/AST/Functions/Numeric/Sign.php | 10 +-- .../AST/Functions/Numeric/TimestampDiff.php | 18 ++--- .../Query/AST/Functions/SimpleFunction.php | 10 +-- .../Query/AST/Functions/String/ConcatWs.php | 16 ++--- .../Query/AST/Functions/String/DateFormat.php | 12 ++-- .../AST/Functions/String/GroupConcat.php | 26 +++---- .../Query/AST/Functions/String/Replace.php | 14 ++-- tests/Oro/Entities/Foo.php | 64 +++++++---------- tests/Oro/Tests/Connection/SetupTest.php | 6 +- tests/Oro/Tests/Connection/TestUtil.php | 22 ++++-- tests/Oro/Tests/DBAL/Types/ArrayTypeTest.php | 66 ----------------- tests/Oro/Tests/DBAL/Types/MoneyTypeTest.php | 2 +- tests/Oro/Tests/DBAL/Types/ObjectTypeTest.php | 70 ------------------- .../Oro/Tests/DBAL/Types/PercentTypeTest.php | 2 +- tests/Oro/Tests/TestCase.php | 2 +- 27 files changed, 150 insertions(+), 348 deletions(-) delete mode 100644 src/Oro/DBAL/Types/ArrayType.php delete mode 100644 src/Oro/DBAL/Types/ObjectType.php delete mode 100644 tests/Oro/Tests/DBAL/Types/ArrayTypeTest.php delete mode 100644 tests/Oro/Tests/DBAL/Types/ObjectTypeTest.php diff --git a/README.md b/README.md index 48934a27673..5586968f82c 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,3 @@ This library also provides the following field types: * `MoneyType` * `PercentType` -* `ObjectType` -* `ArrayType` - -`ObjectType` and `ArrayType` use Base64 encoded strings to store values in the database instead of storing serialized strings. For backward compatibility the values that are already stored in the database will be unserialized without Base64 encoding. The new values will be Base64 encoded before saving to the database and Base64 decoded before unserialization. diff --git a/UPGRADE.md b/UPGRADE.md index fe9b11a05f8..d9cb0b1676e 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,10 @@ +# Upgrade to 3.0 +Version 3.0 requires PHP 8.1 or newer and works with Doctrine/ORM 3.0 or newer. + +The following types are no longer supported : +* `ObjectType` +* `ArrayType` + # Upgrade to 2.0 Version 2.0 requires PHP 7.3 or newer and works with Doctrine/ORM 2.6 or newer. diff --git a/composer.json b/composer.json index 5f445e022c4..a2fead89587 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,9 @@ ], "require": { "php": ">=8.1", - "doctrine/orm": ">=2.6", - "doctrine/dbal": ">=2.6" + "doctrine/lexer": "~3.0", + "doctrine/orm": "~3.0", + "doctrine/dbal": "~3.0|~4.0" }, "require-dev": { "phpunit/phpunit": "~10", @@ -22,7 +23,7 @@ "symfony/yaml": "5.*", "symfony/cache": "5.*", "squizlabs/php_codesniffer": "3.5.*", - "doctrine/annotations": ">1.0, <2.0" + "doctrine/annotations": "~2.0" }, "autoload": { "psr-4": { diff --git a/src/Oro/DBAL/Types/ArrayType.php b/src/Oro/DBAL/Types/ArrayType.php deleted file mode 100644 index 7b79001300d..00000000000 --- a/src/Oro/DBAL/Types/ArrayType.php +++ /dev/null @@ -1,31 +0,0 @@ -isSerialized($value)) { - $value = \base64_decode($value); - } - - return parent::convertToPHPValue($value, $platform); - } - - /** @noinspection PhpMissingReturnTypeInspection */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) - { - $convertedValue = parent::convertToDatabaseValue($value, $platform); - return \base64_encode($convertedValue); - } - - protected function isSerialized(string $string): bool - { - return false !== \strpos($string, ';') || false !== \strpos($string, ':') || false !== \strpos($string, '{'); - } -} diff --git a/src/Oro/DBAL/Types/MoneyType.php b/src/Oro/DBAL/Types/MoneyType.php index e7fdfeb6e79..cd07ab9ea4a 100644 --- a/src/Oro/DBAL/Types/MoneyType.php +++ b/src/Oro/DBAL/Types/MoneyType.php @@ -25,7 +25,7 @@ public function getName() * @noinspection PhpMissingReturnTypeInspection * @noinspection ReturnTypeCanBeDeclaredInspection */ - public function getSQLDeclaration(array $column, AbstractPlatform $platform) + public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { $column['precision'] = self::TYPE_PRECISION; $column['scale'] = self::TYPE_SCALE; @@ -38,7 +38,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform) * @noinspection PhpMissingParentCallCommonInspection * @noinspection PhpDocSignatureInspection */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue($value, AbstractPlatform $platform): mixed { return $value; } diff --git a/src/Oro/DBAL/Types/ObjectType.php b/src/Oro/DBAL/Types/ObjectType.php deleted file mode 100644 index edd33be4943..00000000000 --- a/src/Oro/DBAL/Types/ObjectType.php +++ /dev/null @@ -1,31 +0,0 @@ -isSerialized((string) $value)) { - $value = \base64_decode($value); - } - - return parent::convertToPHPValue($value, $platform); - } - - /** @noinspection PhpMissingReturnTypeInspection */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) - { - $convertedValue = parent::convertToDatabaseValue($value, $platform); - return \base64_encode($convertedValue); - } - - protected function isSerialized(string $string): bool - { - return false !== \strpos($string, ';') || false !== \strpos($string, ':') || false !== \strpos($string, '{'); - } -} diff --git a/src/Oro/DBAL/Types/PercentType.php b/src/Oro/DBAL/Types/PercentType.php index ca2d7f489b8..c78d0ebc9db 100644 --- a/src/Oro/DBAL/Types/PercentType.php +++ b/src/Oro/DBAL/Types/PercentType.php @@ -24,7 +24,7 @@ public function getName() * @noinspection PhpMissingReturnTypeInspection * @noinspection ReturnTypeCanBeDeclaredInspection */ - public function getSQLDeclaration(array $column, AbstractPlatform $platform) + public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { return $platform->getFloatDeclarationSQL($column); } @@ -35,7 +35,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform) * @noinspection ReturnTypeCanBeDeclaredInspection * @noinspection PhpDocSignatureInspection */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue($value, AbstractPlatform $platform): mixed { return (null === $value) ? null : (double) $value; } diff --git a/src/Oro/ORM/Query/AST/Functions/AbstractPlatformAwareFunctionNode.php b/src/Oro/ORM/Query/AST/Functions/AbstractPlatformAwareFunctionNode.php index 1f347b68c7b..0878c5d0d0c 100644 --- a/src/Oro/ORM/Query/AST/Functions/AbstractPlatformAwareFunctionNode.php +++ b/src/Oro/ORM/Query/AST/Functions/AbstractPlatformAwareFunctionNode.php @@ -16,7 +16,7 @@ abstract class AbstractPlatformAwareFunctionNode extends FunctionNode * @noinspection ReturnTypeCanBeDeclaredInspection * {@inheritdoc} */ - public function getSql(SqlWalker $sqlWalker) + public function getSql(SqlWalker $sqlWalker): string { $function = FunctionFactory::create( $sqlWalker->getConnection()->getDatabasePlatform(), diff --git a/src/Oro/ORM/Query/AST/Functions/Cast.php b/src/Oro/ORM/Query/AST/Functions/Cast.php index 9a745d25679..d18135a805e 100644 --- a/src/Oro/ORM/Query/AST/Functions/Cast.php +++ b/src/Oro/ORM/Query/AST/Functions/Cast.php @@ -4,7 +4,7 @@ namespace Oro\ORM\Query\AST\Functions; use Doctrine\ORM\Query\Parser; -use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\TokenType; class Cast extends AbstractPlatformAwareFunctionNode { @@ -33,32 +33,32 @@ class Cast extends AbstractPlatformAwareFunctionNode /** * {@inheritdoc} */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->parameters[self::PARAMETER_KEY] = $parser->ArithmeticExpression(); - $parser->match(Lexer::T_AS); + $parser->match(TokenType::T_AS); - $parser->match(Lexer::T_IDENTIFIER); + $parser->match(TokenType::T_IDENTIFIER); $lexer = $parser->getLexer(); - $type = $lexer->token['value']; + $type = $lexer->token->value; - if ($lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { - $parser->match(Lexer::T_OPEN_PARENTHESIS); + if ($lexer->isNextToken(TokenType::T_OPEN_PARENTHESIS)) { + $parser->match(TokenType::T_OPEN_PARENTHESIS); $parameter = $parser->Literal(); $parameters = [ $parameter->value ]; - if ($lexer->isNextToken(Lexer::T_COMMA)) { - while ($lexer->isNextToken(Lexer::T_COMMA)) { - $parser->match(Lexer::T_COMMA); + if ($lexer->isNextToken(TokenType::T_COMMA)) { + while ($lexer->isNextToken(TokenType::T_COMMA)) { + $parser->match(TokenType::T_COMMA); $parameter = $parser->Literal(); $parameters[] = $parameter->value; } } - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); $type .= '(' . \implode(', ', $parameters) . ')'; } @@ -75,7 +75,7 @@ public function parse(Parser $parser) $this->parameters[self::TYPE_KEY] = $type; - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } protected function isSupportedType(string $type): bool diff --git a/src/Oro/ORM/Query/AST/Functions/DateTime/ConvertTz.php b/src/Oro/ORM/Query/AST/Functions/DateTime/ConvertTz.php index 06a8f8b50b2..9983d2207d6 100644 --- a/src/Oro/ORM/Query/AST/Functions/DateTime/ConvertTz.php +++ b/src/Oro/ORM/Query/AST/Functions/DateTime/ConvertTz.php @@ -4,7 +4,7 @@ namespace Oro\ORM\Query\AST\Functions\DateTime; use Doctrine\ORM\Query\Parser; -use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\TokenType; use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode; class ConvertTz extends AbstractPlatformAwareFunctionNode @@ -16,15 +16,15 @@ class ConvertTz extends AbstractPlatformAwareFunctionNode /** * {@inheritdoc} */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->parameters[self::VALUE_KEY] = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->parameters[self::FROM_TZ_KEY] = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->parameters[self::TO_TZ_KEY] = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Oro/ORM/Query/AST/Functions/Numeric/Pow.php b/src/Oro/ORM/Query/AST/Functions/Numeric/Pow.php index eee793f126d..42fad2e03b6 100644 --- a/src/Oro/ORM/Query/AST/Functions/Numeric/Pow.php +++ b/src/Oro/ORM/Query/AST/Functions/Numeric/Pow.php @@ -4,7 +4,7 @@ namespace Oro\ORM\Query\AST\Functions\Numeric; use Doctrine\ORM\Query\Parser; -use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\TokenType; use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode; class Pow extends AbstractPlatformAwareFunctionNode @@ -15,13 +15,13 @@ class Pow extends AbstractPlatformAwareFunctionNode /** * {@inheritdoc} */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->parameters[self::VALUE_KEY] = $parser->SimpleArithmeticExpression(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->parameters[self::POWER_KEY] = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Oro/ORM/Query/AST/Functions/Numeric/Round.php b/src/Oro/ORM/Query/AST/Functions/Numeric/Round.php index 0af8bc1a2e2..e52e5647b6d 100644 --- a/src/Oro/ORM/Query/AST/Functions/Numeric/Round.php +++ b/src/Oro/ORM/Query/AST/Functions/Numeric/Round.php @@ -4,7 +4,7 @@ namespace Oro\ORM\Query\AST\Functions\Numeric; use Doctrine\ORM\Query\Parser; -use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\TokenType; use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode; class Round extends AbstractPlatformAwareFunctionNode @@ -15,19 +15,19 @@ class Round extends AbstractPlatformAwareFunctionNode /** * {@inheritdoc} */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { $lexer = $parser->getLexer(); - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->parameters[self::VALUE] = $parser->SimpleArithmeticExpression(); // parse second parameter if available - if (Lexer::T_COMMA === $lexer->lookahead['type']) { - $parser->match(Lexer::T_COMMA); + if (TokenType::T_COMMA === $lexer->lookahead->type) { + $parser->match(TokenType::T_COMMA); $this->parameters[self::PRECISION] = $parser->ArithmeticPrimary(); } - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Oro/ORM/Query/AST/Functions/Numeric/Sign.php b/src/Oro/ORM/Query/AST/Functions/Numeric/Sign.php index 22870b2e99a..f1a6774c92d 100644 --- a/src/Oro/ORM/Query/AST/Functions/Numeric/Sign.php +++ b/src/Oro/ORM/Query/AST/Functions/Numeric/Sign.php @@ -4,7 +4,7 @@ namespace Oro\ORM\Query\AST\Functions\Numeric; use Doctrine\ORM\Query\Parser; -use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\TokenType; use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode; class Sign extends AbstractPlatformAwareFunctionNode @@ -14,11 +14,11 @@ class Sign extends AbstractPlatformAwareFunctionNode /** * {@inheritdoc} */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->parameters[self::PARAMETER_KEY] = $parser->SimpleArithmeticExpression(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Oro/ORM/Query/AST/Functions/Numeric/TimestampDiff.php b/src/Oro/ORM/Query/AST/Functions/Numeric/TimestampDiff.php index 2f5a71cbfb4..eba9a2c9f88 100644 --- a/src/Oro/ORM/Query/AST/Functions/Numeric/TimestampDiff.php +++ b/src/Oro/ORM/Query/AST/Functions/Numeric/TimestampDiff.php @@ -4,7 +4,7 @@ namespace Oro\ORM\Query\AST\Functions\Numeric; use Doctrine\ORM\Query\Parser; -use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\TokenType; use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode; class TimestampDiff extends AbstractPlatformAwareFunctionNode @@ -31,14 +31,14 @@ class TimestampDiff extends AbstractPlatformAwareFunctionNode /** * {@inheritdoc} */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); - $parser->match(Lexer::T_IDENTIFIER); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); $lexer = $parser->getLexer(); - $unit = strtoupper(trim($lexer->token['value'])); + $unit = strtoupper(trim($lexer->token->value)); if (!$this->isSupportedUnit($unit)) { $parser->syntaxError( \sprintf( @@ -51,11 +51,11 @@ public function parse(Parser $parser) } $this->parameters[self::UNIT_KEY] = $unit; - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->parameters[self::VAL1_KEY] = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->parameters[self::VAL2_KEY] = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } protected function isSupportedUnit(string $unit): bool diff --git a/src/Oro/ORM/Query/AST/Functions/SimpleFunction.php b/src/Oro/ORM/Query/AST/Functions/SimpleFunction.php index 49f3106c6fd..c85591e4d87 100644 --- a/src/Oro/ORM/Query/AST/Functions/SimpleFunction.php +++ b/src/Oro/ORM/Query/AST/Functions/SimpleFunction.php @@ -4,7 +4,7 @@ namespace Oro\ORM\Query\AST\Functions; use Doctrine\ORM\Query\Parser; -use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\TokenType; class SimpleFunction extends AbstractPlatformAwareFunctionNode { @@ -13,11 +13,11 @@ class SimpleFunction extends AbstractPlatformAwareFunctionNode /** * {@inheritdoc} */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->parameters[self::PARAMETER_KEY] = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Oro/ORM/Query/AST/Functions/String/ConcatWs.php b/src/Oro/ORM/Query/AST/Functions/String/ConcatWs.php index 2752e2e89a5..13c7f9c5496 100644 --- a/src/Oro/ORM/Query/AST/Functions/String/ConcatWs.php +++ b/src/Oro/ORM/Query/AST/Functions/String/ConcatWs.php @@ -4,7 +4,7 @@ namespace Oro\ORM\Query\AST\Functions\String; use Doctrine\ORM\Query\Parser; -use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\TokenType; use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode; @@ -16,22 +16,22 @@ class ConcatWs extends AbstractPlatformAwareFunctionNode /** * {@inheritdoc} */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->parameters[self::SEPARATOR_KEY] = $parser->StringPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->parameters[self::STRINGS_KEY][] = $parser->StringPrimary(); - while ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) { - $parser->match(Lexer::T_COMMA); + while ($parser->getLexer()->isNextToken(TokenType::T_COMMA)) { + $parser->match(TokenType::T_COMMA); $this->parameters[self::STRINGS_KEY][] = $parser->StringPrimary(); } - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Oro/ORM/Query/AST/Functions/String/DateFormat.php b/src/Oro/ORM/Query/AST/Functions/String/DateFormat.php index ef55fdbe98c..b2da1ebd87a 100644 --- a/src/Oro/ORM/Query/AST/Functions/String/DateFormat.php +++ b/src/Oro/ORM/Query/AST/Functions/String/DateFormat.php @@ -3,7 +3,7 @@ namespace Oro\ORM\Query\AST\Functions\String; -use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\TokenType; use Doctrine\ORM\Query\Parser; use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode; @@ -79,19 +79,19 @@ class DateFormat extends AbstractPlatformAwareFunctionNode /** * {@inheritdoc} */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->parameters[self::DATE_KEY] = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->parameters[self::FORMAT_KEY] = $parser->StringPrimary(); $this->validateFormat($parser); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } private function validateFormat(Parser $parser): void diff --git a/src/Oro/ORM/Query/AST/Functions/String/GroupConcat.php b/src/Oro/ORM/Query/AST/Functions/String/GroupConcat.php index af04c74575f..7b036e68285 100644 --- a/src/Oro/ORM/Query/AST/Functions/String/GroupConcat.php +++ b/src/Oro/ORM/Query/AST/Functions/String/GroupConcat.php @@ -4,7 +4,7 @@ namespace Oro\ORM\Query\AST\Functions\String; use Doctrine\ORM\Query\Parser; -use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\TokenType; use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode; class GroupConcat extends AbstractPlatformAwareFunctionNode @@ -18,14 +18,14 @@ class GroupConcat extends AbstractPlatformAwareFunctionNode * @url http://sysmagazine.com/posts/181666/ * {@inheritdoc} */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $lexer = $parser->getLexer(); - if ($lexer->isNextToken(Lexer::T_DISTINCT)) { - $parser->match(Lexer::T_DISTINCT); + if ($lexer->isNextToken(TokenType::T_DISTINCT)) { + $parser->match(TokenType::T_DISTINCT); $this->parameters[self::DISTINCT_KEY] = true; } @@ -34,24 +34,24 @@ public function parse(Parser $parser) $this->parameters[self::PARAMETER_KEY] = []; $this->parameters[self::PARAMETER_KEY][] = $parser->StringPrimary(); - while ($lexer->isNextToken(Lexer::T_COMMA)) { - $parser->match(Lexer::T_COMMA); + while ($lexer->isNextToken(TokenType::T_COMMA)) { + $parser->match(TokenType::T_COMMA); $this->parameters[self::PARAMETER_KEY][] = $parser->StringPrimary(); } - if ($lexer->isNextToken(Lexer::T_ORDER)) { + if ($lexer->isNextToken(TokenType::T_ORDER)) { $this->parameters[self::ORDER_KEY] = $parser->OrderByClause(); } - if ($lexer->isNextToken(Lexer::T_IDENTIFIER)) { - if (\strtolower($lexer->lookahead['value']) !== 'separator') { + if ($lexer->isNextToken(TokenType::T_IDENTIFIER)) { + if (\strtolower($lexer->lookahead->value) !== 'separator') { $parser->syntaxError('separator'); } - $parser->match(Lexer::T_IDENTIFIER); + $parser->match(TokenType::T_IDENTIFIER); $this->parameters[self::SEPARATOR_KEY] = $parser->StringPrimary(); } - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Oro/ORM/Query/AST/Functions/String/Replace.php b/src/Oro/ORM/Query/AST/Functions/String/Replace.php index a6481972dd8..466520f07d1 100644 --- a/src/Oro/ORM/Query/AST/Functions/String/Replace.php +++ b/src/Oro/ORM/Query/AST/Functions/String/Replace.php @@ -4,7 +4,7 @@ namespace Oro\ORM\Query\AST\Functions\String; use Doctrine\ORM\Query\Parser; -use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\TokenType; use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode; @@ -17,21 +17,21 @@ class Replace extends AbstractPlatformAwareFunctionNode /** * {@inheritdoc} */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->parameters[self::SUBJECT_KEY] = $parser->StringPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->parameters[self::FROM_KEY] = $parser->StringPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->parameters[self::TO_KEY] = $parser->StringPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/tests/Oro/Entities/Foo.php b/tests/Oro/Entities/Foo.php index 5958ae580b3..51a4bb77b54 100644 --- a/tests/Oro/Entities/Foo.php +++ b/tests/Oro/Entities/Foo.php @@ -3,48 +3,32 @@ namespace Oro\Entities; -/** - * @Entity - * @Table(name="test_foo") - */ +use Doctrine\ORM\Mapping\Column; +use Doctrine\ORM\Mapping\Entity; +use Doctrine\ORM\Mapping\GeneratedValue; +use Doctrine\ORM\Mapping\Id; +use Doctrine\ORM\Mapping\Table; + +#[Entity] +#[Table(name: 'test_foo')] class Foo { - /** - * @var int - * - * @Id - * @Column(type="integer", name="id") - * @GeneratedValue(strategy="AUTO") - */ - protected $id; - - /** - * @var string - * - * @Column(name="name", type="string", length=255) - */ - protected $name; - - /** - * @var \DateTime $createdAt - * - * @Column(name="created_at", type="datetime", nullable=true) - */ - protected $createdAt; - - /** - * @var float - * - * @Column(name="budget", type="float", nullable=true) - */ - protected $budget; - - /** - * @var string - * - * @Column(name="code", type="string", length=255) - */ - protected $code; + #[Id] + #[Column(name: 'id', type: 'integer')] + #[GeneratedValue(strategy: 'AUTO')] + protected int $id; + + #[Column(name: "name", type: "string", length: 255)] + protected string $name; + + #[Column(name: "created_at", type: "datetime", nullable: true)] + protected \DateTime $createdAt; + + #[Column(name: "budget", type: "float", nullable: true)] + protected float $budget; + + #[Column(name: "code", type: "string", length: 255)] + protected string $code; public function getId(): ?int { diff --git a/tests/Oro/Tests/Connection/SetupTest.php b/tests/Oro/Tests/Connection/SetupTest.php index c04bd8e7439..950348ce25f 100644 --- a/tests/Oro/Tests/Connection/SetupTest.php +++ b/tests/Oro/Tests/Connection/SetupTest.php @@ -6,7 +6,7 @@ use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Loader; use Doctrine\Common\DataFixtures\Purger\ORMPurger; -use Doctrine\ORM\ORMException; +use Doctrine\DBAL\Exception; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\Tools\ToolsException; use Oro\Tests\TestCase; @@ -14,13 +14,13 @@ class SetupTest extends TestCase { /** - * @throws ORMException * @throws ToolsException + * @throws Exception */ public function testSchemaUp(): void { $this->entityManager = TestUtil::getEntityManager(); - $schemaManager = $this->entityManager->getConnection()->getSchemaManager(); + $schemaManager = $this->entityManager->getConnection()->createSchemaManager(); $schemaTool = new SchemaTool($this->entityManager); $tables = $schemaManager->listTableNames(); diff --git a/tests/Oro/Tests/Connection/TestUtil.php b/tests/Oro/Tests/Connection/TestUtil.php index c2a2cc2e78d..2abcb232472 100644 --- a/tests/Oro/Tests/Connection/TestUtil.php +++ b/tests/Oro/Tests/Connection/TestUtil.php @@ -3,8 +3,11 @@ namespace Oro\Tests\Connection; +use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Tools\Setup; +use Doctrine\ORM\ORMSetup; class TestUtil { @@ -13,7 +16,6 @@ class TestUtil /** * @throws \RuntimeException - * @throws \Doctrine\ORM\ORMException */ public static function getEntityManager(): EntityManager { @@ -21,8 +23,8 @@ public static function getEntityManager(): EntityManager $dbParams = self::getConnectionParams(); $entitiesPath = \realpath(__DIR__ . '/../../Entities'); - $config = Setup::createAnnotationMetadataConfiguration([$entitiesPath], true); - self::$entityManager = EntityManager::create($dbParams, $config); + $config = ORMSetup::createAttributeMetadataConfiguration([$entitiesPath], true); + self::$entityManager = new EntityManager(DriverManager::getConnection($dbParams), $config); } if (self::$entityManager) { @@ -68,10 +70,20 @@ private static function getConnectionParams(): array /** * @throws \Exception + * @throws \Doctrine\DBAL\Exception */ public static function getPlatformName(): string { $entityManager = self::getEntityManager(); - return $entityManager->getConnection()->getDatabasePlatform()->getName(); + + $platform = $entityManager->getConnection()->getDatabasePlatform(); + + if ($platform instanceof AbstractMySQLPlatform) { + return 'mysql'; + } else if ($platform instanceof PostgreSQLPlatform) { + return 'postgresql'; + } + + throw new \Exception(sprintf('Platform "%s" not supported', $platform::class)); } } diff --git a/tests/Oro/Tests/DBAL/Types/ArrayTypeTest.php b/tests/Oro/Tests/DBAL/Types/ArrayTypeTest.php deleted file mode 100644 index 22db31e1b8a..00000000000 --- a/tests/Oro/Tests/DBAL/Types/ArrayTypeTest.php +++ /dev/null @@ -1,66 +0,0 @@ -getConnection()->getDatabasePlatform(); - $type = $this->getType(); - - $actualDbValue = $type->convertToDatabaseValue($data, $platform); - static::assertEquals($encoded, $actualDbValue); - static::assertEquals($data, $type->convertToPHPValue($actualDbValue, $platform)); - static::assertEquals($data, $type->convertToPHPValue($encoded, $platform)); - } - - /** - * @dataProvider serializationDataProvider - * @throws Exception - * @throws ORMException - */ - public function testCompatibilityMode(array $data): void - { - $dataSerialized = \serialize($data); - - $platform = TestUtil::getEntityManager()->getConnection()->getDatabasePlatform(); - $type = $this->getType(); - - static::assertEquals($data, $type->convertToPHPValue($dataSerialized, $platform)); - } - - /** - * @throws Exception - */ - protected function getType(): Type - { - /** @noinspection PhpFullyQualifiedNameUsageInspection */ - Type::overrideType(Types::ARRAY, \Oro\DBAL\Types\ArrayType::class); - return Type::getType(Types::ARRAY); - } - - public static function serializationDataProvider(): array - { - return [ - [['a' => 'b']], - [[]], - [[1, 2, 3]], - ]; - } -} diff --git a/tests/Oro/Tests/DBAL/Types/MoneyTypeTest.php b/tests/Oro/Tests/DBAL/Types/MoneyTypeTest.php index 6edb6fa9f00..688bf92a6c0 100644 --- a/tests/Oro/Tests/DBAL/Types/MoneyTypeTest.php +++ b/tests/Oro/Tests/DBAL/Types/MoneyTypeTest.php @@ -5,7 +5,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Types\Type; -use Doctrine\ORM\ORMException; +use Doctrine\ORM\Exception\ORMException; use Oro\DBAL\Types\MoneyType; use Oro\Tests\Connection\TestUtil; use PHPUnit\Framework\TestCase; diff --git a/tests/Oro/Tests/DBAL/Types/ObjectTypeTest.php b/tests/Oro/Tests/DBAL/Types/ObjectTypeTest.php deleted file mode 100644 index 27c32e09d6f..00000000000 --- a/tests/Oro/Tests/DBAL/Types/ObjectTypeTest.php +++ /dev/null @@ -1,70 +0,0 @@ -getConnection()->getDatabasePlatform(); - $type = $this->getType(); - - $actualDbValue = $type->convertToDatabaseValue($data, $platform); - static::assertEquals($encoded, $actualDbValue); - static::assertEquals($data, $type->convertToPHPValue($actualDbValue, $platform)); - static::assertEquals($data, $type->convertToPHPValue($encoded, $platform)); - } - - /** - * @dataProvider serializationDataProvider - * @throws Exception - * @throws ORMException - */ - public function testCompatibilityMode(object $data): void - { - $dataSerialized = serialize($data); - - $platform = TestUtil::getEntityManager()->getConnection()->getDatabasePlatform(); - $type = $this->getType(); - - static::assertEquals($data, $type->convertToPHPValue($dataSerialized, $platform)); - } - - /** - * @throws Exception - */ - protected function getType(): Type - { - /** @noinspection PhpFullyQualifiedNameUsageInspection */ - Type::overrideType(Types::OBJECT, \Oro\DBAL\Types\ObjectType::class); - return Type::getType(Types::OBJECT); - } - - public static function serializationDataProvider(): array - { - $object = new \stdClass(); - $object->a = 'test1'; - - $emptyObject = new \stdClass(); - - return [ - [$object], - [$emptyObject] - ]; - } -} diff --git a/tests/Oro/Tests/DBAL/Types/PercentTypeTest.php b/tests/Oro/Tests/DBAL/Types/PercentTypeTest.php index 8959aff25f3..fc71625e6ab 100644 --- a/tests/Oro/Tests/DBAL/Types/PercentTypeTest.php +++ b/tests/Oro/Tests/DBAL/Types/PercentTypeTest.php @@ -5,7 +5,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Types\Type; -use Doctrine\ORM\ORMException; +use Doctrine\ORM\Exception\ORMException; use Oro\DBAL\Types\PercentType; use Oro\Tests\Connection\TestUtil; use PHPUnit\Framework\TestCase; diff --git a/tests/Oro/Tests/TestCase.php b/tests/Oro/Tests/TestCase.php index 99d3e38a0e3..10819e60892 100644 --- a/tests/Oro/Tests/TestCase.php +++ b/tests/Oro/Tests/TestCase.php @@ -4,7 +4,7 @@ namespace Oro\Tests; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\ORMException; +use Doctrine\ORM\Exception\ORMException; use Oro\Tests\Connection\TestUtil; class TestCase extends \PHPUnit\Framework\TestCase From 9fa0eed0f13486d6b13c2e15717beaf01f0b6e3f Mon Sep 17 00:00:00 2001 From: Thibault Buathier Date: Thu, 18 Apr 2024 18:11:49 +0200 Subject: [PATCH 2/4] docs: change minimum version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5586968f82c..45f9c5576fd 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Add the following dependency to your composer.json: ```json { "require": { - "oro/doctrine-extensions": "^2.0" + "oro/doctrine-extensions": "^3.0" } } ``` From 6122f492e81f9679d1ca4443d473f36bfd79e7c0 Mon Sep 17 00:00:00 2001 From: Thibault Buathier Date: Thu, 18 Apr 2024 18:25:07 +0200 Subject: [PATCH 3/4] fix: styles --- composer.json | 2 +- tests/Oro/Tests/Connection/TestUtil.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a2fead89587..d622aed24ba 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "doctrine/data-fixtures": "^1.3", "symfony/yaml": "5.*", "symfony/cache": "5.*", - "squizlabs/php_codesniffer": "3.5.*", + "squizlabs/php_codesniffer": "3.9.*", "doctrine/annotations": "~2.0" }, "autoload": { diff --git a/tests/Oro/Tests/Connection/TestUtil.php b/tests/Oro/Tests/Connection/TestUtil.php index 2abcb232472..162a71701d0 100644 --- a/tests/Oro/Tests/Connection/TestUtil.php +++ b/tests/Oro/Tests/Connection/TestUtil.php @@ -80,7 +80,7 @@ public static function getPlatformName(): string if ($platform instanceof AbstractMySQLPlatform) { return 'mysql'; - } else if ($platform instanceof PostgreSQLPlatform) { + } elseif ($platform instanceof PostgreSQLPlatform) { return 'postgresql'; } From b2216309d278690b9c3df625258b4fb446e122cc Mon Sep 17 00:00:00 2001 From: Thibault Buathier Date: Mon, 22 Apr 2024 08:57:43 +0200 Subject: [PATCH 4/4] fix: tear down test --- tests/Oro/Tests/Connection/TearDownTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Oro/Tests/Connection/TearDownTest.php b/tests/Oro/Tests/Connection/TearDownTest.php index ecf42e6a5dd..8474791eb56 100644 --- a/tests/Oro/Tests/Connection/TearDownTest.php +++ b/tests/Oro/Tests/Connection/TearDownTest.php @@ -13,7 +13,7 @@ public function testSchemaDown(): void $schemaTool = new SchemaTool($this->entityManager); $schemaTool->dropDatabase(); - $schemaManager = $this->entityManager->getConnection()->getSchemaManager(); + $schemaManager = $this->entityManager->getConnection()->createSchemaManager(); $tables = $schemaManager->listTableNames(); static::assertEmpty($tables); }