Show
Ignore:
Timestamp:
03/10/2008 11:03:30 AM (10 months ago)
Author:
Geert
Message:

Unit_Test library now throws nice Kohana_Exceptions in case of invalid test paths or other fatal conflicts.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/unit_test/libraries/Unit_Test.php

    r2272 r2273  
    2323        public function __construct() 
    2424        { 
    25                 // Normalize all given test paths 
     25                // Loop over each given test path 
    2626                foreach (func_get_args() as $path) 
    2727                { 
    28                         $this->paths[] = str_replace('\\', '/', realpath($path)); 
    29                 } 
    30  
    31                 // Recursively iterate over all test paths 
    32                 foreach ($this->paths as $test_path) 
    33                 { 
     28                        // Normalize all given test paths and store them 
     29                        $this->paths[] = $test_path = str_replace('\\', '/', realpath((string) $path)); 
     30 
     31                        // Validate test path 
     32                        if ( ! is_dir($test_path)) 
     33                                throw new Kohana_Exception('unit_test.invalid_test_path', $test_path); 
     34 
     35                        // Recursively iterate over each file in the test path 
    3436                        foreach 
    3537                        ( 
     
    4850                                $class = substr($path, strrpos($path, '/') + 1, -(strlen(EXT))); 
    4951 
     52                                // Check for duplicate test class name 
     53                                if (class_exists($class, FALSE)) 
     54                                        throw new Kohana_Exception('unit_test.duplicate_test_class', $class, $path); 
     55 
    5056                                // Include the test class 
    5157                                include_once $path; 
    5258 
    53                                 // Validate the class name 
     59                                // Check whether the test class has been found and loaded 
    5460                                if ( ! class_exists($class, FALSE)) 
    55                                         continue; 
     61                                        throw new Kohana_Exception('unit_test.test_class_not_found', $class, $path); 
    5662 
    5763                                // Reverse-engineer Test class 
     
    6066                                // Test classes must extend Unit_Test_Case 
    6167                                if ( ! $reflector->isSubclassOf(new ReflectionClass('Unit_Test_Case'))) 
    62                                         break; 
     68                                        throw new Kohana_Exception('unit_test.test_class_extends', $class); 
    6369 
    6470                                // Loop through all the class methods