440c36f537
Conflicts: Command/PopulateCommand.php Command/SearchCommand.php DependencyInjection/Configuration.php Doctrine/AbstractElasticaToModelTransformer.php Doctrine/AbstractListener.php Doctrine/MongoDB/ElasticaToModelTransformer.php Doctrine/ORM/ElasticaToModelTransformer.php Doctrine/RepositoryManager.php Finder/TransformedFinder.php Paginator/PaginatorAdapterInterface.php Paginator/RawPaginatorAdapter.php Persister/ObjectPersister.php Propel/ElasticaToModelTransformer.php Subscriber/PaginateElasticaQuerySubscriber.php Tests/DataCollector/ElasticaDataCollectorTest.php Tests/Doctrine/AbstractProviderTest.php Tests/Doctrine/RepositoryManagerTest.php Tests/Manager/RepositoryManagerTest.php Tests/RepositoryTest.php Transformer/ElasticaToModelTransformerCollection.php composer.json
102 lines
4 KiB
PHP
102 lines
4 KiB
PHP
<?php
|
|
|
|
namespace FOS\ElasticaBundle\Tests\Manager;
|
|
|
|
use FOS\ElasticaBundle\Manager\RepositoryManager;
|
|
|
|
class CustomRepository{}
|
|
|
|
class Entity{}
|
|
|
|
/**
|
|
* @author Richard Miller <info@limethinking.co.uk>
|
|
*/
|
|
class RepositoryManagerTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
|
|
public function testThatGetRepositoryReturnsDefaultRepository()
|
|
{
|
|
/** @var $finderMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
|
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
/** @var $readerMock \PHPUnit_Framework_MockObject_MockObject|\Doctrine\Common\Annotations\Reader */
|
|
$readerMock = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$entityName = 'FOS\ElasticaBundle\Tests\Manager\Entity';
|
|
|
|
$manager = new RepositoryManager($readerMock);
|
|
$manager->addEntity($entityName, $finderMock);
|
|
$repository = $manager->getRepository($entityName);
|
|
$this->assertInstanceOf('FOS\ElasticaBundle\Repository', $repository);
|
|
}
|
|
|
|
public function testThatGetRepositoryReturnsCustomRepository()
|
|
{
|
|
/** @var $finderMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
|
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
/** @var $readerMock \PHPUnit_Framework_MockObject_MockObject|\Doctrine\Common\Annotations\Reader */
|
|
$readerMock = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$entityName = 'FOS\ElasticaBundle\Tests\Manager\Entity';
|
|
|
|
$manager = new RepositoryManager($readerMock);
|
|
$manager->addEntity($entityName, $finderMock, 'FOS\ElasticaBundle\Tests\Manager\CustomRepository');
|
|
$repository = $manager->getRepository($entityName);
|
|
$this->assertInstanceOf('FOS\ElasticaBundle\Tests\Manager\CustomRepository', $repository);
|
|
}
|
|
|
|
/**
|
|
* @expectedException \RuntimeException
|
|
*/
|
|
public function testThatGetRepositoryThrowsExceptionIfEntityNotConfigured()
|
|
{
|
|
/** @var $finderMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
|
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
/** @var $readerMock \PHPUnit_Framework_MockObject_MockObject|\Doctrine\Common\Annotations\Reader */
|
|
$readerMock = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$entityName = 'FOS\ElasticaBundle\Tests\Manager\Entity';
|
|
|
|
$manager = new RepositoryManager($readerMock);
|
|
$manager->addEntity($entityName, $finderMock);
|
|
$manager->getRepository('Missing Entity');
|
|
}
|
|
|
|
/**
|
|
* @expectedException \RuntimeException
|
|
*/
|
|
public function testThatGetRepositoryThrowsExceptionIfCustomRepositoryNotFound()
|
|
{
|
|
/** @var $finderMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
|
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
/** @var $readerMock \PHPUnit_Framework_MockObject_MockObject|\Doctrine\Common\Annotations\Reader */
|
|
$readerMock = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$entityName = 'FOS\ElasticaBundle\Tests\Manager\Entity';
|
|
|
|
$manager = new RepositoryManager($readerMock);
|
|
$manager->addEntity($entityName, $finderMock, 'FOS\ElasticaBundle\Tests\MissingRepository');
|
|
$manager->getRepository('Missing Entity');
|
|
}
|
|
|
|
}
|