Author: maksim_ka
Date: 2010-02-03 13:07:51 +0100 (Wed, 03 Feb 2010)
New Revision: 27484

Modified:
   plugins/sfPhpunitPlugin/branches/1.2/lib/task/sfPhpunitRuntestTask.class.php
Log:
[sfPhpunitPlugin]

Modified: 
plugins/sfPhpunitPlugin/branches/1.2/lib/task/sfPhpunitRuntestTask.class.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.2/lib/task/sfPhpunitRuntestTask.class.php    
    2010-02-03 12:00:05 UTC (rev 27483)
+++ 
plugins/sfPhpunitPlugin/branches/1.2/lib/task/sfPhpunitRuntestTask.class.php    
    2010-02-03 12:07:51 UTC (rev 27484)
@@ -2,6 +2,7 @@
 
 require_once 'PHPUnit/Framework.php';
 require_once 'PHPUnit/TextUI/TestRunner.php';
+require_once 'PHPUnit/TextUI/Command.php';
 
 /**
  * Symfony task that provide more flexable way to run tests.
@@ -15,13 +16,17 @@
 {
   protected function configure()
   {
-    // // add your own arguments here
     $this->addArguments(array(
-      new sfCommandArgument('test', sfCommandArgument::OPTIONAL, 'Name of test 
to run', ''),
-    ));
-
-    //$this->addOptions(array());
-
+      new sfCommandArgument('test', sfCommandArgument::OPTIONAL, 'Name of test 
to run', '')));
+    
+    $this->addOptions(array(
+      new sfCommandOption('log-junit', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The connection name', null),
+      new sfCommandOption('log-pmd', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The connection name', null),
+      new sfCommandOption('log-metrics', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The connection name', null),
+      new sfCommandOption('coverage-clover', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The connection name', null),
+      new sfCommandOption('coverage-html', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The connection name', null)));
+    
+    
     $this->namespace        = 'phpunit';
     $this->name             = 'runtest';
     $this->briefDescription = 'Runs PHPUnit tests';
@@ -44,11 +49,99 @@
 //    $initTask = new sfPhpunitInitTask($this->dispatcher, $this->formatter);
 //    $initTask->run();
     chdir(sfConfig::get('sf_root_dir'));
-    shell_exec('./symfony phpunit:init');
+    shell_exec('php symfony phpunit:init');
        
        $path = $arguments['test'];
-       
-    $runner = new PHPUnit_TextUI_TestRunner();
-    $runner->doRun(sfPhpunitSuiteLoader::factory($path)->getSuite());
+//    
+//     $result = 
sfPhpunitSuiteLoader::factory($path)->run($this->_getResult($options));
+//    $result->flushListeners();
+//    
+//    $printer = new PHPUnit_TextUI_ResultPrinter();
+//    $printer->printResult($result);
+
+//     $command = new sfPhpunitCommand();
+//     
+//     $a = $_SERVER['argv'];
+//     unset($a[0], $a[1]);
+//    $a[0] = 'test.php';
+//    $a[1] = 'test.php';
+//    ksort($a);       
+//     $command->convertSymfonyOptionsToPhpunit($a);
+//
+//     var_Dump($a, $command->getArguments());
+//     die;
+//     
+//     
+       $runner = new PHPUnit_TextUI_TestRunner();
+    $runner->doRun(
+      sfPhpunitSuiteLoader::factory($path)->getSuite(), 
+      $this->_handleArguments($options));
   }
+  
+//  /**
+//   * @return PHPUnit_Framework_TestResult
+//   */
+//  protected function _getResult(array $options = array())
+//  {
+////    $arguments = array();
+////    
+////    if ($options['colors']) $arguments['colors'] = true;
+////    if ($options['verbose']) $arguments['verbose'] = true;
+////    if ($options['debug']) $arguments['debug'] = true;
+////    
+////    if ($options['log-junit']) $arguments['junitLogfile'] = 
$options['log-junit'];
+////    if ($options['log-junit']) $arguments['junitLogfile'] = 
$options['log-junit'];
+////    
+////    
+////    return $arguments;
+////    
+////    
+//    $printer = new PHPUnit_TextUI_ResultPrinter();
+//    $printer->write(PHPUnit_Runner_Version::getVersionString() . "\n\n");
+//    
+//    $result = new PHPUnit_Framework_TestResult();
+//    $result->addListener($printer);
+//    
+//    if ($options['log-junit']) {
+//      require_once 'PHPUnit/Util/Log/JUnit.php';
+//      $result->addListener(new PHPUnit_Util_Log_JUnit($options['log-junit'], 
true));
+//      $result->collectCodeCoverageInformation(TRUE);
+//    }
+//   
+//    
+//    return $result;
+//  }
+  
+  protected function _handleArguments(array $options = array())
+  {
+    $arguments = array();
+    
+    if ($options['log-junit']) {
+      $arguments['junitLogfile'] = $options['log-junit'];
+    }
+    if ($options['coverage-clover']) {
+      if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
+        $arguments['coverageClover'] = $options['coverage-clover'];
+      } else {
+        if (!extension_loaded('tokenizer')) {
+          throw new Exception('For the `coverage-clover` option need to be 
loaded tokenizer extension.');
+        } else {
+          throw new Exception('For the `coverage-clover` option need to be 
loaded Xdebug extension.');
+        }
+      }
+    }
+    if ($options['coverage-html']) {
+      if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
+        $arguments['reportDirectory'] = $options['coverage-html'];
+      } else {
+        if (!extension_loaded('tokenizer')) {
+          throw new Exception('For the `coverage-html` option need to be 
loaded tokenizer extension.');
+        } else {
+          throw new Exception('For the `coverage-html` option need to be 
loaded Xdebug extension.');
+        }
+      }
+    }
+    
+    return $arguments;
+  }
 }
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to