FOSElasticaBundle/Tests/PopulatorTest.php

61 lines
2 KiB
PHP
Raw Normal View History

2011-07-07 22:41:46 +02:00
<?php
namespace FOQ\ElasticaBundle\Tests\Populator;
use FOQ\ElasticaBundle\Populator;
use FOQ\ElasticaBundle\Provider\ProviderInterface;
use Closure;
class PopulatorMock extends Populator
{
public $providers = array();
}
class PopulatorTest extends \PHPUnit_Framework_TestCase
{
2011-07-07 22:58:43 +02:00
public function testThatWeCanAddProvider()
{
$provider = $this->getMock('FOQ\ElasticaBundle\Provider\ProviderInterface', array('populate'));
$populator = new PopulatorMock(array());
$populator->addProvider('l3l0Provider', $provider);
2011-07-07 22:41:46 +02:00
2011-07-07 22:58:43 +02:00
$this->assertEquals(count($populator->providers), 1);
$this->assertArrayHasKey('l3l0Provider', $populator->providers);
$this->assertInstanceOf('FOQ\ElasticaBundle\Provider\ProviderInterface', $populator->providers['l3l0Provider']);
}
public function testThatPopulateThroughProviders()
{
$provider = $this->getMock('FOQ\ElasticaBundle\Provider\ProviderInterface', array('populate'));
$provider->expects($this->once())
->method('populate');
$provider2 = $this->getMock('FOQ\ElasticaBundle\Provider\ProviderInterface', array('populate'));
$provider2->expects($this->once())
->method('populate');
2011-07-07 22:58:43 +02:00
$populator = new Populator(array('l3l0Provider' => $provider, 'secondProvider' => $provider2));
$populator->populate(function ($text) { return $text; });
}
/**
* @expectedException PHPUnit_Framework_Error
*/
public function testThatAddProviderHaveToImpelementProviderInterface()
{
$populator = new Populator(array());
$populator->addProvider('provider', new \stdClass());
$populator->populate(function ($text) { return $text; });
}
/**
* @expectedException PHPUnit_Framework_Error
*/
public function testThatProvidersPassToTheContructorHaveToImplementProviderInterface()
{
$populator = new Populator(array('provider' => new \stdClass()));
2011-07-07 22:58:43 +02:00
$populator->populate(function ($text) { return $text; });
}
2011-07-07 22:41:46 +02:00
}