Skip to content

Commit

Permalink
Merge pull request #22 from MitchProbst/master
Browse files Browse the repository at this point in the history
Preserve globals for bootstrap files
  • Loading branch information
danielstjules committed Mar 24, 2016
2 parents 7cdbc18 + fcf8e43 commit 8f2a0c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
26 changes: 0 additions & 26 deletions src/Runner/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ public function afterEach(\Closure $closure)
*/
public function run()
{
if (self::$console->options['bootstrap'] &&
!$this->loadBootstrap(self::$console->options['bootstrap'])) {
return;
}

// Get and instantiate the reporter class, load files
$reporterClass = self::$console->getReporterClass();
$this->reporter = new $reporterClass(self::$console);
Expand Down Expand Up @@ -340,25 +335,4 @@ private function runRunnable($runnable)
$runnable->run();
}
}

/**
* Loads a bootstrap file given its string path.
*
* @param string $bootstrap Path to the bootstrap file to load
* @return bool Whether or not the file was successfully loaded
*/
private function loadBootstrap($bootstrap)
{
if (!file_exists($bootstrap)) {
self::$console->writeLn("Bootstrap file not found: $bootstrap");
} else if(!is_readable($bootstrap)) {
self::$console->writeLn("Bootstrap file not readable: $bootstrap");
} else if(!@include_once($bootstrap)) {
self::$console->writeLn("Unable to include bootstrap: $bootstrap");
} else {
return true;
}

return false;
}
}
16 changes: 16 additions & 0 deletions src/pho.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ function expandPaths($paths)
require_once($path);
}

// Bootstrap file must be required directly rather than from function
// invocation to preserve any loaded globals
$bootstrap = $console->options['bootstrap'];
if ($bootstrap) {
if (!file_exists($bootstrap)) {
$console->writeLn("Bootstrap file not found: $bootstrap");
exit(1);
} else if(!is_readable($bootstrap)) {
$console->writeLn("Bootstrap file not readable: $bootstrap");
exit(1);
} else if(!@include_once($bootstrap)) {
$console->writeLn("Unable to include bootstrap: $bootstrap");
exit(1);
}
}

// Files must be required directly rather than from function
// invocation to preserve any loaded globals
$paths = expandPaths($console->getPaths());
Expand Down

0 comments on commit 8f2a0c0

Please sign in to comment.