phpspec and laravel setup
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\LaravelExtensionsuites: laravel_controller_suite: namespace: Controllers src_path: app laravel_model_suite: namespace: Models src_path: applaravel_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.
For those using Laravel 5.x and PhpSpec 4.x, you can tweak with the PSR4 prefix configuration in order to make PhpSpec compatible with the Laravel layout.
My project used this configuration:
suites: app: namespace: App src_path: app psr4_prefix: App spec_prefix: classes spec_path: specs