GithubHelp home page GithubHelp logo

friendsofbehat / servicecontainerextension Goto Github PK

View Code? Open in Web Editor NEW
115.0 3.0 6.0 53 KB

:radio: Allows to declare own services inside Behat container without writing an extension.

License: MIT License

PHP 40.43% Gherkin 59.57%
behat behat-extension php dependency-injection

servicecontainerextension's Introduction

Service Container Extension License Version Build status on Linux Scrutinizer Quality Score

Allows to declare own services inside Behat container without writing an extension.

Usage

  1. Install it:

    $ composer require friends-of-behat/service-container-extension --dev
  2. Enable this extension and configure Behat to use it:

    # behat.yml
    default:
        # ...
        extensions:
            FriendsOfBehat\ServiceContainerExtension:
                imports:
                    - "features/bootstrap/config/services.xml"
                    - "features/bootstrap/config/services.yml"
                    - "features/bootstrap/config/services.php"
  3. Write services files definitions:

    <!-- features/bootstrap/config/services.xml -->
    <?xml version="1.0" encoding="UTF-8" ?>
    <container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services">
        <services>
            <service id="acme.my_service" class="Acme\MyService" />
        </services>
    </container>
    # features/bootstrap/config/services.yml
    services:
        acme.my_service:
            class: Acme\MyService
    // features/bootstrap/config/services.php
    use Symfony\Component\DependencyInjection\Definition;
    
    $container->setDefinition('acme.my_service', new Definition(\Acme\MyService::class));

servicecontainerextension's People

Contributors

lchrusciel avatar pamil 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

servicecontainerextension's Issues

Problem with multiple services using the same class

I noticed that when you have two (or more) services of the same class, only the last one seems to take effect.

Config in behat.yml.dist:

....
default:
    extensions:
        FriendsOfBehat\ContextServiceExtension:
            imports:
                - "vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml"
                - "tests/Behat/Resources/contexts.yml"
                - "tests/Behat/Resources/pages.yml"
...
cached:
    extensions:
        FriendsOfBehat\ContextServiceExtension:
            imports:
                - "vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml"

Steps to reproduce:

  1. Create a class
namespace Tests\Behat\Context\Hook;

use Behat\Behat\Context\Context;

/**
 * @author Wojciech Górski <[email protected]>
 */
class Something implements Context
{
    /**
     * @var string
     */
    private $message;

    /**
     * @param string $message
     */
    public function __construct($message)
    {
        $this->message = $message;
    }

    /**
     * @BeforeScenario
     */
    public function doThings()
    {
        echo 'Does things for: ' . $this->message;
    }
}

2.)

In my Resources/contexts/hook.yml:

    something_first:
        class: Tests\Behat\Context\Hook\Something
        arguments: ["first"]
        tags:
            - { name: fob.context_service }

    something_second:
        class: Tests\Behat\Context\Hook\Something
        arguments: ["second"]
        tags:
            - { name: fob.context_service }

Now hook them up within the contexts_services:

- something_first
- something_second

Now when I run my tests I can only see output for the something_second service ("Does things for: second")

[YML] - Which's the correct configuration in YML for a behat service

I have a service and some parameters for inject:

services:
    app.behat.page:
        class: AppBundle\Behat\Page\Page
        arguments: ['@mink.default_session', '*__behat__.mink.parameters']
        abstract: true
        public: false

When I run the bin/behat command, throw me this:

The service "XXX" has a dependency on a non-existent service "mink.default_session".

Use MinkContext

I try to load context define as a service and simple context like MinkContext

    suites:
        employee:
            contexts:
                - 'Behat\MinkExtension\Context\MinkContext'
            contexts_services:
                - al.employee.context

It seems that `MinkContext is not used because I have undefined steps like I press 'something'. What happen? did I do something wrong?

Thank you.

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.