runner.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php namespace Laravel\CLI\Tasks\Test;
  2. use Laravel\File;
  3. use Laravel\Bundle;
  4. use Laravel\CLI\Tasks\Task;
  5. class Runner extends Task {
  6. /**
  7. * Run all of the unit tests for the application.
  8. *
  9. * @return void
  10. */
  11. public function run()
  12. {
  13. $this->bundle(array(DEFAULT_BUNDLE));
  14. }
  15. /**
  16. * Run the tests for the Laravel framework.
  17. *
  18. * @return void
  19. */
  20. public function core()
  21. {
  22. if ( ! is_dir(path('bundle').'laravel-tests'))
  23. {
  24. throw new \Exception("The bundle [laravel-tests] has not been installed!");
  25. }
  26. // When testing the Laravel core, we will just stub the path directly
  27. // so the test bundle is not required to be registered in the bundle
  28. // configuration, as it is kind of a unique bundle.
  29. $this->stub(path('bundle').'laravel-tests/cases');
  30. $path = path('bundle').'laravel-tests/';
  31. $this->test();
  32. }
  33. /**
  34. * Run the tests for a given bundle.
  35. *
  36. * @param array $arguments
  37. * @return void
  38. */
  39. public function bundle($bundles = array())
  40. {
  41. if (count($bundles) == 0)
  42. {
  43. $bundles = Bundle::names();
  44. }
  45. foreach ($bundles as $bundle)
  46. {
  47. // To run PHPUnit for the application, bundles, and the framework
  48. // from one task, we'll dynamically stub PHPUnit.xml files via
  49. // the task and point the test suite to the correct directory
  50. // based on what was requested.
  51. if (is_dir($path = Bundle::path($bundle).'tests'))
  52. {
  53. $this->stub($path);
  54. $this->test();
  55. }
  56. }
  57. }
  58. /**
  59. * Run PHPUnit with the temporary XML configuration.
  60. *
  61. * @return void
  62. */
  63. protected function test()
  64. {
  65. // We'll simply fire off PHPUnit with the configuration switch
  66. // pointing to our temporary configuration file. This allows
  67. // us to flexibly run tests for any setup.
  68. passthru('phpunit -c '.path('base').'phpunit.xml');
  69. @unlink(path('base').'phpunit.xml');
  70. }
  71. /**
  72. * Write a stub phpunit.xml file to the base directory.
  73. *
  74. * @param string $directory
  75. * @return void
  76. */
  77. protected function stub($directory)
  78. {
  79. $stub = File::get(path('sys').'cli/tasks/test/stub.xml');
  80. $stub = str_replace('{{directory}}', $directory, $stub);
  81. File::put(path('base').'phpunit.xml', $stub);
  82. }
  83. }