/** Initialize the PHPUnit test runner and run tests.
  *
  * @param string[] $options
  *
  * @return void
  */
 private function _doRunTests(array $options)
 {
     if (empty($options['plugin'])) {
         $basedir = null;
     } else {
         try {
             /* @var $config sfPluginConfiguration */
             /** @noinspection PhpUndefinedMethodInspection */
             $config = $this->configuration->getPluginConfiguration($options['plugin']);
         } catch (InvalidArgumentException $e) {
             throw new sfException(sprintf('Plugin "%s" does not exist or is not enabled.', $options['plugin']));
         }
         $basedir = implode(DIRECTORY_SEPARATOR, array($config->getRootDir(), 'test', ''));
         unset($options['plugin']);
     }
     if ($files = $this->_findTestFiles($this->_type, (array) $this->_paths, $basedir)) {
         /** @noinspection PhpIncludeInspection */
         require_once 'PHPUnit' . DIRECTORY_SEPARATOR . 'TextUI' . DIRECTORY_SEPARATOR . 'TestRunner.php';
         $Runner = new PHPUnit_TextUI_TestRunner();
         $Suite = new PHPUnit_Framework_TestSuite(ucfirst($this->name) . ' Tests');
         $Suite->addTestFiles($files);
         /* Inject the command application controller so that it is accessible to
          *  test cases.
          */
         Test_Case::setController($this->commandApplication);
         /* Ignition... */
         try {
             $Runner->doRun($Suite, $options);
         } catch (PHPUnit_Framework_Exception $e) {
             $this->logSection('phpunit', $e->getMessage());
         }
     } else {
         $this->logSection('phpunit', 'No tests found.');
     }
 }
Ejemplo n.º 2
0
 /** Validates the uploads directory to ensure we're not going to inadvertently
  *   put test uploads in the wrong place and/or delete production files.
  *
  * @param bool $force
  *
  * @return void
  */
 protected function _assertTestUploadsDir($force = false)
 {
     if (!self::$_uploadsDirCheck or $force) {
         $this->_assertTestEnvironment();
         $config = sfConfigHandler::replaceConstants(sfYaml::load($this->_getSettingsFilename()));
         /* Determine whether a the test uploads directory is different than the
          *  production one.
          */
         if (isset($config['prod']['.settings']['upload_dir'])) {
             $prod = $config['prod']['.settings']['upload_dir'];
         } elseif (isset($config['all']['.settings']['upload_dir'])) {
             $prod = $config['all']['.settings']['upload_dir'];
         } else {
             /* Get the default value:  no good way to do this in Symfony 1.4. */
             $prod = sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . 'uploads';
         }
         $test = sfConfig::get('sf_test_dir');
         if ($prod == $test) {
             self::_halt(sprintf('Please specify a *separate* test value for sf_upload_dir in %s.', $this->_getSettingsFilename()));
         }
         /* Check the directory itself to make sure it's valid. */
         if (!file_exists($test)) {
             /* If it doesn't exist, let's see if we can't create it. */
             if (!mkdir($test, 0777, true)) {
                 self::_halt('Test upload directory (%s) does not exist.  Please create this directory before continuing.', $test);
             }
         } elseif (!is_dir($test)) {
             self::_halt('Test upload directory (%s) not a directory.', $test);
         }
         if (!is_writable($test)) {
             self::_halt('Test upload directory (%s) is not writable.', $test);
         }
         self::$_uploadsDirCheck = true;
     }
 }