Giter Club home page Giter Club logo

symfonydependencyinjectiontest's Introduction

SymfonyDependencyInjectionTest

By Matthias Noback and contributors

Build Status

This library contains several PHPUnit test case classes and many semantic assertions which you can use to functionally test your container extensions (or "bundle extensions") and compiler passes. It also provides the tools to functionally test your container extension (or "bundle") configuration by verifying processed values from different types of configuration files.

Besides verifying their correctness, this library will also help you to adopt a TDD approach when developing these classes.

Installation

Using Composer:

composer require --dev matthiasnoback/symfony-dependency-injection-test

Usage

Testing a container extension

To test your own container extension class MyExtension create a class and extend from Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase. Then implement the getContainerExtensions() method:

<?php

use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;

class MyExtensionTest extends AbstractExtensionTestCase
{
    protected function getContainerExtensions(): array
    {
        return [
            new MyExtension()
        ];
    }
}

Basically you will be testing your extension's load method, which will look something like this:

<?php

class MyExtension extends Extension
{
    public function load(array $config, ContainerBuilder $container)
    {
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__));
        $loader->load('services.xml');

        // maybe process the configuration values in $config, then:

        $container->setParameter('parameter_name', 'some value');
    }
}

So in the test case you should test that after loading the container, the parameter has been set correctly:

<?php

class MyExtensionTest extends AbstractExtensionTestCase
{
    /**
     * @test
     */
    public function after_loading_the_correct_parameter_has_been_set()
    {
        $this->load();

        $this->assertContainerBuilderHasParameter('parameter_name', 'some value');
    }
}

To test the effect of different configuration values, use the first argument of load():

<?php

class MyExtensionTest extends AbstractExtensionTestCase
{
    /**
     * @test
     */
    public function after_loading_the_correct_parameter_has_been_set()
    {
        $this->load(['my' => ['enabled' => 'false']);

        ...
    }
}

To prevent duplication of required configuration values, you can provide some minimal configuration, by overriding the getMinimalConfiguration() method of the test case.

Testing a compiler pass

To test a compiler pass, create a test class and extend from Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase. Then implement the registerCompilerPass() method:

<?php

use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;

class MyCompilerPassTest extends AbstractCompilerPassTestCase
{
    protected function registerCompilerPass(ContainerBuilder $container): void
    {
        $container->addCompilerPass(new MyCompilerPass());
    }
}

In each test you can first set up the ContainerBuilder instance properly, depending on what your compiler pass is expected to do. For instance you can add some definitions with specific tags you will collect. Then after the "arrange" phase of your test, you need to "act", by calling the compile()method. Finally you may enter the "assert" stage and you should verify the correct behavior of the compiler pass by making assertions about the ContainerBuilder instance.

<?php

class MyCompilerPassTest extends AbstractCompilerPassTestCase
{
    /**
     * @test
     */
    public function if_compiler_pass_collects_services_by_adding_method_calls_these_will_exist()
    {
        $collectingService = new Definition();
        $this->setDefinition('collecting_service_id', $collectingService);

        $collectedService = new Definition();
        $collectedService->addTag('collect_with_method_calls');
        $this->setDefinition('collected_service', $collectedService);

        $this->compile();

        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
            'collecting_service_id',
            'add',
            [
                new Reference('collected_service')
            ]
        );
    }
}

Standard test for unobtrusiveness

The AbstractCompilerPassTestCase class always executes one specific test - compilation_should_not_fail_with_empty_container() - which makes sure that the compiler pass is unobtrusive. For example, when your compiler pass assumes the existence of a service, an exception will be thrown, and this test will fail:

<?php

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class MyCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        $definition = $container->getDefinition('some_service_id');

        ...
    }
}

So you need to always add one or more guard clauses inside the process() method:

<?php

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class MyCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('some_service_id')) {
            return;
        }

        $definition = $container->getDefinition('some_service_id');

        ...
    }
}

Use findDefinition() instead of getDefinition()

You may not know in advance if a service id stands for a service definition, or for an alias. So instead of hasDefinition() and getDefinition() you may consider using has() and findDefinition(). These methods recognize both aliases and definitions.

Test different configuration file formats

