-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
* 3.8.x: Run tests on MySQL 8.2 (doctrine#6207) MySQLSchemaManager. Check expected database type for json columns only. (doctrine#6189) Make the type annotation for CompositeExpression::count more specific (doctrine#6188)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,7 +349,7 @@ jobs: | |
mysql-version: | ||
- "5.7" | ||
- "8.0" | ||
- "8.1" | ||
- "8.2" | ||
extension: | ||
- "mysqli" | ||
- "pdo_mysql" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\Schema; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Schema\AbstractSchemaManager; | ||
use Doctrine\DBAL\Schema\Comparator; | ||
use Doctrine\DBAL\Schema\Table; | ||
use Doctrine\DBAL\Tests\Functional\Schema\Types\MoneyType; | ||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
use Doctrine\DBAL\Types\Type; | ||
|
||
use function array_map; | ||
use function implode; | ||
use function sprintf; | ||
|
||
/** | ||
* Tests introspection of a custom column type with an underlying decimal column | ||
* on MySQL and MariaDb platforms. | ||
* | ||
* See bug #6185 | ||
*/ | ||
class CustomIntrospectionTest extends FunctionalTestCase | ||
{ | ||
private AbstractSchemaManager $schemaManager; | ||
|
||
private Comparator $comparator; | ||
|
||
private AbstractPlatform $platform; | ||
|
||
public static function setUpBeforeClass(): void | ||
{ | ||
Type::addType('money', MoneyType::class); | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->platform = $this->connection->getDatabasePlatform(); | ||
|
||
if (! $this->platform instanceof AbstractMySQLPlatform) { | ||
self::markTestSkipped(); | ||
} | ||
|
||
$this->schemaManager = $this->connection->createSchemaManager(); | ||
$this->comparator = $this->schemaManager->createComparator(); | ||
} | ||
|
||
public function testCustomColumnIntrospection(): void | ||
{ | ||
$tableName = 'test_custom_column_introspection'; | ||
$table = new Table($tableName); | ||
|
||
$table->addColumn('id', 'integer'); | ||
$table->addColumn('quantity', 'decimal'); | ||
$table->addColumn('amount', 'money', [ | ||
'notnull' => false, | ||
'scale' => 2, | ||
'precision' => 10, | ||
]); | ||
|
||
$this->dropAndCreateTable($table); | ||
|
||
$onlineTable = $this->schemaManager->introspectTable($tableName); | ||
|
||
$diff = $this->comparator->compareTables($table, $onlineTable); | ||
$changedCols = []; | ||
|
||
if (! $diff->isEmpty()) { | ||
$changedCols = array_map(static fn ($c) => $c->getOldColumnName()->getName(), $diff->getModifiedColumns()); | ||
Check failure on line 72 in tests/Functional/Schema/CustomIntrospectionTest.php GitHub Actions / Static Analysis with Psalm (8.2)MissingClosureReturnType
Check failure on line 72 in tests/Functional/Schema/CustomIntrospectionTest.php GitHub Actions / Static Analysis with Psalm (8.2)UndefinedMethod
|
||
} | ||
|
||
self::assertTrue($diff->isEmpty(), sprintf( | ||
'Tables should be identical. Differences detected in %s.', | ||
implode(':', $changedCols), | ||
)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\Schema\Types; | ||
|
||
final class Money | ||
{ | ||
private string $value; | ||
|
||
public function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\Schema\Types; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Types\ConversionException; | ||
use Doctrine\DBAL\Types\Type; | ||
use InvalidArgumentException; | ||
|
||
use function is_string; | ||
|
||
class MoneyType extends Type | ||
{ | ||
public const NAME = 'money'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getName() | ||
Check failure on line 19 in tests/Functional/Schema/Types/MoneyType.php GitHub Actions / Static Analysis with Psalm (8.2)MissingReturnType
|
||
{ | ||
return self::NAME; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string | ||
{ | ||
return $platform->getDecimalTypeDeclarationSQL($column); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string | ||
{ | ||
if ($value === null) { | ||
return $value; | ||
} | ||
|
||
if ($value instanceof Money) { | ||
return $value->__toString(); | ||
} | ||
|
||
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', Money::class]); | ||
Check failure on line 45 in tests/Functional/Schema/Types/MoneyType.php GitHub Actions / Static Analysis with Psalm (8.2)UndefinedMethod
|
||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function convertToPHPValue($value, AbstractPlatform $platform): ?Money | ||
{ | ||
if ($value === null || $value instanceof Money) { | ||
return $value; | ||
} | ||
|
||
if (! is_string($value)) { | ||
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'string']); | ||
Check failure on line 58 in tests/Functional/Schema/Types/MoneyType.php GitHub Actions / Static Analysis with Psalm (8.2)UndefinedMethod
|
||
} | ||
|
||
try { | ||
return new Money($value); | ||
} catch (InvalidArgumentException $e) { | ||
throw ConversionException::conversionFailedFormat($value, $this->getName(), Money::class, $e); | ||
Check failure on line 64 in tests/Functional/Schema/Types/MoneyType.php GitHub Actions / Static Analysis with Psalm (8.2)UndefinedMethod
|
||
} | ||
} | ||
|
||
public function requiresSQLCommentHint(AbstractPlatform $platform): bool | ||
{ | ||
return true; | ||
} | ||
} |