Behat - Context class not found.
Asked Answered
J

2

7

This is my directory structure:

composer.json
composer.phar
vendor/
    bin/
        behat
tests/
    functional/
        behat.yml
        features/
            registration.feature
            bootstrap/
                FeatureContext.php

I did:

cd tests/functional
../../vendor/bin/behat --init

Which created basic structure for me. This is inside behat.yml:

default:
  paths:
    features: '%behat.paths.base%/features'
    bootstrap:  '%behat.paths.base%/features/bootstrap'

Now I try to run BDD tests like this:

vendor/bin/behat -c tests/functional/behat.yml

And I get:

  [RuntimeException]                                                       
  Context class not found.                                                 
  Maybe you have provided wrong or no `bootstrap` path in your behat.yml:  
  http://docs.behat.org/guides/7.config.html#paths                         



behat [--init] [-f|--format="..."] [--out="..."] [--lang="..."] [--[no-]ansi] [--[no-]time] [--[no-]paths] [--[no-]snippets] [--[no-]snippets-paths] [--[no-]multiline] [--[no-]expand] [--story-syntax] [-d|--definitions="..."] [--name="..."] [--tags="..."] [--cache="..."] [--strict] [--dry-run] [--rerun="..."] [--append-snippets] [--append-to="..."] [features]

Any idea what is the problem?

I installed Behat via Composer. This is my composer.json:

{
    "name": "hello",
    "description": "Hello World",
    "minimum-stability": "dev",
    "require": {
        "php": ">=5.3",
        "zendframework/zendframework": "2.1.4",
        "doctrine/common": "dev-master#d7987c96675e153638729383577090feed9854f1"
    },
    "require-dev": {
        "phpunit/phpunit": "3.7.14",
        "behat/behat": "2.4.*@stable"
    }
}

Which I installed with:

php composer.phar install --dev -o
Jordanjordana answered 10/4, 2013 at 14:47 Comment(0)
J
3

This is what worked.

cd tests/functional
../../vendor/bin/behat --init
cd ../../
vendor/bin/behat -c tests/functional/behat.yml

With this config file:

default:
  paths:
    features: features
    bootstrap: features/bootstrap
Jordanjordana answered 10/4, 2013 at 15:35 Comment(0)
M
6

You initialised Behat while being in the tests/functional directory but you're trying to run it from the root directory.

Fix your paths:

default:
  paths:
    features: 'tests/functional/features'
    bootstrap:  'tests/functional/features/bootstrap'

Or run Behat from tests/functional directory.

I'd recommend to keep the original file layout (features in the root dir). Edit: Actually, I tried setting it up myself and it worked with the config you provided. There must be something else you're doing which you didn't specify in the question.

Modestia answered 10/4, 2013 at 14:58 Comment(2)
Still getting the same error. I have to keep this folder structure as it is a project convention. It cannot be in the root folder.Jordanjordana
I don't want to change bin folder as well. I am using other libraries as well and their binaries are in vendor/bin/Jordanjordana
J
3

This is what worked.

cd tests/functional
../../vendor/bin/behat --init
cd ../../
vendor/bin/behat -c tests/functional/behat.yml

With this config file:

default:
  paths:
    features: features
    bootstrap: features/bootstrap
Jordanjordana answered 10/4, 2013 at 15:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.