|
17 | 17 |
|
18 | 18 | namespace TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Snapshot; |
19 | 19 |
|
| 20 | +use Doctrine\DBAL\ParameterType; |
20 | 21 | use Doctrine\DBAL\Schema\Table; |
| 22 | +use Doctrine\DBAL\Types\Type; |
| 23 | +use Doctrine\DBAL\Types\Types; |
21 | 24 | use TYPO3\CMS\Core\Database\Connection; |
22 | 25 | use TYPO3\CMS\Core\Database\Query\QueryBuilder as TYPO3QueryBuilder; |
23 | 26 | use TYPO3\TestingFramework\Core\Testbase; |
@@ -116,9 +119,19 @@ private function prepareColumns(array $columnNames, Table $table): array |
116 | 119 | { |
117 | 120 | $columnTypes = array_map( |
118 | 121 | function (string $columnName) use ($table) { |
119 | | - return $table->getColumn($columnName) |
120 | | - ->getType() |
121 | | - ->getBindingType(); |
| 122 | + // Doctrine DBAL v4 converted the `*ParameterType` to an enum, and therefore returning this enum instead |
| 123 | + // of the string value like before. As this is a non-baked enum, it cannot be serialized or json_encoded, |
| 124 | + // and breaking the snapshot export badly. Due to the requirement to support Doctrine DBAL v3 and v4 it |
| 125 | + // is necessary to detect the enum end return the doctrine type name instead. The `Connection->insert()` |
| 126 | + // adjustment is adjusted to transform the provided types during import to the correct ParameterType |
| 127 | + // again. |
| 128 | + // @see https://github.com/doctrine/dbal/blob/4.0.x/UPGRADE.md#bc-break-converted-enum-like-classes-to-enums |
| 129 | + // @todo Simplify this after Doctine DBAL v3 support can be dropped. |
| 130 | + $type = $table->getColumn($columnName)->getType(); |
| 131 | + $bindingType = $type->getBindingType(); |
| 132 | + return (enum_exists(ParameterType::class)) |
| 133 | + ? Type::lookupName($type) |
| 134 | + : $type->getBindingType(); |
122 | 135 | }, |
123 | 136 | $columnNames |
124 | 137 | ); |
|
0 commit comments