1
votes

I did a fresh install of Luracast/Restler using Composer and am unable to get any behat tests to run. I'm a newbie to both Restler and behat, so I may be making a beginners mistake, but according to the documentation, all I need to do is change the root URL in behat.yml and then type bin/behat.

Here is the error message I'm getting when I type vendor/bin/behat.

  [RuntimeException]                                                         
  Context class not found.                                                   
  Maybe you have provided a 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] [--stop-on-failure] [--rerun="..."] [--append-snippets] [--append-to="..."] [features]


Content-type: text/html

Here is my behat.yml file:

# behat.yml
default:
    context:
        parameters:
            base_url: http://<MY_DOMAIN>.com/restler3/sampleproject/public

I've tried specifying both the paths.features and path.bootstrap variables with both absolute and relative paths with no success.

# behat.yml
default:
    paths:
        features: features
        bootstrap:  features/bootstrap
    context:
        parameters:
            base_url: http://<MY_DOMAIN>.com/restler3/sampleproject/public

I would really like to use Restler for an API project that I'm starting, but I need to be able to run tests, so any help in getting me over this issue would be appreciated.

1

1 Answers

1
votes

Have you set up Behat using behat --init?

Behat needs features and bootstrap directories in order to run. You can create these by entering behat --init on the command line. See the Behat documentation for more information about this:

Create a new directory and setup behat inside that directory:

$ mkdir ls_project
$ cd ls_project
$ behat --init

The behat --init will create a features/ directory with some basic things to get your started.

Behat will run a test method for every line in your test file. These methods are contained in contexts. To write the sort of feature tests used in the Restler examples you'll need to use the "RestContext" which is included with Restler. Copy the contents of vendor/luracast/restler/features/bootstrap into your Behat bootstrap directory in order to be able to make use of these (you'll need FeatureContext.php too: this instantiates the RestContext).

Restler's feature tests make use of Guzzle so you'll also need to add that to your composer.json:

{
   "require-dev": {
      "guzzlehttp/guzzle": "~3.1.1"
   }
}