The Symfony DependencyInjection component supports many different types of configuration loaders: Yaml, XML, and PHP files, but also closures. When you create a Configuration class for your bundle, you need to make sure that each of these formats is supported. Special attention needs to be given to XML files.

In order to verify that any type of configuration file will be correctly loaded by your bundle, you must install the SymfonyConfigTest library and create a test class that extends from AbstractExtensionConfigurationTestCase:

<?php

use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionConfigurationTestCase;

class ConfigurationTest extends AbstractExtensionConfigurationTestCase
{
    protected function getContainerExtension()
    {
        return new TwigExtension();
    }

    protected function getConfiguration()
    {
        return new Configuration();
    }
}

Now inside each test method you can use the assertProcessedConfigurationEquals($expectedConfiguration, $sources) method to verify that after loading the given sources the processed configuration equals the expected array of values:

# in Fixtures/config.yml
twig:
    extensions: ['twig.extension.foo']
<!-- in Fixtures/config.xml -->
<container>
    <twig:config>
        <twig:extension>twig.extension.bar</twig:extension>
    </twig:config>
</container>
<?php
...

class ConfigurationTest extends AbstractExtensionConfigurationTestCase
{
    ...

    /**
     * @test
     */
    public function it_converts_extension_elements_to_extensions()
    {
        $expectedConfiguration = [
            'extensions' => ['twig.extension.foo', 'twig.extension.bar']
        ];

        $sources = [
            __DIR__ . '/Fixtures/config.yml',
            __DIR__ . '/Fixtures/config.xml',
        ];

        $this->assertProcessedConfigurationEquals($expectedConfiguration, $sources);
    }
}

List of assertions

These are the available semantic assertions for each of the test cases shown above:

assertContainerBuilderHasService($serviceId)
Assert that the ContainerBuilder for this test has a service definition with the given id.
assertContainerBuilderHasService($serviceId, $expectedClass)
Assert that the ContainerBuilder for this test has a service definition with the given id and class.
assertContainerBuilderNotHasService($serviceId)
Assert that the ContainerBuilder for this test does not have a service definition with the given id.
assertContainerBuilderHasSyntheticService($serviceId)
Assert that the ContainerBuilder for this test has a synthetic service with the given id.
assertContainerBuilderHasAlias($aliasId)
Assert that the ContainerBuilder for this test has an alias.
assertContainerBuilderHasAlias($aliasId, $expectedServiceId)
Assert that the ContainerBuilder for this test has an alias and that it is an alias for the given service id.
assertContainerBuilderHasParameter($parameterName)
Assert that the ContainerBuilder for this test has a parameter.
assertContainerBuilderHasParameter($parameterName, $expectedParameterValue)
Assert that the ContainerBuilder for this test has a parameter and that its value is the given value.
assertContainerBuilderHasExactParameter($parameterName)
Assert that the ContainerBuilder for this test has a parameter.
assertContainerBuilderHasExactParameter($parameterName, $expectedParameterValue)
Assert that the ContainerBuilder for this test has a parameter and that its value is the given value, as well as its type matches given value type.
assertContainerBuilderHasServiceDefinitionWithArgument($serviceId, $argumentIndex)
Assert that the ContainerBuilder for this test has a service definition with the given id, which has an argument at the given index.
assertContainerBuilderHasServiceDefinitionWithArgument($serviceId, $argumentIndex, $expectedValue)
Assert that the ContainerBuilder for this test has a service definition with the given id, which has an argument at the given index, and its value is the given value.
assertContainerBuilderHasServiceDefinitionWithServiceLocatorArgument($serviceId, $argumentIndex, $expectedValue)
Assert that the ContainerBuilder for this test has a service definition with the given id, which has an argument at the given index, and its value is a ServiceLocator with a reference-map equal to the given value.
assertContainerBuilderHasServiceDefinitionWithMethodCall($serviceId, $method, array $arguments = [], $index = null)
Assert that the ContainerBuilder for this test has a service definition with the given id, which has a method call to the given method with the given arguments. If index is provided, invocation index order of method call is asserted as well.
assertContainerBuilderHasServiceDefinitionWithTag($serviceId, $tag, array $attributes = [])
Assert that the ContainerBuilder for this test has a service definition with the given id, which has the given tag with the given arguments.
assertContainerBuilderHasServiceDefinitionWithParent($serviceId, $parentServiceId)
Assert that the ContainerBuilder for this test has a service definition with the given id which is a decorated service and it has the given parent service.
assertContainerBuilderHasServiceLocator($serviceId, $expectedServiceMap)
Assert that the ContainerBuilder for this test has a ServiceLocator service definition with the given id.

