Author: Marcin.Chylek
Date: 2010-05-07 08:30:54 +0200 (Fri, 07 May 2010)
New Revision: 29381

Modified:
   plugins/symfonyUnderControlPlugin/trunk/lib/SymfonyUnderControlTest.class.php
   
plugins/symfonyUnderControlPlugin/trunk/lib/SymfonyUnderControlTestOutput.class.php
   
plugins/symfonyUnderControlPlugin/trunk/lib/task/sfTestUnderControlTask.class.php
Log:
Intercept bad tests and return status

Modified: 
plugins/symfonyUnderControlPlugin/trunk/lib/SymfonyUnderControlTest.class.php
===================================================================
--- 
plugins/symfonyUnderControlPlugin/trunk/lib/SymfonyUnderControlTest.class.php   
    2010-05-06 18:22:44 UTC (rev 29380)
+++ 
plugins/symfonyUnderControlPlugin/trunk/lib/SymfonyUnderControlTest.class.php   
    2010-05-07 06:30:54 UTC (rev 29381)
@@ -67,10 +67,6 @@
     $this->time_spent = $time_end - $time_start;
 
     $this->parseTestOutput();
-
-    // exit status helps to detect failed builds
-    if( strpos( $this->output, 'Failed test' ) !== false && strpos( 
$this->output, 'not ok' ) !== false )
-      exit( 1 );
   }
 
   /**
@@ -347,5 +343,4 @@
   {
     return str_replace(sfConfig::get('sf_root_dir') . '/', '', $file);
   }
-
-}
\ No newline at end of file
+}

Modified: 
plugins/symfonyUnderControlPlugin/trunk/lib/SymfonyUnderControlTestOutput.class.php
===================================================================
--- 
plugins/symfonyUnderControlPlugin/trunk/lib/SymfonyUnderControlTestOutput.class.php
 2010-05-06 18:22:44 UTC (rev 29380)
+++ 
plugins/symfonyUnderControlPlugin/trunk/lib/SymfonyUnderControlTestOutput.class.php
 2010-05-07 06:30:54 UTC (rev 29381)
@@ -4,7 +4,9 @@
 
 class SymfonyUnderControlTestOutput extends SymfonyUnderControlOutput 
implements SymfonyUnderControlOutputInterface
 {
-  
+  private
+    $failureCount = 0;
+
   /**
    * Write the XML to the file specified in the constructor
    *
@@ -17,9 +19,21 @@
     //}
     $xml = $this->buildXML();
     file_put_contents($this->path . '/undercontrol.xml', $xml);
+
+    return $xml;
   }
-  
+
   /**
+   * Get count Failure test
+   *
+   * @return int Count Failure test
+   */
+  public function getFailureCount()
+  {
+    return $this->failureCount;
+  }
+
+  /**
    * Build the XML from the test results
    *
    * @return string xUnit XML
@@ -27,40 +41,40 @@
   public function buildXML()
   {
     $this->loadBaseXML();
-    
+
     $alltests = $this->addTestSuite('All Tests');
-    
+
     $failure_count = 0;
     $test_count = 0;
     $assertion_count = 0;
     $total_time = 0;
-    
+
     foreach ( $this->tests as $type => $tests )
     {
       $current_suite = $this->addTestSuite($type, $alltests);
-      
+
       $type_failure = 0;
       $type_test = 0;
       $type_assertion = 0;
       $type_time = 0;
-      
+
       foreach ( $tests as $test )
       {
         $test_count ++;
         $type_test ++;
-        
+
         $asserts = $test->getAsserts();
-        
+
         $current_case = $this->addTestcase($current_suite, $test->getName());
         $current_case ['file'] = $test->getFilename();
         $current_case ['assertions'] = $test->getNumberOfAssertions();
         $current_case ['time'] = $test->getTimeSpent();
-        
+
         $assertion_count = $assertion_count + $test->getNumberOfAssertions();
         $type_assertion = $type_assertion + $test->getNumberOfAssertions();
         $total_time = $total_time + $test->getTimeSpent();
         $type_time = $type_time + $test->getTimeSpent();
-        
+
         foreach ( $asserts as $assert_number => $assert )
         {
           if (! empty($assert_number))
@@ -74,30 +88,32 @@
           }
         }
       }
-      
+
       $current_suite ['tests'] = $type_test;
       $current_suite ['assertions'] = $type_assertion;
       $current_suite ['failures'] = $type_failure;
       $current_suite ['errors'] = 0;
       $current_suite ['time'] = $type_time;
-    
+
     }
-    
+
     $alltests ['tests'] = $test_count;
     $alltests ['assertions'] = $assertion_count;
     $alltests ['failures'] = $failure_count;
     $alltests ['errors'] = 0;
     $alltests ['time'] = $total_time;
-    
+
+    $this->failureCount = $failure_count;
+
     return $this->xml->asXml();
   }
-  
+
   protected function loadBaseXML()
   {
     $this->xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?>
             <testsuites></testsuites>');
   }
-  
+
   protected function addTestSuite($name, $suite = '')
   {
     if (empty($suite))
@@ -111,24 +127,24 @@
     $returnsuite ['name'] = $name;
     return $returnsuite;
   }
-  
+
   protected function getTestSuite($name)
   {
     return $this->xml->xpath("//testsui...@name='" . $name . "']'");
   }
-  
+
   protected function addTestcase($suite, $name, $value = null)
   {
     $returncase = $suite->addChild('testcase', $value);
     $returncase ['name'] = $name . 'class';
     return $returncase;
   }
-  
+
   protected function getTestcase($name)
   {
     return $this->xml->xpath("//testca...@name='" . $name . "']'");
   }
-  
+
   protected function addFailure($testcase, $failure)
   {
     $failure = $testcase->addChild('failure', $failure);

Modified: 
plugins/symfonyUnderControlPlugin/trunk/lib/task/sfTestUnderControlTask.class.php
===================================================================
--- 
plugins/symfonyUnderControlPlugin/trunk/lib/task/sfTestUnderControlTask.class.php
   2010-05-06 18:22:44 UTC (rev 29380)
+++ 
plugins/symfonyUnderControlPlugin/trunk/lib/task/sfTestUnderControlTask.class.php
   2010-05-07 06:30:54 UTC (rev 29381)
@@ -1,14 +1,14 @@
 <?php
 /**
  * Task to execute the symfonyUnderControl testing
- * 
+ *
  * @package symfonyUnderControlPlugin
  * @author Stefan Koopmanschap <[email protected]>
  *
  */
 class sfTestUnderControlTask extends sfBaseTask
 {
-       
+
        /**
         * @see sfTask
         */
@@ -18,7 +18,7 @@
     $this->addArguments(array(
       new sfCommandArgument('path', sfCommandArgument::REQUIRED, 'Output path 
for XML'),
     ));
-    
+
     $this->addOptions(array(
       new sfCommandOption('enable-coverage', null, 
sfCommandOption::PARAMETER_NONE, 'Enable code coverage metrics (requires 
Xdebug)'),
     ));
@@ -39,7 +39,7 @@
 Optionally, you can add the [--enable-coverage|COMMENT] option to enable code 
coverage analysis. This option requires the Xdebug PHP extension to be enabled.
 EOF;
   }
-  
+
   /**
    * @see sfTask
    */
@@ -47,39 +47,43 @@
   {
     $output = new SymfonyUnderControlTestOutput($arguments['path']);
        $test_dir = sfConfig::get('sf_test_dir');
-       
+
     $finder = sfFinder::type('file')->follow_link()->name('*Test.php');
                $tests = $finder->in($test_dir . '/unit');
 
                $testObjects = array();
-               
+
                foreach($tests as $test)
                {
-                       $testObj = new SymfonyUnderControlTest($test, 
SymfonyUnderControlTest::TEST_UNIT);              
+                       $testObj = new SymfonyUnderControlTest($test, 
SymfonyUnderControlTest::TEST_UNIT);
                        $testObjects[] = $testObj;
                        $testObj->runTest($output);
                }
-               
+
                $functests = $finder->in($test_dir . '/functional');
-               
+
                foreach($functests as $functest)
                {
                  $testObj = new SymfonyUnderControlTest($functest, 
SymfonyUnderControlTest::TEST_FUNC);
                  $testObj->runTest($output);
                }
-               
+
                $output->writeToFile();
-               
+
                // code coverage support
-               if ($options['enable-coverage'])
+               if($options['enable-coverage'])
                {
                  $coverage_output = new 
SymfonyUnderControlCoverageOutput($arguments['path']);
                  foreach($testObjects as $test)
                  {
                    $test->runCoverage($coverage_output);
                  }
-                 
+
                  $coverage_output->writeToFile();
                }
+
+               // exit status helps to detect failed builds
+    if( $output->getFailureCount() > 0 )
+      exit( 1 );
   }
-}
+}
\ 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