2018-09-01 13:00:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Kimai time-tracking app.
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Tests\Repository;
|
|
|
|
|
|
|
|
use App\Tests\KernelTestTrait;
|
2020-03-05 02:15:16 +01:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Doctrine\Persistence\ObjectManager;
|
2018-09-01 13:00:30 +02:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A base test class for AbstractRepository implementations.
|
|
|
|
*/
|
|
|
|
abstract class AbstractRepositoryTest extends KernelTestCase
|
|
|
|
{
|
|
|
|
use KernelTestTrait;
|
|
|
|
|
|
|
|
/**
|
2020-03-05 02:15:16 +01:00
|
|
|
* @var ObjectManager|null
|
2018-09-01 13:00:30 +02:00
|
|
|
*/
|
|
|
|
private $entityManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2019-10-24 17:35:05 +02:00
|
|
|
protected function setUp(): void
|
2018-09-01 13:00:30 +02:00
|
|
|
{
|
2022-01-23 15:49:38 +01:00
|
|
|
parent::setUp();
|
2018-09-01 13:00:30 +02:00
|
|
|
$kernel = self::bootKernel();
|
|
|
|
|
|
|
|
$this->entityManager = $kernel->getContainer()
|
|
|
|
->get('doctrine')
|
|
|
|
->getManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-05 02:15:16 +01:00
|
|
|
* @return ObjectManager
|
2018-09-01 13:00:30 +02:00
|
|
|
*/
|
|
|
|
protected function getEntityManager()
|
|
|
|
{
|
|
|
|
return $this->entityManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2019-10-24 17:35:05 +02:00
|
|
|
protected function tearDown(): void
|
2018-09-01 13:00:30 +02:00
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
|
2020-03-05 02:15:16 +01:00
|
|
|
if ($this->entityManager instanceof EntityManagerInterface) {
|
|
|
|
$this->entityManager->close();
|
|
|
|
}
|
2018-09-01 13:00:30 +02:00
|
|
|
$this->entityManager = null; // avoid memory leaks
|
|
|
|
}
|
|
|
|
}
|