Skip to content

Commit

Permalink
do not require support for releasing savepoints (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher authored Aug 9, 2023
1 parent a9ff7d7 commit 8b0991d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public function commit(): bool
throw new \BadMethodCallException(sprintf('Bad call to "%s". There is no savepoint for a nested transaction.', __METHOD__));
}

$this->exec($this->platform->releaseSavePoint(self::SAVEPOINT_NAME));
if ($this->platform->supportsReleaseSavepoints()) {
$this->exec($this->platform->releaseSavePoint(self::SAVEPOINT_NAME));
}

$this->nested = false;

Expand Down
2 changes: 1 addition & 1 deletion src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function connect(array $params): DriverConnection
? $this->createDatabasePlatformForVersion($params['serverVersion'])
: $this->getDatabasePlatform());

if (!$platform->supportsSavepoints() || !$platform->supportsReleaseSavepoints()) {
if (!$platform->supportsSavepoints()) {
throw new \RuntimeException('This bundle only works for database platforms that support savepoints.');
}

Expand Down
9 changes: 7 additions & 2 deletions tests/DAMA/DoctrineTestBundle/Doctrine/DBAL/MockDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use PHPUnit\Framework\MockObject\Generator;

class MockDriver implements Driver
{
private function getMock(string $class)
{
return (new Generator())->getMock(
// TODO: remove this once we drop support for PHPUnit < 10
$generatorClass = class_exists('PHPUnit\Framework\MockObject\Generator')
? 'PHPUnit\Framework\MockObject\Generator'
: 'PHPUnit\Framework\MockObject\Generator\Generator';

/** @phpstan-ignore-next-line */
return (new $generatorClass())->getMock(
$class,
[],
[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ public function testConnectWithPlatform(): void
->method('supportsSavepoints')
->willReturn(true)
;
$platform
->expects(self::exactly(7))
->method('supportsReleaseSavepoints')
->willReturn(true)
;

$params = [
'driver' => 'pdo_mysql',
Expand Down
11 changes: 11 additions & 0 deletions tests/Functional/PhpunitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,21 @@ public function testChangeDbStateWithinTransaction(): void
$this->rollbackTransaction();
$this->assertRowCount(0);

$this->beginTransaction();
$this->insertRow();
$this->assertRowCount(1);
$this->rollbackTransaction();
$this->assertRowCount(0);

$this->beginTransaction();
$this->insertRow();
$this->commitTransaction();
$this->assertRowCount(1);

$this->beginTransaction();
$this->insertRow();
$this->commitTransaction();
$this->assertRowCount(2);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions tests/Functional/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Tests\Functional\app;

use DAMA\DoctrineTestBundle\DAMADoctrineTestBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
Expand All @@ -12,9 +15,9 @@ class AppKernel extends Kernel
public function registerBundles(): array
{
return [
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new \DAMA\DoctrineTestBundle\DAMADoctrineTestBundle(),
new FrameworkBundle(),
new DoctrineBundle(),
new DAMADoctrineTestBundle(),
];
}

Expand Down

0 comments on commit 8b0991d

Please sign in to comment.