Available methods to set up container

In all test cases shown above, you have access to some methods to set up the container:

setDefinition($serviceId, $definition)
Set a definition. The second parameter is a Definition class
registerService($serviceId, $class)
A shortcut for setDefinition. It returns a Definition object that can be modified if necessary.
setParameter($parameterId, $parameterValue)
Set a parameter.

Version Guidance

Version Released PHPUnit Status
5.x Jan 23, 2024 9.x, 10.x Latest
4.x Mar 28, 2019 8.x and 9.x Bugfixes
3.x Mar 5, 2018 7.x Bugfixes
2.x May 9, 2017 6.x Bugfixes
1.x Jul 4, 2016 4.x and 5.x EOL

symfonydependencyinjectiontest's People

Contributors

alexander-schranz avatar andrew-demb avatar chris53897 avatar cordoval avatar emodric avatar greg0ire avatar h4cc avatar jdreesen avatar kbond avatar loevgaard avatar matthiasnoback avatar mbabker avatar mhujer avatar mwadon avatar norkunas avatar nyholm avatar pamil avatar rejinka avatar rolfdenhartog avatar silvioq avatar soullivaneuh avatar sstok avatar stloyd avatar thecelavi avatar uwej711 avatar vudaltsov avatar wickedone avatar wouterj avatar xabbuh avatar zales0123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

symfonydependencyinjectiontest's Issues

ContainerBuilderTestCase needs to be abstract

In some situations the PHPStorm test runner (and probably others as well) will run ContainerBuilderTestCase as a regulare test class and show a warning that it contains no tests. It should of course be marked as abstract.

Negated assertions

I need to test that a certain service is not there but there is no assertContainerBuilderHasNotService ...

Definition could not be converted to string

ContainerBuilderHasServiceDefinitionConstraint::toString() threads expectedClass as a string value while an its object.

evaluateClass uses \PHPUnit_Util_Type::export() but I'm not sure this should also be used for toString().

PHPUnit 5 compatibility

There are currently some issues regarding compatibility with PHPUnit 5 which is quite important as PHPUnit 4 is not fully compatible with PHP 7.

@matthiasnoback Just to keep track of this issue. :)

Configuration get appended when using numeric keys and multiple sources

When testing multiple configuration formats, the assertion is not executed seperetly for each source. Instead of that, all sources are parsed and after that the assertion is executed.

This will work for most of the configuration things, as they almost always have an unique key. When merging those arrays, nothing changes:

$one = array('foo' => 'cat');
$two = array('foo' => 'cat');

var_dump(array_merge($one, $two)); //> Array( [foo] => 'cat' )

But if you use a prototype without key, for instance:

$root
    ->fixXmlConfig('locale')
    ->children()
        ->arrayNode('locales')
            ->prototype('scalar')->end()
        ->end() // locales
    ->end();

Now, when using multiple sources, you get a numeric key. When merging these arrays, the items will be appended instead of replaced:

$one = array('cat');
$two = array('cat');

var_dump(array_merge($one, $two)); //> Array( [0] => 'cat', [1] => 'cat' )

This causes the test to fail.

DefinitionHasArgumentConstraint does not work well with DefinitionDecorator

When the DefinitionHasArgumentConstraint is used to validate the existence and correctness of a definition argument, this does not work well with a service definition which is an instance of DefinitionDecorator. Instead of directly accessing the argument array, the constraint should try to call getArgument() on it, otherwise it will always fail.

Proper access of the kernel.bundles parameter

I am trying to integrate your package under SonataAdminBundle: sonata-project/SonataAdminBundle#3932

Our SonataAdminExtension currently need the kernel.bundles parameter: https://github.com/sonata-project/SonataAdminBundle/blob/3.2.0/DependencyInjection/SonataAdminExtension.php#L37

But we got this error:

