Skip to content

Commit

Permalink
Merge pull request #15 from BenConstable/laravel-path-setting
Browse files Browse the repository at this point in the history
Set Laravel path in phpspec.yml, closes #13
  • Loading branch information
BenConstable committed Oct 14, 2014
2 parents 09c2c32 + 275e0b6 commit d6e0d49
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 29 additions & 6 deletions src/PhpSpec/Laravel/Extension/LaravelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d6e0d49

Please sign in to comment.