123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php namespace Laravel\CLI\Tasks\Test;
- use Laravel\File;
- use Laravel\Bundle;
- use Laravel\CLI\Tasks\Task;
- class Runner extends Task {
- /**
- * Run all of the unit tests for the application.
- *
- * @return void
- */
- public function run()
- {
- $this->bundle(array(DEFAULT_BUNDLE));
- }
- /**
- * Run the tests for the Laravel framework.
- *
- * @return void
- */
- public function core()
- {
- if ( ! is_dir($GLOBALS['BUNDLE_PATH'].'laravel-tests'))
- {
- throw new \Exception("The bundle [laravel-tests] has not been installed!");
- }
- // When testing the Laravel core, we will just stub the path directly
- // so the test bundle is not required to be registered in the bundle
- // configuration, as it is kind of a unique bundle.
- $this->stub($GLOBALS['BUNDLE_PATH'].'laravel-tests/cases');
- $path = $GLOBALS['BUNDLE_PATH'].'laravel-tests/';
- // When testing the framework, we will swap out the application
- // and other core paths to stub out the application portion of
- // the framework for testing. This allows us to create dummy
- // controllers, views, models, etc.
- $GLOBALS['APP_PATH'] = $path.'application'.DS;
- $GLOBALS['BUNDLE_PATH'] = $path.'bundles'.DS;
- $GLOBALS['STORAGE_PATH'] = $path.'storage'.DS;
- $this->test();
- }
- /**
- * Run the tests for a given bundle.
- *
- * @param array $arguments
- * @return void
- */
- public function bundle($bundles = array())
- {
- if (count($bundles) == 0)
- {
- $bundles = Bundle::names();
- }
- foreach ($bundles as $bundle)
- {
- // To run PHPUnit for the application, bundles, and the framework
- // from one task, we'll dynamically stub PHPUnit.xml files via
- // the task and point the test suite to the correct directory
- // based on what was requested.
- if (is_dir($path = Bundle::path($bundle).'tests'))
- {
- $this->stub($path);
- $this->test();
- }
- }
- }
- /**
- * Run PHPUnit with the temporary XML configuration.
- *
- * @return void
- */
- protected function test()
- {
- // We'll simply fire off PHPUnit with the configuration switch
- // pointing to our temporary configuration file. This allows
- // us to flexibly run tests for any setup.
- passthru('phpunit -c '.$GLOBALS['BASE_PATH'].'phpunit.xml');
- @unlink($GLOBALS['BASE_PATH'].'phpunit.xml');
- }
- /**
- * Write a stub phpunit.xml file to the base directory.
- *
- * @param string $directory
- * @return void
- */
- protected function stub($directory)
- {
- $stub = File::get($GLOBALS['SYS_PATH'].'cli/tasks/test/stub.xml');
- $stub = str_replace('{{directory}}', $directory, $stub);
- File::put($GLOBALS['BASE_PATH'].'phpunit.xml', $stub);
- }
- }
|