Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

symfony

behat

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
like image 868
Krisztián Ferenczi Avatar asked Jun 30 '14 16:06

Krisztián Ferenczi


1 Answers

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

like image 101
Michaël Perrin Avatar answered Nov 16 '22 18:11

Michaël Perrin