Search code examples
behatautoloader

Additional directories with behat


I'm putting together automated testing with behat - and encountered an issue I can't seem to find a solution to.

My behat.yml has all the usual stuff; I got directories for features and boostrap - and it all works.

Now, I have a separate directory, which contains additional classes that I need during the test execution. While I can, of course, use lots of require, I'm sure there's a better way to add a directory to the autoloader - yet I can't figure out how.

For example, I have the following directory structure:

test/
    features/
    bootstrap/
    lib/
    behat.yml

behat.yml contains this:

default:
  autoload: [%paths.base%/boostrap]
  suites:
    web:
      paths: [%paths.base%/features/web]
      contexts: [Web\LoginContext]
    api:
      paths: [%paths.base%/features/api]
      contexts: [Api\ApiContext]

Directory lib contains additional classes that I need to use in my tests. How can I add lib directory to the autoloader?


Solution

  • After much struggle, I kind of figured it out. I need to add this directory to my composer.json file:

    "autoload": {
        "psr-4": {
            "MyNameSpace\\": "lib/"
        }
    }
    

    and then run composer update.