1) Sonata\AdminBundle\Tests\SonataAdminExtensionTest::testLoad
Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException: You have requested a non-existent parameter "kernel.bundles".

/home/sullivan/projects/fork/sonata-project/SonataAdminBundle/vendor/symfony/dependency-injection/ParameterBag/ParameterBag.php:84
/home/sullivan/projects/fork/sonata-project/SonataAdminBundle/vendor/symfony/dependency-injection/Container.php:127
/home/sullivan/projects/fork/sonata-project/SonataAdminBundle/DependencyInjection/SonataAdminExtension.php:220
/home/sullivan/projects/fork/sonata-project/SonataAdminBundle/vendor/symfony/dependency-injection/Compiler/MergeExtensionConfigurationPass.php:36
/home/sullivan/projects/fork/sonata-project/SonataAdminBundle/vendor/symfony/dependency-injection/Compiler/Compiler.php:104
/home/sullivan/projects/fork/sonata-project/SonataAdminBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:545
/home/sullivan/projects/fork/sonata-project/SonataAdminBundle/Tests/DependencyInjection/SonataAdminExtensionTest.php:24

What is the best way to get/simulate this parameter this your package? Can this be possible?

Optional parameters for assertContainerBuilderHas*

If i just want to check, if the ContainerBuilder has a service, but i dont want/need to check against the concrete value, it would be great to change some the signatures like this:

assertContainerBuilderHasService($serviceId, $expectedClass=null)
assertContainerBuilderHasAlias($aliasId, $expectedServiceId=null)
assertContainerBuilderHasParameter($parameterName, $expectedParameterValue=null)
assertContainerBuilderHasServiceDefinitionWithArgument($serviceId, $argumentIndex, $expectedValue=null)

For me it was a little bit confusing at first, because the "has" inside the name did not get me to the "equals" check that will be made.

Add phpunit as a non-dev depedency.

Since this package itself will be installed as a --dev dependency I think it makes sense to require phpunit in the main require list, ensuring it's usable when installed.

I'll happily PR this when/if agreed to this proposal.

Lots of composer deprecation warnings about PSR-4 compliance

I am getting a lot of warnings when installing/updating the package, saying something like: Class (name) does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0.

Example of affected classes:

  • Matthias\SymfonyDependencyInjectionTest\Tests\PhpUnit\DependencyInjection\DefinitionHasTagConstraintTest
  • Matthias\SymfonyConfigTest\Tests\PartialConfigurationIntegrationTest

As you can see it also affects your other SymfonyConfigTest package.

PHPUnit 6 compatibility

If you bump requirement for phpunit to ^5.7|^6.0, you can use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase (in 5.7 there is a forward-compatible layer).
Of course, this means dropping support for phpunit 4 (that is out of support, by the way)

Incompatibility with phpunit 8

using matthiasnoback/symfony-dependency-injection-test v3.1.0

PHP Fatal error:  Declaration of Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractContainerBuilderTestCase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in [...]/vendor/matthiasnoback/symfony-dependency-injection-test/PhpUnit/AbstractContainerBuilderTestCase.php on line 221

Does not support import of other file type

Due to a lack of a Resolver, its impossible to test configurations that import other types of configs, for example a yml file with:

imports:                            
    - { resource: constants.xml }   

Any ideas on how to achieve this?

Not working at all with global PHPUnit

If we run tests based on your library with a global phpunit binary, it fails. But it works with phpunit as a project dependency.

See more details here: sonata-project/SonataAdminSearchBundle#16 (comment)

And the related test case: https://github.com/sonata-project/SonataAdminSearchBundle/blob/72b0a5c5202ae8da33b5c1ea7936afde8e117e1d/Tests/DependencyInjection/Compiler/DatagridBuilderInjectionCompilerPassTest.php

We can't figure out why.

Maybe do you have an explanation?

Thanks.

puzzled on a sf2.5 project

Matthias\SymfonyServiceDefinitionValidator\Exception\InvalidServiceDefinitionsException]
Service definition validation errors (2):

  • form.type_guesser.validator: Argument for type-hint "Symfony\Component\Validator\MetadataFactor
    yInterface" points to a service of class "Symfony\Component\Validator\ValidatorInterface"
  • validator: Class "Symfony\Component\Validator\ValidatorBuilderInterface" does not exist

