Skip to content
This repository has been archived by the owner on Feb 5, 2021. It is now read-only.

Problem with multiple services using the same class #13

Open
ghost opened this issue Aug 8, 2017 · 2 comments
Open

Problem with multiple services using the same class #13

ghost opened this issue Aug 8, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 8, 2017

(As @pamil requested, posting it here):

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 }

3.) Now hook them up within the contexts_services:

- something_first
- something_second

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

@pamil
Copy link
Member

pamil commented Aug 8, 2017

Can you check if it applies only to contexts used as hooks or also to regular contexts (one context class with a step defined that's printing an injected string)?

@ghost
Copy link
Author

ghost commented Aug 13, 2017

I'm not sure if I understand the question? It applies to any context service that is tagged with fob.context_service and then used within the contexts_services option

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant