Optimized repository tests

This commit is contained in:
Kevin Frantz 2019-01-16 20:55:49 +01:00
parent 3ca5f3dc36
commit 665f0044cc
3 changed files with 52 additions and 2 deletions

View File

@ -1,6 +1,6 @@
<?php
namespace tests\Unit\Repository;
namespace tests\Unit\Repository\Meta;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Doctrine\ORM\EntityRepository;

View File

@ -0,0 +1,50 @@
<?php
namespace tests\Unit\Repository\Source;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use App\Repository\Source\SourceRepositoryInterface;
use App\Entity\Source\AbstractSource;
use App\Domain\RequestManagement\RequestedSourceInterface;
use App\DBAL\Types\SystemSlugType;
use App\Entity\Source\SourceInterface;
/**
* @author kevinfrantz
*/
class SourceRepositoryTest extends KernelTestCase
{
/**
* @var SourceRepositoryInterface
*/
protected $sourceRepository;
public function setUp(): void
{
$kernel = self::bootKernel();
$entityManager = $kernel->getContainer()
->get('doctrine')
->getManager();
$this->sourceRepository = $entityManager->getRepository(AbstractSource::class);
}
public function testLoadBySlugOrId(): void
{
$requestedSource = $this->createMock(RequestedSourceInterface::class);
$requestedSource->method('hasSlug')->willReturn(true);
$requestedSource->method('getSlug')->willReturn(SystemSlugType::IMPRINT);
$imprint = $this->sourceRepository->findOneByIdOrSlug($requestedSource);
$this->assertInstanceOf(SourceInterface::class, $imprint);
$requestedSource2 = $this->createMock(RequestedSourceInterface::class);
$requestedSource2->method('hasId')->willReturn(true);
$requestedSource2->method('getId')->willReturn($imprint->getId());
$imprint2 = $this->sourceRepository->findOneByIdOrSlug($requestedSource2);
$this->assertInstanceOf(SourceInterface::class, $imprint2);
}
public function testLoadBySlug(): void
{
$imprint = $this->sourceRepository->findOneBySlug(SystemSlugType::IMPRINT);
$this->assertInstanceOf(SourceInterface::class, $imprint);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace tests\Unit\Repository;
namespace tests\Unit\Repository\Source;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Doctrine\ORM\EntityManager;