Improve test coverage
This commit is contained in:
parent
6c4740b292
commit
090f02b05d
|
@ -147,6 +147,6 @@ class ElasticaLogger implements LoggerInterface
|
|||
*/
|
||||
public function log($level, $message, array $context = array())
|
||||
{
|
||||
return $this->logger->log($message, $context);
|
||||
return $this->logger->log($level, $message, $context);
|
||||
}
|
||||
}
|
||||
|
|
42
Tests/ClientTest.php
Normal file
42
Tests/ClientTest.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace FOS\ElasticaBundle\Tests\Resetter;
|
||||
|
||||
use Elastica\Request;
|
||||
use Elastica\Transport\Null as NullTransport;
|
||||
|
||||
class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testRequestsAreLogged()
|
||||
{
|
||||
$transport = new NullTransport;
|
||||
|
||||
$connection = $this->getMock('Elastica\Connection');
|
||||
$connection->expects($this->any())->method('getTransportObject')->will($this->returnValue($transport));
|
||||
$connection->expects($this->any())->method('toArray')->will($this->returnValue(array()));
|
||||
|
||||
$logger = $this->getMock('FOS\ElasticaBundle\Logger\ElasticaLogger');
|
||||
$logger
|
||||
->expects($this->once())
|
||||
->method('logQuery')
|
||||
->with(
|
||||
'foo',
|
||||
Request::GET,
|
||||
$this->isType('array'),
|
||||
$this->isType('float'),
|
||||
$this->isType('array')
|
||||
);
|
||||
|
||||
$client = $this->getMockBuilder('FOS\ElasticaBundle\Client')
|
||||
->setMethods(array('getConnection'))
|
||||
->getMock();
|
||||
|
||||
$client->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
|
||||
|
||||
$client->setLogger($logger);
|
||||
|
||||
$response = $client->request('foo');
|
||||
|
||||
$this->assertInstanceOf('Elastica\Response', $response);
|
||||
}
|
||||
}
|
39
Tests/FOSElasticaBundleTest.php
Normal file
39
Tests/FOSElasticaBundleTest.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace FOS\ElasticaBundle\Tests\Resetter;
|
||||
|
||||
use FOS\ElasticaBundle\FOSElasticaBundle;
|
||||
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
||||
|
||||
class FOSElasticaBundleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCompilerPassesAreRegistered()
|
||||
{
|
||||
$passes = array(
|
||||
array (
|
||||
'FOS\ElasticaBundle\DependencyInjection\Compiler\RegisterProvidersPass',
|
||||
PassConfig::TYPE_BEFORE_REMOVING
|
||||
),
|
||||
array (
|
||||
'FOS\ElasticaBundle\DependencyInjection\Compiler\TransformerPass'
|
||||
),
|
||||
);
|
||||
|
||||
$container = $this
|
||||
->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
|
||||
|
||||
$container
|
||||
->expects($this->at(0))
|
||||
->method('addCompilerPass')
|
||||
->with($this->isInstanceOf($passes[0][0]), $passes[0][1]);
|
||||
|
||||
$container
|
||||
->expects($this->at(1))
|
||||
->method('addCompilerPass')
|
||||
->with($this->isInstanceOf($passes[1][0]));
|
||||
|
||||
$bundle = new FOSElasticaBundle();
|
||||
|
||||
$bundle->build($container);
|
||||
}
|
||||
}
|
19
Tests/HybridResultTest.php
Normal file
19
Tests/HybridResultTest.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace FOS\ElasticaBundle\Tests\Resetter;
|
||||
|
||||
use Elastica\Result;
|
||||
use FOS\ElasticaBundle\HybridResult;
|
||||
|
||||
class HybridResultTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testTransformedResultDefaultsToNull()
|
||||
{
|
||||
$result = new Result(array());
|
||||
|
||||
$hybridResult = new HybridResult($result);
|
||||
|
||||
$this->assertSame($result, $hybridResult->getResult());
|
||||
$this->assertNull($hybridResult->getTransformed());
|
||||
}
|
||||
}
|
|
@ -9,6 +9,40 @@ use FOS\ElasticaBundle\Logger\ElasticaLogger;
|
|||
*/
|
||||
class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\HttpKernel\Log\LoggerInterface
|
||||
*/
|
||||
private function getMockLogger()
|
||||
{
|
||||
return $this->getMockBuilder('Symfony\Component\HttpKernel\Log\LoggerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $level
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return ElasticaLogger
|
||||
*/
|
||||
private function getMockLoggerForLevelMessageAndContext($level, $message, $context)
|
||||
{
|
||||
$loggerMock = $this->getMockBuilder('Symfony\Component\HttpKernel\Log\LoggerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$loggerMock->expects($this->once())
|
||||
->method($level)
|
||||
->with(
|
||||
$this->equalTo($message),
|
||||
$this->equalTo($context)
|
||||
);
|
||||
|
||||
$elasticaLogger = new ElasticaLogger($loggerMock);
|
||||
|
||||
return $elasticaLogger;
|
||||
}
|
||||
|
||||
public function testGetZeroIfNoQueriesAdded()
|
||||
{
|
||||
$elasticaLogger = new ElasticaLogger;
|
||||
|
@ -64,10 +98,7 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testQueryIsLogged()
|
||||
{
|
||||
/** @var $loggerMock \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\HttpKernel\Log\LoggerInterface */
|
||||
$loggerMock = $this->getMockBuilder('Symfony\Component\HttpKernel\Log\LoggerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$loggerMock = $this->getMockLogger();
|
||||
|
||||
$elasticaLogger = new ElasticaLogger($loggerMock);
|
||||
|
||||
|
@ -87,4 +118,55 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$elasticaLogger->logQuery($path, $method, $data, $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function logLevels()
|
||||
{
|
||||
return array(
|
||||
array('emergency'),
|
||||
array('alert'),
|
||||
array('critical'),
|
||||
array('error'),
|
||||
array('warning'),
|
||||
array('notice'),
|
||||
array('info'),
|
||||
array('debug'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider logLevels
|
||||
*/
|
||||
public function testMessagesCanBeLoggedAtSpecificLogLevels($level)
|
||||
{
|
||||
$message = 'foo';
|
||||
$context = array('data');
|
||||
|
||||
$loggerMock = $this->getMockLoggerForLevelMessageAndContext($level, $message, $context);
|
||||
|
||||
call_user_func(array($loggerMock, $level), $message, $context);
|
||||
}
|
||||
|
||||
public function testMessagesCanBeLoggedToArbitraryLevels()
|
||||
{
|
||||
$loggerMock = $this->getMockLogger();
|
||||
|
||||
$level = 'info';
|
||||
$message = 'foo';
|
||||
$context = array('data');
|
||||
|
||||
$loggerMock->expects($this->once())
|
||||
->method('log')
|
||||
->with(
|
||||
$level,
|
||||
$message,
|
||||
$context
|
||||
);
|
||||
|
||||
$elasticaLogger = new ElasticaLogger($loggerMock);
|
||||
|
||||
$elasticaLogger->log($level, $message, $context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,22 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
|||
$repository->findPaginated($testQuery);
|
||||
}
|
||||
|
||||
public function testThatCreatePaginatorCreatesAPaginatorViaFinder()
|
||||
{
|
||||
$testQuery = 'Test Query';
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$finderMock->expects($this->once())
|
||||
->method('createPaginatorAdapter')
|
||||
->with($this->equalTo($testQuery));
|
||||
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->createPaginatorAdapter($testQuery);
|
||||
}
|
||||
|
||||
public function testThatFindHybridCallsFindHybridOnFinder()
|
||||
{
|
||||
$testQuery = 'Test Query';
|
||||
|
|
Loading…
Reference in a new issue