Skip to content

Instantly share code, notes, and snippets.

@mirdic
Created March 24, 2020 22:33
Show Gist options
  • Save mirdic/93d056d619864fe48343fea92ba8b19d to your computer and use it in GitHub Desktop.
Save mirdic/93d056d619864fe48343fea92ba8b19d to your computer and use it in GitHub Desktop.
<?php declare(strict_types=1);
namespace Test\Functional\ApiModule\V1Module;
class BaseApiTest extends BaseFunctionalTest
{
protected function _before()
{
/** @var EntityManager $em */
$em = $this->tester->grabService(EntityManager::class);
$em->clear();
if ($em->getConnection()->isTransactionActive()) {
try {
while ($em->getConnection()->getTransactionNestingLevel() > 0) {
$em->getConnection()->rollback();
}
} catch (\PDOException $e) {
}
}
$em->getConnection()->beginTransaction();
}
protected function _after()
{
/** @var EntityManager $em */
$em = $this->tester->grabService(EntityManager::class);
try {
while ($em->getConnection()->getTransactionNestingLevel() > 0) {
$em->getConnection()->rollback();
}
} catch (\PDOException $e) {
}
$em->clear();
$em->getConnection()->close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment