-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
217 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticConnectionTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace DAMA\DoctrineTestBundle\Doctrine\DBAL; | ||
|
||
use Doctrine\DBAL\Driver\Connection; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
trait StaticConnectionTrait | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private $connection; | ||
|
||
/** | ||
* @var AbstractPlatform | ||
*/ | ||
private $platform; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $nested = false; | ||
|
||
public function __construct(Connection $connection, AbstractPlatform $platform) | ||
{ | ||
parent::__construct($connection); | ||
$this->connection = $connection; | ||
$this->platform = $platform; | ||
} | ||
|
||
private function doBeginTransaction(): void | ||
{ | ||
if ($this->nested) { | ||
throw new \BadMethodCallException(sprintf('Bad call to "%s". A savepoint is already in use for a nested transaction.', __METHOD__)); | ||
} | ||
|
||
$this->exec($this->platform->createSavePoint('DAMA_TEST')); | ||
|
||
$this->nested = true; | ||
} | ||
|
||
private function doCommit(): void | ||
{ | ||
if (!$this->nested) { | ||
throw new \BadMethodCallException(sprintf('Bad call to "%s". There is no savepoint for a nested transaction.', __METHOD__)); | ||
} | ||
|
||
if ($this->platform->supportsReleaseSavepoints()) { | ||
$this->exec($this->platform->releaseSavePoint('DAMA_TEST')); | ||
} | ||
|
||
$this->nested = false; | ||
} | ||
|
||
private function doRollBack(): void | ||
{ | ||
if (!$this->nested) { | ||
throw new \BadMethodCallException(sprintf('Bad call to "%s". There is no savepoint for a nested transaction.', __METHOD__)); | ||
} | ||
|
||
$this->exec($this->platform->rollbackSavePoint('DAMA_TEST')); | ||
|
||
$this->nested = false; | ||
} | ||
|
||
public function getWrappedConnection(): Connection | ||
{ | ||
return $this->connection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/DAMA/DoctrineTestBundle/Doctrine/DBAL/MockDriverTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Tests\DAMA\DoctrineTestBundle\Doctrine\DBAL; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Driver; | ||
use Doctrine\DBAL\Driver\API\ExceptionConverter; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Schema\AbstractSchemaManager; | ||
|
||
trait MockDriverTrait | ||
{ | ||
private $connection; | ||
private $schemaManager; | ||
private $exceptionConverter; | ||
|
||
/** | ||
* @param Driver\Connection $connection | ||
* @param AbstractSchemaManager $schemaManager | ||
* @param ExceptionConverter $exceptionConverter | ||
*/ | ||
public function __construct( | ||
$connection, | ||
$schemaManager, | ||
$exceptionConverter | ||
) { | ||
$this->connection = $connection; | ||
$this->schemaManager = $schemaManager; | ||
$this->exceptionConverter = $exceptionConverter; | ||
} | ||
|
||
public function connect(array $params): Driver\Connection | ||
{ | ||
return clone $this->connection; | ||
} | ||
|
||
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager | ||
{ | ||
return $this->schemaManager; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'mock'; | ||
} | ||
|
||
public function getDatabase(Connection $conn): string | ||
{ | ||
return 'mock'; | ||
} | ||
|
||
public function getExceptionConverter(): ExceptionConverter | ||
{ | ||
return $this->exceptionConverter; | ||
} | ||
} |
Oops, something went wrong.