From 41ff7af2135f819bdf4fbc339b009668a2b6ae32 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 13 Jul 2012 03:02:30 +0200 Subject: [PATCH] Change inner workings of test runner to use different bootstrap file when testing the core. --- laravel/cli/tasks/test/phpunit.php | 24 ---------------------- laravel/cli/tasks/test/runner.php | 28 +++++++++++++++++--------- laravel/tests/phpunit.php | 32 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 laravel/tests/phpunit.php diff --git a/laravel/cli/tasks/test/phpunit.php b/laravel/cli/tasks/test/phpunit.php index 67644838..32eadd58 100644 --- a/laravel/cli/tasks/test/phpunit.php +++ b/laravel/cli/tasks/test/phpunit.php @@ -1,12 +1,4 @@ - * @link http://laravel.com - */ // -------------------------------------------------------------- // Define the directory separator for the environment. @@ -18,22 +10,6 @@ // -------------------------------------------------------------- require 'paths.php'; -// -------------------------------------------------------------- -// Override the application paths when testing the core. -// -------------------------------------------------------------- -$config = file_get_contents('phpunit.xml'); - -if (strpos($config, 'laravel-tests') !== false) -{ - $path = path('bundle').'laravel-tests'.DS; - - set_path('app', $path.'application'.DS); - - set_path('bundle', $path.'bundles'.DS); - - set_path('storage', $path.'storage'.DS); -} - // -------------------------------------------------------------- // Bootstrap the Laravel core. // -------------------------------------------------------------- diff --git a/laravel/cli/tasks/test/runner.php b/laravel/cli/tasks/test/runner.php index 853f76b0..32c8774f 100644 --- a/laravel/cli/tasks/test/runner.php +++ b/laravel/cli/tasks/test/runner.php @@ -7,6 +7,15 @@ class Runner extends Task { + /** + * The base directory where the tests will be executed. + * + * A phpunit.xml should also be stored in that directory. + * + * @var string + */ + protected $base_path; + /** * Run all of the unit tests for the application. * @@ -26,7 +35,8 @@ public function run($bundles = array()) */ public function core() { - $this->stub(path('sys').'tests/cases'); + $this->base_path = path('sys').'tests'.DS; + $this->stub(path('sys').'tests'.DS.'cases'); $this->test(); } @@ -44,6 +54,8 @@ public function bundle($bundles = array()) $bundles = Bundle::names(); } + $this->base_path = path('sys').'cli'.DS.'tasks'.DS.'test'.DS; + foreach ($bundles as $bundle) { // To run PHPUnit for the application, bundles, and the framework @@ -67,9 +79,9 @@ public function bundle($bundles = array()) protected function test() { // We'll simply fire off PHPUnit with the configuration switch - // pointing to our temporary configuration file. This allows + // pointing to our requested configuration file. This allows // us to flexibly run tests for any setup. - $path = path('base').'phpunit.xml'; + $path = 'phpunit.xml'; // fix the spaced directories problem when using the command line // strings with spaces inside should be wrapped in quotes. @@ -97,7 +109,7 @@ protected function stub($directory) // locations depending on what the developer wants to test. foreach (array('bootstrap', 'directory') as $item) { - $stub = $this->{"swap_{$item}"}($stub, $path, $directory); + $stub = $this->{"swap_{$item}"}($stub, $directory); } File::put(path('base').'phpunit.xml', $stub); @@ -107,24 +119,22 @@ protected function stub($directory) * Swap the bootstrap file in the stub. * * @param string $stub - * @param string $path * @param string $directory * @return string */ - protected function swap_bootstrap($stub, $path, $directory) + protected function swap_bootstrap($stub, $directory) { - return str_replace('{{bootstrap}}', $path.'phpunit.php', $stub); + return str_replace('{{bootstrap}}', $this->base_path.'phpunit.php', $stub); } /** * Swap the directory in the stub. * * @param string $stub - * @param string $path * @param string $directory * @return string */ - protected function swap_directory($stub, $path, $directory) + protected function swap_directory($stub, $directory) { return str_replace('{{directory}}', $directory, $stub); } diff --git a/laravel/tests/phpunit.php b/laravel/tests/phpunit.php new file mode 100644 index 00000000..8e5ba204 --- /dev/null +++ b/laravel/tests/phpunit.php @@ -0,0 +1,32 @@ +