2011-11-12 22:10:00 +01:00
|
|
|
<?php
|
|
|
|
|
2013-03-27 18:44:06 +01:00
|
|
|
namespace FOS\ElasticaBundle\Tests;
|
2011-11-12 22:10:00 +01:00
|
|
|
|
2013-03-27 18:44:06 +01:00
|
|
|
use FOS\ElasticaBundle\Repository;
|
2011-11-12 22:10:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Richard Miller <info@limethinking.co.uk>
|
|
|
|
*/
|
|
|
|
class RepositoryTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testThatFindCallsFindOnFinder()
|
|
|
|
{
|
|
|
|
$testQuery = 'Test Query';
|
|
|
|
|
2015-03-12 11:20:00 +01:00
|
|
|
$finderMock = $this->getFinderMock($testQuery);
|
2011-11-12 22:10:00 +01:00
|
|
|
$repository = new Repository($finderMock);
|
|
|
|
$repository->find($testQuery);
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:25:43 +02:00
|
|
|
public function testThatFindCallsFindOnFinderWithLimit()
|
|
|
|
{
|
|
|
|
$testQuery = 'Test Query';
|
|
|
|
$testLimit = 20;
|
|
|
|
|
2015-03-12 11:20:00 +01:00
|
|
|
$finderMock = $this->getFinderMock($testQuery, $testLimit);
|
2012-08-07 20:25:43 +02:00
|
|
|
$repository = new Repository($finderMock);
|
|
|
|
$repository->find($testQuery, $testLimit);
|
|
|
|
}
|
|
|
|
|
2011-11-12 22:10:00 +01:00
|
|
|
public function testThatFindPaginatedCallsFindPaginatedOnFinder()
|
|
|
|
{
|
|
|
|
$testQuery = 'Test Query';
|
|
|
|
|
2015-03-12 11:20:00 +01:00
|
|
|
$finderMock = $this->getFinderMock($testQuery, array(), 'findPaginated');
|
2011-11-12 22:10:00 +01:00
|
|
|
$repository = new Repository($finderMock);
|
|
|
|
$repository->findPaginated($testQuery);
|
|
|
|
}
|
|
|
|
|
2013-12-11 23:52:25 +01:00
|
|
|
public function testThatCreatePaginatorCreatesAPaginatorViaFinder()
|
|
|
|
{
|
|
|
|
$testQuery = 'Test Query';
|
|
|
|
|
2015-03-12 11:20:00 +01:00
|
|
|
$finderMock = $this->getFinderMock($testQuery, array(), 'createPaginatorAdapter');
|
2013-12-11 23:52:25 +01:00
|
|
|
$repository = new Repository($finderMock);
|
|
|
|
$repository->createPaginatorAdapter($testQuery);
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:25:43 +02:00
|
|
|
public function testThatFindHybridCallsFindHybridOnFinder()
|
|
|
|
{
|
|
|
|
$testQuery = 'Test Query';
|
|
|
|
|
2015-03-12 11:20:00 +01:00
|
|
|
$finderMock = $this->getFinderMock($testQuery, null, 'findHybrid');
|
|
|
|
$repository = new Repository($finderMock);
|
|
|
|
$repository->findHybrid($testQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $testQuery
|
2015-03-13 09:34:56 +01:00
|
|
|
* @param mixed $testLimit
|
2015-03-12 11:20:00 +01:00
|
|
|
* @param string $method
|
2015-03-12 11:45:24 +01:00
|
|
|
*
|
2015-03-13 09:34:56 +01:00
|
|
|
* @return \FOS\ElasticaBundle\Finder\TransformedFinder
|
2015-03-12 11:20:00 +01:00
|
|
|
*/
|
|
|
|
private function getFinderMock($testQuery, $testLimit = null, $method = 'find')
|
|
|
|
{
|
2013-03-27 18:44:06 +01:00
|
|
|
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
2012-08-07 20:25:43 +02:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$finderMock->expects($this->once())
|
2015-03-12 11:20:00 +01:00
|
|
|
->method($method)
|
2012-08-07 20:25:43 +02:00
|
|
|
->with($this->equalTo($testQuery), $this->equalTo($testLimit));
|
|
|
|
|
2015-03-12 11:20:00 +01:00
|
|
|
return $finderMock;
|
2012-08-07 20:25:43 +02:00
|
|
|
}
|
2011-11-12 22:10:00 +01:00
|
|
|
}
|