From 43780d37afcbe746b46b45136dd04c3225371a85 Mon Sep 17 00:00:00 2001 From: Ben Constable Date: Tue, 14 Oct 2014 22:28:17 +0100 Subject: [PATCH 1/3] Add Laravel path override setting --- .../Laravel/Extension/LaravelExtension.php | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/PhpSpec/Laravel/Extension/LaravelExtension.php b/src/PhpSpec/Laravel/Extension/LaravelExtension.php index 688e2ca..6ee074d 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['bootstrap_path']) ? $config['bootstrap_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 From 877632f37b858759b0e27dd1ac8a1782c20e4b50 Mon Sep 17 00:00:00 2001 From: Ben Constable Date: Tue, 14 Oct 2014 22:28:23 +0100 Subject: [PATCH 2/3] Update README --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 8218ec1..721ee8c 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: + bootstrap_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: + bootstrap_path: ".." # Read like vendor/../ +``` + ##Usage ###General testing From 275e0b6813bb7f0b0db8f9bab662d5ce3d39b009 Mon Sep 17 00:00:00 2001 From: Ben Constable Date: Tue, 14 Oct 2014 22:33:27 +0100 Subject: [PATCH 3/3] Use 'framework_path' over 'bootstrap_path' --- README.md | 4 ++-- src/PhpSpec/Laravel/Extension/LaravelExtension.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 721ee8c..5891562 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ specify the path to the Laravel framework files like so: ```yaml laravel_extension: - bootstrap_path: "/shared/laravel/install" + framework_path: "/shared/laravel/install" ``` You can specify either an absolute path (use leading slash), or a path relative @@ -125,7 +125,7 @@ install location would be as follows: ```yaml laravel_extension: - bootstrap_path: ".." # Read like vendor/../ + framework_path: ".." # Read like vendor/../ ``` ##Usage diff --git a/src/PhpSpec/Laravel/Extension/LaravelExtension.php b/src/PhpSpec/Laravel/Extension/LaravelExtension.php index 6ee074d..af0f490 100644 --- a/src/PhpSpec/Laravel/Extension/LaravelExtension.php +++ b/src/PhpSpec/Laravel/Extension/LaravelExtension.php @@ -53,7 +53,7 @@ function ($c) use ($getBoostrapPath) $config = $c->getParam('laravel_extension'); $bootstrapPath = $getBoostrapPath( - isset($config['bootstrap_path']) ? $config['bootstrap_path'] : null + isset($config['framework_path']) ? $config['framework_path'] : null ); if (file_exists($bootstrapPath . '/autoload.php')) {