Kindly answered via email from Ben Constable :
Setting up PHPSpec with Laravel with its default file layout is pretty difficult, and I haven’t yet figured out how to do it. However, you can get it working with a slightly different layout, like:
- app - Controllers - MyController.php - Models - MyModel.php - spec - Controllers - MyControllerSpec.php - Models - MyModelSpec.php
then, in your
phpspec.yml
you’d have:extensions: - PhpSpec\Laravel\Extension\LaravelExtension suites: laravel_controller_suite: namespace: Controllers src_path: app laravel_model_suite: namespace: Models src_path: app laravel_extension: testing_environment: 'testing'
and finally, you’d need to modify your
composer.json
to includeapp/
in the autoload class map. Your models, controllers and whatever would then be namespaced, like:<?php namespace Controllers; use Controller; class MyController extends Controller {}
That should sort you out. Just as an aside, when I’ve been making Laravel projects I’ve been putting everything in
app/src/MyVendor/MyNamespace/Controllers
etc, which I prefer as a layout (keeps the source away from the config and other files, and is similar to the layout of Laravel Packages).In the future, I will try and look into it and see if I can get PHPSpec working with the default Laravel layout - I’ll update the project on GitHub if/when I do.