Adam Copley
Adam Copley

Reputation: 1495

How do I configure Behat to autoload classes from my app specific folder

I'm trying to install & configure Behat on an existing small project of mine. I understand the concept of putting the *.feature files into the features folder, and also can live with putting my actual *Context.php files in the features/bootstrap folder. When I look at the part of the documentation which mentions actual feature implementation it implies that Behat by default expects that you would put your application specific classes into this same folder:

We put the Shelf class into features/bootstrap/Shelf.php because features/bootstrap is an autoloading folder for Behat. Behat has a built-in PSR-0 autoloader, which looks into features/bootstrap. If you’re developing your own application, you probably would want to put classes into a place appropriate for your app.

However it doesn't mention anywhere in the documentation how I would configure Behat to be able to recognise classes from the actual app folder.

This is my projects directory structure:

/
-/app
--/classes --where my apps classes actually live
-/features --behat generated folder
--/bootstrap --behat generated folder
-/public
-/system
-/vendor -- composer included libraries

My project uses its own autoloader for classes which searches in the app/classes folder, and the class names use an underscore where a directory separator would be in the path. e.g. class Controller_App would be found in app/classes/controller/app.php

How can I configure Behat so that it isn't expecting to find my applications classes in the features/bootstrap folder?

Upvotes: 3

Views: 979

Answers (1)

Adam Copley
Adam Copley

Reputation: 1495

solution was to add the following to composer.json:

"autoload": {
        "psr-0": {"":"app/classes"}
}

and then run composer dump-autoload

then it works!

Upvotes: 3

Related Questions