failed to load vendor/autoload.php

I just started reading the laravel 5.6 docs and php is not my forte I am still learning so try to use a lot of sample projects to learn but I cant seem to get the server up found a solution but unfortunately works on
an older version of php ^5.5.0 they said to use composer install and composer update but fix doesnt work for php 7 am using 7.2.6

[RFC] make ContainerBuilderHasAliasConstraint case-insensitive

When writing tests for a legacy application, I discovered that the checks performed in the ContainerBuilderHasAliasConstraint are not case-insensitive.

For example, take the following service definition and alias:

services:
   fooBar:
     class: \Foobar
   foo:
     alias: fooBar

Notice the capitalised B in the service id for the fooBar service definition. However, when using the assertContainerBuilderHasAlias(), you will have to lowercase the service id. The reason is that the Symfony DependencyInjection component lowercases all service ids and aliases.

I suggest to reflect this behaviour in the ContainerBuilderHasAliasConstraint and would be happy to open a pull request for this. Though I first wanted to ask for your opinion on this.

@matthiasnoback What do you think?

error after installing version 2.0

screenshot 2017-03-07 12 26 31

my tests are failing, I am wondering, why I can install version >=2.0, if i have PHPUnit 5.7.15 installed:

oskar.stark:/Volumes/development/workspaces/dashy (show-navi)$ composer show | grep phpunit/phpunit
phpunit/phpunit                                  5.7.15  The PHP Unit Testing framework.
oskar.stark:/Volumes/development/workspaces/dashy (show-navi)$ composer show | grep matthias
matthiasnoback/symfony-config-test               v3.0.1  Library for testing user classes related to the Symfony Config Component
matthiasnoback/symfony-dependency-injection-test v2.0.0  Library for testing user classes related to the Symfony Dependency Injection Component

IMO >=2.0 should have PHPUnit <=6.0 in the conflict section

[FEATURE]: assertContainerBuilderHasServiceDefinitionWithMethodCall - unable to test implementation of chain of responsibility

Considering that there is a service of type of "Registry", which gets injected with services of types of "Handler" via method call "addHendler" -> if order of injection of each individual handler via method call is significant, we are not able to test it.

Proposal: extend method signature of assertContainerBuilderHasServiceDefinitionWithMethodCall() to:

protected function assertContainerBuilderHasServiceDefinitionWithMethodCall(
    $serviceId,
    $method,
    array $arguments = array(),
    $index = null // Zero-based order of invocation of method call
)

This implementation will be BC compatible, if $index is provided, assert should check if method call has appropriate order in collection of registered method calls.

Application is useful, of course, when testing implementation of chain of responsibility pattern and/or visitor pattern where order of injection is prioritized.

I am willing to submit a patch, if you agree that this is a valid request for improvement.

Assert container does not have a method call

This is a feature request. Thank you for this library which is very useful!

Would it be possible to add a method that asserts that a service id does not have a certain method call?

assertContainerBuilderHasResource

Hey @matthiasnoback & other GitHubbers,
writing some tests last night I was thinking about testing dependency injection extensions and all the assertContainerBuilderHasService, assertContainerBuilderHasParameter etc assertations only make sense if they were actually added by the extension and not loaded via a yml/xml file. If my load method only loads a yml/xml file the only assertation that makes sense to me is that I check if that file was added as a file resource (and therefore loaded). So I was wondering if you think it makes sense to add a assertContainerBuilderHasResource assertion? For example
$this->assertContainerBuilderHasResource('src/AppBundle/Resources/config/services.xml');

Add support for testing if a extension still allows the container to be dumped

Hi,

So a while back I ran into a problem being that the extension that I was testing created a container instance that couldn't be dumped (but passed all tests).

To fix this I added the following assert to my TestCase:

use Symfony\Component\DependencyInjection\Dumper;

class TestCase {
....
    /**
     * Assert that the current container can be dumped.
     */
    private function assertContainerCanBeDumped()
    {
        $dumperCalls = array(
            Dumper\XmlDumper::class,
            Dumper\PhpDumper::class,
            Dumper\GraphvizDumper::class,
            Dumper\YamlDumper::class,
        );
        foreach ($dumperCalls as $dumperClass) {
            /** @var Dumper\Dumper $dumper */
            $dumper = new $dumperClass($this->container);
            $this->assertInstanceOf(Dumper\Dumper::class, $dumper);
            $dumper->dump();
        }
    }
....
}

