open-orchestra/open-orchestra-media-admin-bundle

View on GitHub
MediaAdminBundle/Tests/DependencyInjection/Compiler/FieldToElasticaTypeCompilerPassTest.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace OpenOrchestra\MediaAdminBundle\Tests\DependencyInjection\Compiler;

use OpenOrchestra\MediaAdminBundle\DependencyInjection\Compiler\FieldToElasticaTypeCompilerPass;
use Phake;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

/**
 * Test FieldToElasticaTypeCompilerPassTest
 */
class FieldToElasticaTypeCompilerPassTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var FieldToElasticaTypeCompilerPass
     */
    protected $compiler;

    protected $containerBuilder;

    /**
     * Set up the test
     */
    public function setUp()
    {
        $this->containerBuilder = Phake::mock(ContainerBuilder::CLASS);

        $this->compiler = new FieldToElasticaTypeCompilerPass();
    }

    /**
     * Test instance
     */
    public function testInstance()
    {
        $this->assertInstanceOf(CompilerPassInterface::CLASS, $this->compiler);
    }

    /**
     * Test with no mapper
     */
    public function testProcessWithNoMapper()
    {
        $this->compiler->process($this->containerBuilder);

        Phake::verify($this->containerBuilder)->has('open_orchestra_elastica_admin.mapper.form');
    }

    /**
     * Test with mapper present
     */
    public function testProcessWithMapper()
    {
        $definition = Phake::mock(Definition::CLASS);
        Phake::when($this->containerBuilder)->getDefinition(Phake::anyParameters())->thenReturn($definition);
        Phake::when($this->containerBuilder)->has(Phake::anyParameters())->thenReturn(true);

        $this->compiler->process($this->containerBuilder);

        Phake::verify($definition)->addMethodCall('addMappingConfiguration', array('orchestra_media', 'object'));
    }
}