2017 © Pedro PelĂĄez
 

library atoum-symfony-di-extension

Symfony Dependency Injection extension for atoum

image

jdecool/atoum-symfony-di-extension

Symfony Dependency Injection extension for atoum

  • Thursday, February 22, 2018
  • by jdecool
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

AtoumSymfonyDI extension

Build Status, (*1)

This extension is inspired by SymfonyDependencyInjectionTest, and used for simplify testing of Symfony DI., (*2)

Example

namespace Vendor\MyProjectBundle\DependencyInjection\Tests\Units;

use atoum;
use Vendor\MyProjectBundle\DependencyInjection\VendorMyBundleExtension as TestedClass;
use Symfony\Component\DependencyInjection;

class VendorMyBundleExtension extends atoum
{
    public function testLoad()
    {
        $this
            ->given(
                $container = new DependencyInjection\ContainerBuilder(),
                $testedClass = new TestedClass(),
                $testedClass->load([], $container)
            )
            ->then
                ->containerBuilder($container)
                    ->hasService('myServiceName')
                    ->hasParameter('myParameterName')
        ;
    }
}

Install it

Install extension using composer:, (*3)

composer require --dev jdecool/atoum-symfony-di-extension

Enable the extension using atoum configuration file:, (*4)

<?php

// .atoum.php

require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

use jdecool\atoum\symfonyDependencyInjection;

$runner->addExtension(new symfonyDependencyInjection\extension($script));

Asserters

This extension adds two new asserters : containerBuilder and serviceDefinition., (*5)

In the following examples we will assume we have a container definition like this one, available in a $container variable:, (*6)

<parameters>
    <parameter key="mailer.transport">sendmail</parameter>
</parameters>

<services>
    <service id="myAwesomeAlias" alias="serviceid" />

    <service id="serviceid" class="ArrayObject" >
        <argument type="collection">
            <argument type="service"><service class="stdClass" /></argument>
        </argument>
        <call method="append">
            <argument type="service"><service class="stdClass" /></argument>
        </call>
        <tag name="myCustomTag" />
    </service>

    <service id="app.synthetic_service" synthetic="true" />
</services>

containerBuilder

On the containerBuilder asserter, all assertions from the variable asserter are available., (*7)

hasService

hasService checks if a service is present in the container., (*8)

$this
    ->containerBuilder($container)
        ->hasService('serviceId') // passes
        ->hasService('service_id') // fails
;

hasAlias

hasAlias checks if an alias is present in the container., (*9)

$this
    ->containerBuilder($container)
        ->hasAlias('myAwesomeAlias') // passes
        ->hasAlias('anUnexistingAlias') // fails
;

hasSyntheticService

hasSyntheticService checks if a service is present in the container and is synthetic., (*10)

$this
    ->containerBuilder($container)
        ->hasSyntheticService('app.synthetic_service') // passes
        ->hasService('app.synthetic_service') // fails
        ->hasSyntheticService('app_synthetic_service') // fails
;

hasNotService

hasNotService checks if a service is not present in the container., (*11)

$this
    ->containerBuilder($container)
        ->hasService('service_id') // passes
        ->hasService('serviceId') // fails
;

hasParameter

hasParameter checks if a parameter is present in the container., (*12)

$this
    ->containerBuilder($container)
        ->hasParameter('mailer.transport') // passes
        ->hasParameter('mailer_transport') // fails
;

hasNotParameter

hasNotParameter checks if a parameter is not present in the container., (*13)

$this
    ->containerBuilder($container)
        ->hasNotParameter('mailer_transport') // passes
        ->hasNotParameter('mailer.transport') // fails
;

serviceDefinition

On the serviceDefinition asserter, all assertions from the variable asserter are available., (*14)

isInstanceOf

isInstanceOf checks if the defined service class is the same as tested., (*15)

Warning : this will not check if the class inherits from another one., (*16)

$this
    ->serviceDefinition($container->getDefinition('serviceid'))
        ->isInstanceOf('ArrayObject') // passes
        ->isInstanceOf('SplFileObject') // fails
;

isNotInstanceOf

isInstanceOf checks if the defined service class is not the same as tested., (*17)

Warning : this will not check if the class inherits from another one., (*18)

$this
    ->serviceDefinition($container->getDefinition('serviceid'))
        ->isNotInstanceOf('SplFileObject') // passes
        ->isNotInstanceOf('ArrayObject') // fails 
;

hasArgument

hasArgument checks if the service definition has an argument in the index passed has parameter., (*19)

$this
    ->serviceDefinition($container->getDefinition('serviceid'))
        ->hasArgument(0)
;

hasTag

hasTag checks if the service definition has a given tag., (*20)

$this
    ->serviceDefinition($container->getDefinition('serviceid'))
        ->hasTag('myCustomTag')
;

hasMethodCall

hasMethodCall checks if a service definition it a method call defined on the method name passed as parameter., (*21)

$this
    ->serviceDefinition($container->getDefinition('serviceid'))
        ->hasTag('myCustomTag')
;

License

This extension is released under the MIT License. See the bundled LICENSE file for details., (*22)

atoum, (*23)

The Versions

22/02 2018

dev-master

9999999-dev

Symfony Dependency Injection extension for atoum

  Sources   Download

BSD BSD-3-Clause

The Requires

 

The Development Requires

tdd test dependency injection unit testing symfony atoum

22/02 2018

dev-test-symfony-4

dev-test-symfony-4

Symfony Dependency Injection extension for atoum

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

tdd test dependency injection unit testing symfony atoum

22/02 2018

1.1.0

1.1.0.0

Symfony Dependency Injection extension for atoum

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

tdd test dependency injection unit testing symfony atoum

14/02 2016

1.0.1

1.0.1.0

Symfony Dependency Injection extension for atoum

  Sources   Download

BSD

The Requires

 

tdd test dependency injection unit testing symfony atoum

14/02 2016

1.0.0

1.0.0.0

Symfony Dependency Injection extension for atoum

  Sources   Download

BSD

The Requires

 

tdd test dependency injection unit testing symfony atoum