run.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. require_once dirname(__FILE__) . '/config.php';
  3. require_once SWEETY_SIMPLETEST_PATH . '/unit_tester.php';
  4. require_once SWEETY_SIMPLETEST_PATH . '/mock_objects.php';
  5. require_once SWEETY_SIMPLETEST_PATH . '/reporter.php';
  6. require_once SWEETY_SIMPLETEST_PATH . '/xml.php';
  7. require_once 'Sweety/Runner.php';
  8. require_once 'Sweety/Runner/CliRunner.php';
  9. require_once 'Sweety/Reporter/CliReporter.php';
  10. $exe = SWEETY_PHP_EXE;
  11. if (!$exe)
  12. {
  13. if (getenv('_'))
  14. {
  15. $exe = getenv('_');
  16. }
  17. elseif (class_exists('Com'))
  18. {
  19. $wmi = new Com('winmgmts:');
  20. $exe = $wmi->get('//./root/cimv2:Win32_Process.Handle="' . getmypid() . '"')
  21. ->executablePath;
  22. }
  23. }
  24. $runner = new Sweety_Runner_CliRunner(
  25. explode(PATH_SEPARATOR, SWEETY_TEST_PATH),
  26. $exe . ' ' . $argv[0]
  27. );
  28. $name = !empty($argv[1]) ? $argv[1] : 'All Tests';
  29. $runner->setReporter(new Sweety_Reporter_CliReporter(sprintf('%s - %s', SWEETY_SUITE_NAME, $name)));
  30. $runner->setIgnoredClassRegex(SWEETY_IGNORED_CLASSES);
  31. $locators = preg_split('/\s*,\s*/', SWEETY_TEST_LOCATOR);
  32. foreach ($locators as $locator)
  33. {
  34. $runner->registerTestLocator(new $locator());
  35. }
  36. if (!empty($argv[1]) && !preg_match('~!?/.*?/~', $argv[1]))
  37. {
  38. $testName = $argv[1];
  39. $format = !empty($argv[2]) ? $argv[2] : Sweety_Runner::REPORT_TEXT;
  40. $runner->runTestCase($testName, $format);
  41. }
  42. else
  43. {
  44. $runner->runAllTests();
  45. }