Skip to content
Browse files

Fix issue with script not calling autoloader

  • Loading branch information...
1 parent d517e28 commit 34ec946c44a7dbf8d0b72cf3741d9dd9c8bc195a @MarcelloDuarte MarcelloDuarte committed Aug 7, 2012
Showing with 38 additions and 14 deletions.
  1. +1 −1 composer.json
  2. +37 −9 scripts/phpspec.php
  3. +0 −2 spec/Matcher/CustomMatcherSpec.php
  4. +0 −2 spec/Runner/Cli/RunnerSpec.php
View
2 composer.json
@@ -12,7 +12,7 @@
],
"bin": ["scripts/phpspec.php"],
"autoload": {
- "psr-0": { "PHPSpec\\": "src/" }
+ "psr-0": { "PHPSpec": "src/" }
},
"require": {
"php": ">=5.3.2",
View
46 scripts/phpspec.php
@@ -171,19 +171,47 @@
*/
ini_set('display_errors', 1);
error_reporting(E_ALL|E_STRICT);
+define('COMPOSER_INSTALL', 'composer_install');
+define('PEAR_INSTALL', 'pear_install');
ini_set('xdebug.show_exception_trace', 'Off');
+$ds = DIRECTORY_SEPARATOR;
-require_once 'PHPSpec/Loader/UniversalClassLoader.php';
-include_once 'Mockery.php';
+$installation = '';
+if (is_dir($vendor = __DIR__ . "{$ds}..{$ds}vendor")) {
+ require($vendor . "{$ds}autoload.php");
+ $installation = COMPOSER_INSTALL;
+} elseif (is_dir($vendor = __DIR__ . "{$ds}..{$ds}..{$ds}..{$ds}..{$ds}vendor")) {
+ require($vendor . "{$ds}autoload.php");
+ $installation = COMPOSER_INSTALL;
+} else {
+ $paths = explode(':', ini_get('include_path'));
+ @require_once 'PHPSpec/Loader/UniversalClassLoader.php';
+ if (class_exists('PHPSpec\Loader\UniversalClassLoader')) {
+ $installation = PEAR_INSTALL;
+ $loader = new PHPSpec\Loader\UniversalClassLoader();
+ $loader->registerNamespace('PHPSpec', $paths);
+ $loader->registerNamespace('Mockery', $paths);
+ $loader->registerPrefix('Text_', $paths);
+ $loader->register();
+ } else {
+ die(
+ 'You must set up the project dependencies, run the following commands:' . PHP_EOL .
+ 'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
+ 'php composer.phar install' . PHP_EOL
+ );
-$paths = explode(':', ini_get('include_path'));
-$loader = new \PHPSpec\Loader\UniversalClassLoader();
-$loader->registerNamespace('PHPSpec', $paths);
-$loader->registerNamespace('Mockery', $paths);
+ }
+}
-$loader->registerPrefix('Text_', $paths);
-
-$loader->register();
+if ($installation === COMPOSER_INSTALL) {
+ if (is_dir($phpspecDir = dirname(__DIR__) . "{$ds}src{$ds}PHPSpec{$ds}")) {
+ require_once $phpspecDir . "Matcher{$ds}Functions.php";
+ } elseif (is_dir($phpspecDir = $vendor . "{$ds}phpspec{$ds}phpspec{$ds}src{$ds}PHPSpec{$ds}")) {
+ require_once $phpspecDir . "{$ds}Matcher{$ds}Functions.php";
+ } else {
+ die('hi');
+ }
+}
$phpspec = new \PHPSpec\PHPSpec($argv);
$phpspec->execute();
View
2 spec/Matcher/CustomMatcherSpec.php
@@ -2,8 +2,6 @@
namespace Spec\PHPSpec\Matcher;
-require_once "PHPSpec/Matcher/Functions.php";
-
class ExampleCustomMatcherMatchSuccessful extends \Exception {}
class ExampleCustomMatcherMatchFailed extends \Exception {}
View
2 spec/Runner/Cli/RunnerSpec.php
@@ -3,8 +3,6 @@
namespace Spec\PHPSpec\Runner\Cli;
require_once __DIR__ . '/../../WorldBuilder.php';
-require_once 'PHPSpec/Runner/Reporter.php';
-require_once 'PHPSpec/Runner/Cli/Reporter.php';
use \PHPSpec\Runner\Cli\Runner as CliRunner,
\Spec\PHPSpec\WorldBuilder;

0 comments on commit 34ec946

Please sign in to comment.
Something went wrong with that request. Please try again.