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

Run builds with DBAL 4.0.x-dev #9727

Merged
merged 5 commits into from
May 6, 2022
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
1 change: 1 addition & 0 deletions lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
continue;
}

unset($classAnnotations[$key]);
$classAnnotations[get_class($annot)] = $annot;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/ORM/OptimisticLockException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DateTimeInterface;
use Doctrine\ORM\Exception\ORMException;
use Exception;
use Throwable;

/**
* An OptimisticLockException is thrown when a version check on an object
Expand All @@ -21,9 +22,9 @@ class OptimisticLockException extends Exception implements ORMException
* @param string $msg
* @param object|null $entity
*/
public function __construct($msg, $entity)
public function __construct($msg, $entity, ?Throwable $previous = null)
{
parent::__construct($msg);
parent::__construct($msg, 0, $previous);
$this->entity = $entity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ private function deleteJoinedEntityCollection(PersistentCollection $collection):

foreach ($idColumnNames as $idColumnName) {
$columnDefinitions[$idColumnName] = [
'name' => $idColumnName,
'notnull' => true,
'type' => Type::getType(PersisterHelper::getTypeOfColumn($idColumnName, $rootClass, $this->em)),
];
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ protected function getSelectConditionDiscriminatorValueSQL(): string
$values = [];

if ($this->class->discriminatorValue !== null) { // discriminators can be 0
$values[] = $this->conn->quote($this->class->discriminatorValue);
$values[] = $this->conn->quote((string) $this->class->discriminatorValue);
}

$discrValues = array_flip($this->class->discriminatorMap);

foreach ($this->class->subClasses as $subclassName) {
$values[] = $this->conn->quote($discrValues[$subclassName]);
$values[] = $this->conn->quote((string) $discrValues[$subclassName]);
}

$discColumnName = $this->class->getDiscriminatorColumn()['name'];
Expand Down
1 change: 1 addition & 0 deletions lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function __construct(AST\Node $AST, $sqlWalker)
$columnDefinitions = [];
foreach ($idColumnNames as $idColumnName) {
$columnDefinitions[$idColumnName] = [
'name' => $idColumnName,
'notnull' => true,
'type' => Type::getType(PersisterHelper::getTypeOfColumn($idColumnName, $rootClass, $em)),
];
Expand Down
1 change: 1 addition & 0 deletions lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public function __construct(AST\Node $AST, $sqlWalker)

foreach ($idColumnNames as $idColumnName) {
$columnDefinitions[$idColumnName] = [
'name' => $idColumnName,
'notnull' => true,
'type' => Type::getType(PersisterHelper::getTypeOfColumn($idColumnName, $rootClass, $em)),
];
Expand Down
6 changes: 2 additions & 4 deletions lib/Doctrine/ORM/Query/Filter/SQLFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ final public function getParameter(string $name): string
throw FilterException::cannotConvertListParameterIntoSingleValue($name);
}

$param = $this->parameters[$name];

return $this->em->getConnection()->quote($param['value'], $param['type']);
return $this->em->getConnection()->quote((string) $this->parameters[$name]['value']);
}

/**
Expand All @@ -133,7 +131,7 @@ final public function getParameterList(string $name): string
$connection = $this->em->getConnection();

$quoted = array_map(
static fn (mixed $value): string => (string) $connection->quote($value, $param['type']),
static fn (mixed $value): string => $connection->quote((string) $value),
$param['value']
);

Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private function generateDiscriminatorColumnConditionSQL(array $dqlAliases): str
}

foreach ($class->subClasses as $subclassName) {
$values[] = $conn->quote($this->em->getClassMetadata($subclassName)->discriminatorValue);
$values[] = $conn->quote((string) $this->em->getClassMetadata($subclassName)->discriminatorValue);
}

$sqlTableAlias = $this->useSqlTableAliases
Expand Down Expand Up @@ -1812,7 +1812,7 @@ public function walkUpdateItem($updateItem)
break;

default:
$sql .= $this->conn->quote($newValue);
$sql .= $this->conn->quote((string) $newValue);
break;
}

Expand Down Expand Up @@ -2225,7 +2225,7 @@ public function walkInputParameter($inputParam)

if ($parameter) {
$type = $parameter->getType();
if (Type::hasType($type)) {
if (is_string($type) && Type::hasType($type)) {
return Type::getType($type)->convertToDatabaseValueSQL('?', $this->platform);
}
}
Expand Down
15 changes: 12 additions & 3 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\EventManager;
use Doctrine\Common\Proxy\Proxy;
use Doctrine\DBAL;
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
use Doctrine\DBAL\LockMode;
use Doctrine\Deprecations\Deprecation;
Expand Down Expand Up @@ -406,9 +407,17 @@ public function commit(): void
}
}

// Commit failed silently
if ($conn->commit() === false) {
throw new OptimisticLockException('Commit failed', null);
$commitFailed = false;
try {
if ($conn->commit() === false) {
$commitFailed = true;
}
} catch (DBAL\Exception $e) {
$commitFailed = true;
}

if ($commitFailed) {
throw new OptimisticLockException('Commit failed', null, $e ?? null);
}
} catch (Throwable $e) {
$this->em->close();
Expand Down
3 changes: 3 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,9 @@
<PossiblyUndefinedVariable occurrences="1">
<code>$columnList</code>
</PossiblyUndefinedVariable>
<RedundantCastGivenDocblockType occurrences="1">
<code>(string) $discrValues[$subclassName]</code>
</RedundantCastGivenDocblockType>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed up into b291c4e

</file>
<file src="lib/Doctrine/ORM/Proxy/ProxyFactory.php">
<ArgumentTypeCoercion occurrences="2">
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
<errorLevel type="suppress">
<file name="lib/Doctrine/ORM/Internal/SQLResultCasing.php"/>
<file name="lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php"/>
<!-- DBAL 3 compatibility -->
<file name="lib/Doctrine/ORM/UnitOfWork.php"/>
</errorLevel>
</TypeDoesNotContainType>
<UndefinedClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function testDeleteManyToManyUsesTypeValuesSQL(): void

$connection->expects($this->atLeast(2))
->method('delete')
->will($this->onConsecutiveCalls(
->withConsecutive(
morozov marked this conversation as resolved.
Show resolved Hide resolved
[
'customtype_parent_friends',
['friend_customtypeparent_id' => 1],
Expand All @@ -214,7 +214,7 @@ public function testDeleteManyToManyUsesTypeValuesSQL(): void
['customtypeparent_id' => 1],
['integer'],
]
));
);

$persister->delete($parent);
}
Expand Down
6 changes: 4 additions & 2 deletions tests/Doctrine/Tests/ORM/UnitOfWorkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\EventManager;
use Doctrine\DBAL;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
Expand Down Expand Up @@ -595,7 +596,7 @@ public function testPreviousDetectedIllegalNewNonCascadedEntitiesAreCleanedUpOnS
/**
* @group #7946 Throw OptimisticLockException when connection::commit() returns false.
*/
public function testCommitThrowOptimisticLockExceptionWhenConnectionCommitReturnFalse(): void
public function testCommitThrowOptimisticLockExceptionWhenConnectionCommitFails(): void
{
$platform = $this->getMockBuilder(AbstractPlatform::class)
->onlyMethods(['supportsIdentityColumns'])
Expand All @@ -618,7 +619,8 @@ public function testCommitThrowOptimisticLockExceptionWhenConnectionCommitReturn
$this->_unitOfWork = new UnitOfWorkMock($this->_emMock);
$this->_emMock->setUnitOfWork($this->_unitOfWork);

$this->connection->method('commit')->willReturn(false);
$this->connection->method('commit')
->willThrowException(new DBAL\Exception());

// Setup fake persister and id generator
$userPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(ForumUser::class));
Expand Down
7 changes: 6 additions & 1 deletion tests/Doctrine/Tests/OrmTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\SchemaConfig;
use Doctrine\ORM\Cache\CacheConfiguration;
use Doctrine\ORM\Cache\CacheFactory;
use Doctrine\ORM\Cache\DefaultCacheFactory;
Expand Down Expand Up @@ -181,11 +182,15 @@ private function createDriverMock(AbstractPlatform $platform): Driver
$connection->method('query')
->willReturn($result);

$schemaManager = $this->createMock(AbstractSchemaManager::class);
$schemaManager->method('createSchemaConfig')
->willReturn(new SchemaConfig());

$driver = $this->createMock(Driver::class);
$driver->method('connect')
->willReturn($connection);
$driver->method('getSchemaManager')
->willReturn($this->createMock(AbstractSchemaManager::class));
->willReturn($schemaManager);
$driver->method('getDatabasePlatform')
->willReturn($platform);

Expand Down