Symfony2 + Behat 3 : generate Context file to inside the Bundle and not in the features/bootstrap directory
Asked Answered
S

1

7

How can I run behat --init -s bugfix to generate Context files inside the Bundle? Is there any way to do this? I see the Sf2DemoBundle but I didn't solve how it works.

My files

# /composer.json
    "behat/behat": "dev-master",
    "behat/mink": "dev-master",
    "behat/mink-extension": "dev-master",
    "behat/symfony2-extension": "dev-master",
    "behat/mink-goutte-driver": "dev-master",
    "behat/mink-browserkit-driver": "dev-master",
    "behat/mink-selenium2-driver": "dev-master",
# /behat.yml
default:
    suites:
        default:
            path: %paths.base%/features
            contexts: [Behat\MinkExtension\Context\MinkContext]
        bugfix:
            type: symfony_bundle
            bundle: 'TestBugfixBundle'
            contexts: ['TestBugfixBundle\Features\Context\WebContext']
    extensions:
        Behat\Symfony2Extension: ~
        Behat\MinkExtension:
            default_session: 'symfony2'
            sessions:
                symfony2:
                    symfony2: ~

The solution

You must set the autoload parameter to behat:

# /behat.yml
default:
    autoload:
        '': %paths.base%/src
Spotweld answered 30/6, 2014 at 16:45 Comment(1)
Thanks, better add your solution as an answer, it's really hard to find it in documentation: docs.behat.org/en/v3.0/guides/6.profiles.htmlKenaz
C
2

Your solution is fine, but you can also move your context files to the bundle Feature directory (src/Acme/DemoBundle/Features/Context for instance) and it will work right off the bat.

No need then to add any configuration in behat.yml (no autoload entry is necessary).

Cinnabar answered 7/1, 2015 at 15:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.