Would this be worth creating a PR?

Next release

Could you please create next release to make last changes available for install? For example, I need the PrependExtensionInterface::prepend() method invocation, and it is not available.

Deprecated method

Would be great to take care of this:

Symfony\Component\DependencyInjection\Definition::setFactoryMethod method is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead

Thanks again for your library!

Expected/actual should be swapped for ContainerBuilderHasParameterConstraint

...
There was 1 failure:

1) Symfony\Cmf\Bundle\RoutingBundle\Tests\Unit\DependencyInjection\CmfRoutingExtensionTest::testRouteBasepathsMerging with data set #2 (null, array('/cms/test'), array('/cms/routes', '/cms/test'), '/cms/routes')
The value of parameter "cmf_routing.dynamic.persistence.phpcr.route_basepaths" (Array &0 (
    0 => '/cms/routes'
    1 => '/cms/test'
)) does not match the expected value (Array &0 (
    0 => '/cms/test'
))
Failed asserting that Symfony\Component\DependencyInjection\ContainerBuilder Object &000000004ae804bd0000000034c3290d (
    ...
    'parameterBag' => Symfony\Component\DependencyInjection\ParameterBag\ParameterBag Object &000000004ae8069d0000000034
c3290d (
        'parameters' => Array &5 (
            ...
            'cmf_routing.dynamic.persistence.phpcr.route_basepaths' => Array &11 (
                0 => '/cms/test'
            )
            ...
    )
    ...
) has a parameter "cmf_routing.dynamic.persistence.phpcr.route_basepaths" with the given value.

As you can see, the actual value of the parameter is array('/cms/test'), while the expected was array('/cms/routes', '/cms/test'). The failure message says the opposite.

Class names as parameter are not resolved

When a definition is set up with the class using a service parameter, the parameter is not resolved.

This can be fixed by using $container->getParameterBag()->resolveValue($class).

Or is this intended?

Btw, I remember creating this issue in the past, but I can't find it. If I'm creating a duplicate one, I'm really sorry.

Add a shortcut assertion for parametered classes of services

Most of my services have a parameter for their classes. Currently, this needs to call:

$this->assertContainerBuilderHasService('my_service', '%my_service.class%');
$this->assertContainerBuilderHasParameter('my_service.class', 'My\Class');

This could be combined in a helper assertion, even using the suffix ".class" convention to remove duplicate parameters:

/**
 * Assert that a serviceId uses a parameter to use a class.
 * If no parameter name is given, the name of the serviceId suffixed with '.class' will be used.
 *
 * @param $serviceId
 * @param $expectedClass
 * @param null $expectedClassParameterValue
 */
public function assertContainerBuilderHasServiceWithParameteredClass($serviceId, $expectedClass, $expectedClassParameterValue=null)
{
    if(is_null($expectedClassParameterValue)) {
        // Assume the service has a default class parameter.
        $expectedClassParameterValue = $serviceId.'.class';
    }
    $this->assertContainerBuilderHasService($serviceId, '%'.$expectedClassParameterValue.'%');
    $this->assertContainerBuilderHasParameter($expectedClassParameterValue, $expectedClass);
}

Run tests against multiple versions of symfony

Using travis ENV, it is possible to run tests against multiple versions of symfony.

Example:

env:
   - SYMFONY_VERSION=2.1.*
   - SYMFONY_VERSION=2.2.*
   - SYMFONY_VERSION=2.3.*
   - SYMFONY_VERSION=2.4.*

before_script:
   - composer require symfony/dependency-injection:${SYMFONY_VERSION} --no-update
   - composer update --prefer-dist --no-interaction

How can one test the prepend() method ?

I made a P.R. with a modification to the extension so that it uses the prepend() method of the extension to test the presence of a related configuration node for another bundle (SonataAdminBundle). Is it possible to test that with your library ?

Can't install with config-test 1.0

Because of the restriction to 0.* of the config tester, this cannot be installed along side of it when using ~1.0 for the config package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.