Last active
December 19, 2015 11:49
-
-
Save norberttech/5950303 to your computer and use it in GitHub Desktop.
How to write specs for Symfony2 bundle extension.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\DemoBundle\DependencyInjection; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | |
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | |
use Symfony\Component\Config\FileLocator; | |
class AcmeDemoExtension extends Extension | |
{ | |
public function load(array $configs, ContainerBuilder $container) | |
{ | |
$container->setParameter('acme.test.parameter', 'test'); | |
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | |
$loader->load('services.xml'); | |
} | |
public function getAlias() | |
{ | |
return 'acme_demo'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace spec\Acme\DemoBundle\DependencyInjection; | |
use PhpSpec\ObjectBehavior; | |
use Prophecy\Argument; | |
class AcmeDemoExtensionSpec extends ObjectBehavior | |
{ | |
function it_is_initializable() | |
{ | |
$this->shouldHaveType('Acme\DemoBundle\DependencyInjection\AcmeDemoExtension'); | |
} | |
function it_should_set_acme_test_parameter_at_container_builder($builder) | |
{ | |
$builder->beADoubleOf('Symfony\Component\DependencyInjection\ContainerBuilder'); | |
$builder->hasExtension(Argument::type('string'))->willReturn(false); | |
$builder->addResource(Argument::type('\Symfony\Component\Config\Resource\FileResource'))->shouldBeCalled(); | |
$builder->setDefinition(Argument::type('string'), Argument::type('Symfony\Component\DependencyInjection\Definition'))->shouldBeCalled(); | |
$builder->setParameter('acme.test.parameter', 'test')->shouldBeCalled()->willReturn($builder); | |
$this->load(array(), $builder); | |
} | |
function it_should_have_acme_demo_alias() | |
{ | |
$this->getAlias()->shouldReturn('acme_demo'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment