예제 #1
0
파일: tests.php 프로젝트: azuya/Wi3
 /**
  * Configures the environment for testing
  *
  * Does the following:
  *
  * * Loads the phpunit framework (for the web ui)
  * * Restores exception phpunit error handlers (for cli)
  * * registeres an autoloader to load test files
  */
 public static function configure_environment($do_whitelist = TRUE, $do_blacklist = TRUE)
 {
     // During a webui request we need to manually load PHPUnit
     if (!class_exists('PHPUnit_Util_Filter', FALSE) and !function_exists('phpunit_autoload')) {
         try {
             include_once 'PHPUnit/Autoload.php';
         } catch (ErrorException $e) {
             include_once 'PHPUnit/Framework.php';
         }
     }
     // Allow PHPUnit to handle exceptions and errors
     if (Kohana::$is_cli) {
         restore_exception_handler();
         restore_error_handler();
     }
     spl_autoload_register(array('Kohana_Tests', 'autoload'));
     Kohana_Tests::$cache = ($cache = Kohana::cache('unittest_whitelist_cache')) === NULL ? array() : $cache;
     // As of PHPUnit v3.5 there are slight differences in the way files are black|whitelisted
     self::$phpunit_v35 = function_exists('phpunit_autoload');
     $config = Kohana::config('unittest');
     if ($do_whitelist and $config->use_whitelist) {
         self::whitelist();
     }
     if ($do_blacklist and count($config['blacklist'])) {
         Kohana_Tests::blacklist($config->blacklist);
     }
 }
예제 #2
0
 /**
  * Configures the enviroment for testing
  *
  * Does the following:
  *
  * * Loads the phpunit framework (for the web ui)
  * * Restores exception phpunit error handlers (for cli)
  * * registeres an autoloader to load test files
  */
 public static function configure_enviroment($do_whitelist = TRUE, $do_blacklist = TRUE)
 {
     if (!class_exists('PHPUnit_Util_Filter', FALSE)) {
         // Make sure the PHPUnit classes are available
         require_once 'PHPUnit/Framework.php';
     }
     if (Kohana::$is_cli) {
         restore_exception_handler();
         restore_error_handler();
     }
     spl_autoload_register(array('Kohana_Tests', 'autoload'));
     Kohana_Tests::$cache = ($cache = Kohana::cache('phpunit_whitelist_cache')) === NULL ? array() : $cache;
     $config = Kohana::config('phpunit');
     if ($do_whitelist and $config->use_whitelist) {
         self::whitelist();
     }
     if ($do_blacklist and count($config['blacklist'])) {
         foreach ($config->blacklist as $item) {
             if (is_dir($item)) {
                 PHPUnit_Util_Filter::addDirectoryToFilter($item);
             } else {
                 PHPUnit_Util_Filter::addFileToFilter($item);
             }
         }
     }
 }
예제 #3
0
<?php

// If we're on the CLI then PHPUnit will already be loaded
if (class_exists('PHPUnit_Util_Filter', FALSE)) {
    Kohana_Tests::configure_enviroment();
    // Stop kohana from processing the request
    define('SUPPRESS_REQUEST', TRUE);
} else {
    if (Kohana_Tests::enabled()) {
        // People shouldn't be running unit tests on their production server
        // so we assume that this /could/ be a web ui request on the dev server
        // and include phpunit so that modules can add specific files to the blacklist
        require_once 'PHPUnit/Framework.php';
    }
}
Route::set('unittest', '(phpunit(/<action>(/<id>)))')->defaults(array('controller' => 'phpunit', 'action' => 'index'));
예제 #4
0
 /**
  * Whitelists a specified set of modules specified by the user
  *
  * @param array $modules
  */
 protected function whitelist(array $modules)
 {
     $k_modules = Kohana::modules();
     $whitelist = array();
     // Make sure our whitelist is valid
     foreach ($modules as $item) {
         if (isset($k_modules[$item])) {
             $whitelist[$item] = $k_modules[$item];
         } elseif ($item === 'k_app') {
             $whitelist[$item] = APPPATH;
         } elseif ($item === 'k_sys') {
             $whitelist[$item] = SYSPATH;
         }
     }
     if (count($whitelist)) {
         Kohana_Tests::whitelist($whitelist);
     }
     return $whitelist;
 }
예제 #5
0
파일: init.php 프로젝트: azuya/Wi3
<?php

// If we're on the CLI then PHPUnit will already be loaded
if (class_exists('PHPUnit_Util_Filter', FALSE) or function_exists('phpunit_autoload')) {
    Kohana_Tests::configure_environment();
    // Stop kohana from processing the request
    define('SUPPRESS_REQUEST', TRUE);
}
Route::set('unittest', 'unittest(/<action>)')->defaults(array('controller' => 'unittest', 'action' => 'index'));