diff --git a/README.md b/README.md index 8218ec1..5891562 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,36 @@ laravel_extension: custom seed class, be sure to add the fully qualified namespace (e.g `My\Custom\Seeder`) +###Laravel path + +By default, the extension will look for the Laravel framework files in the +directory above the `vendor/` dir, like so: + +``` +- app/ +- bootstrap/ +- public/ +- vendor/ +- phpspec.yml +``` + +This is the default layout of a Laravel project. However, you can manually +specify the path to the Laravel framework files like so: + +```yaml +laravel_extension: + framework_path: "/shared/laravel/install" +``` + +You can specify either an absolute path (use leading slash), or a path relative +to the `vendor/` directory. For example, a relative path setting for the default +install location would be as follows: + +```yaml +laravel_extension: + framework_path: ".." # Read like vendor/../ +``` + ##Usage ###General testing diff --git a/src/PhpSpec/Laravel/Extension/LaravelExtension.php b/src/PhpSpec/Laravel/Extension/LaravelExtension.php index 688e2ca..af0f490 100644 --- a/src/PhpSpec/Laravel/Extension/LaravelExtension.php +++ b/src/PhpSpec/Laravel/Extension/LaravelExtension.php @@ -23,22 +23,45 @@ class LaravelExtension implements ExtensionInterface { */ public function load(ServiceContainer $container) { - $bootstrapPath = __DIR__ . '/../../../../../../../bootstrap'; + $getBoostrapPath = function ($manualPath = null) + { + // Configured absolute paths - // We do this so we can run the tests successfully + if (($manualPath !== null) && (strpos($manualPath, '/') === 0)) { + return $manualPath . '/bootstrap'; + } + + // Paths relative to vendor/ dir + + if (!is_dir($vendorDir = getcwd() . '/vendor')) { + $vendorDir = __DIR__ . '/../../../../../..'; + } - if (file_exists($bootstrapPath . '/autoload.php')) { - require $bootstrapPath . '/autoload.php'; - } + if (($manualPath !== null) && is_dir($vendorDir . '/' . $manualPath)) { + return $vendorDir . '/' . $manualPath . '/bootstrap'; + } else { + return $vendorDir . '/../bootstrap'; + } + }; // Create & store Laravel wrapper $container->setShared( 'laravel', - function ($c) use ($bootstrapPath) + function ($c) use ($getBoostrapPath) { $config = $c->getParam('laravel_extension'); + $bootstrapPath = $getBoostrapPath( + isset($config['framework_path']) ? $config['framework_path'] : null + ); + + if (file_exists($bootstrapPath . '/autoload.php')) { + require $bootstrapPath . '/autoload.php'; + } else { + die("Bootstrap dir not found at $bootstrapPath"); + } + $laravel = new Laravel( isset($config['testing_environment']) ? $config['testing_environment'] : null, $bootstrapPath