Code Monkey home page Code Monkey logo

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

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().

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?

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!

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)

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.

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.

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 ?

[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.

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.

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

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. :)

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

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?

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 ...

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

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?

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');

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.

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?

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.

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.

[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?

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.

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.

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.

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);
}

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.

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

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.