Пример #1
0
 public function test_all_caches()
 {
     $cacheHandlers = array('cache_lite' => 1, 'akadodbcache' => 2);
     $memcacheEnabled = AkConfig::getOption('memcached_enabled', false);
     AkUnitTestSuite::createTestingDatabaseIfNotAvailable();
     if ($memcacheEnabled) {
         $cacheHandlers['akmemcache'] = 3;
     }
     $unitTests = array('_testInit', '_getAndSaveTests', '_removeTests', '_cleanTests');
     foreach ($cacheHandlers as $class => $type) {
         foreach ($unitTests as $test) {
             unset($this->Cache);
             $this->Cache = new AkCache();
             $this->{$test}($type, $class);
         }
         $this->Cache->clean($this->group);
     }
 }
Пример #2
0
defined('AK_FRAMEWORK_DIR') || define('AK_FRAMEWORK_DIR', AK_BASE_DIR);
defined('AK_TESTING_NAMESPACE') || define('AK_TESTING_NAMESPACE', 'akelos');
defined('AK_TESTING_URL') || define('AK_TESTING_URL', 'http://akelos.tests');
include_once AK_FRAMEWORK_DIR . DS . 'autoload.php';
if (AK_CLI && !AK_WIN) {
    // will try to set the right mode for tmp folders, git does not kee trac of this for us
    foreach ((array) glob(AK_BASE_DIR . DS . 'tmp' . DS . '*' . DS . '*/') as $__folder) {
        `chmod 777 {$__folder}`;
    }
    unset($__folder);
}
if (!AkConfig::getOption('testing_url', false)) {
    AkConfig::setOption('testing_url', AK_TESTING_URL);
}
AkUnitTestSuite::checkIfTestingWebserverIsAccesible(array('base_path' => AK_TEST_DIR . DS . AK_TESTING_NAMESPACE));
AkUnitTestSuite::createTestingDatabaseIfNotAvailable();
AkUnitTestSuite::ensureTmpDirPermissions();
try {
    ob_start();
    if (!class_exists('BaseActionController')) {
        class BaseActionController extends AkActionController
        {
        }
    }
    if (!class_exists('ApplicationController')) {
        class ApplicationController extends BaseActionController
        {
            public $layout = false;
        }
    }
    if (!class_exists('BaseActiveRecord')) {
Пример #3
0
 static function runFromOptions($options = array())
 {
     $default_options = array('base_path' => AK_TEST_DIR, 'TestSuite' => null, 'reporter' => AK_TEST_DEFAULT_REPORTER, 'files' => array());
     $options = array_merge($default_options, $options);
     $descriptions = array();
     if (!empty($options['files'])) {
         $full_paths = array();
         foreach ($options['files'] as $file) {
             list($suite, $case) = explode('/', $file . '/');
             $case = str_replace('.php', '', $case);
             $full_paths[] = $options['base_path'] . DS . $suite . DS . 'cases' . DS . $case . '.php';
             $descriptions[AkInflector::titleize($suite)][] = AkInflector::titleize($case);
         }
         $options['files'] = $full_paths;
     }
     AkUnitTestSuite::createTestingDatabaseIfNotAvailable();
     if (!empty($options['component'])) {
         $components = Ak::toArray($options['component']);
         $real_base_path = $options['base_path'];
         $options['description'] = '';
         $options['files'] = array();
         foreach ($components as $component) {
             $options['base_path'] = $real_base_path . DS . $component;
             if (empty($options['suites'])) {
                 $options['suites'] = array_diff(glob($options['base_path'] . DS . '*'), array(''));
             } else {
                 $options['suites'] = Ak::toArray($options['suites']);
             }
             $options['description'] .= AkInflector::titleize($component) . " unit tests: Suites(";
             foreach ($options['suites'] as $k => $suite) {
                 $suite_name = $options['suites'][$k] = trim(str_replace($options['base_path'] . DS, '', $suite), DS);
                 if (is_dir($options['base_path'] . DS . $suite_name)) {
                     $options['description'] .= $suite_name . ',';
                     $options['files'] = array_merge($options['files'], array_diff(glob($options['base_path'] . DS . $suite_name . DS . 'cases' . DS . '*.php'), array('')));
                 } else {
                     unset($options['suites'][$k]);
                 }
             }
             $options['description'] = str_replace(' Suites():', '', trim($options['description'], ', ') . "):\n");
             if (empty($options['title'])) {
                 $options['title'] = AkUnitTestSuite::getTestTitle($options);
             }
         }
     } else {
         $options['description'] = '';
         foreach ($descriptions as $suite => $cases) {
             $options['description'] .= "{$suite} (cases): " . $options['description'] . rtrim(join(', ', $cases), ', ') . "\n";
         }
         if (empty($options['description'])) {
             $options['description'] = AkInflector::titleize($options['suite']) . ' (suite)';
             $options['files'] = array_diff(glob($options['base_path'] . DS . $options['suite'] . DS . 'cases' . DS . '*.php'), array(''));
         }
         if (empty($options['title'])) {
             $suite_name = empty($options['suite']) ? preg_replace('/.+\\/([^\\/]+)\\/cases.+/', '$1', @$options['files'][0]) : $options['suite'];
             AkConfig::setOption('testing_url', AK_TESTING_URL);
             AkConfig::setOption('memcached_enabled', AkMemcache::isServerUp());
             AkUnitTestSuite::checkIfTestingWebserverIsAccesible($options);
             $dabase_settings = AK_DATABASE_SETTINGS_NAMESPACE == 'database' ? Ak::getSetting('database', 'type') : AK_DATABASE_SETTINGS_NAMESPACE;
             $options['title'] = "PHP " . phpversion() . ", Environment: " . AK_ENVIRONMENT . ", Database: " . $dabase_settings . (AkConfig::getOption('memcached_enabled', false) ? ', Memcached: enabled' : '') . (AkConfig::getOption('webserver_enabled', false) ? ', Testing URL: ' . AkConfig::getOption('testing_url') : ', Testing URL: DISABLED!!!') . "\n" . "Error reporting set to: " . AkConfig::getErrorReportingLevelDescription() . "\n" . trim($options['description']) . '';
         }
     }
     $options['TestSuite'] = new AkUnitTestSuite($options['title']);
     $options['TestSuite']->running_from_config = true;
     if (empty($options['files'])) {
         $component = AkInflector::underscore($options['component']);
         if (AkInflector::underscore(AK_APP_NAME) == $component) {
             $options['files'] = glob(AK_TEST_DIR . DS . 'unit' . DS . '*.php');
         } else {
             $options['files'] = glob(AK_TEST_DIR . DS . 'unit' . DS . $component . '*.php');
         }
         if (empty($options['files'])) {
             trigger_error('Could not find test cases to run.', E_USER_ERROR);
         }
     }
     foreach ($options['files'] as $file) {
         $options['TestSuite']->addFile($file);
     }
     //($options['TestSuite']->run(new $options['reporter']()) ? 0 : 1); file_put_contents(AK_LOG_DIR.DS.'included_files.php', var_export(get_included_files(), true)); return;
     exit($options['TestSuite']->run(new $options['reporter']()) ? AkUnitTestSuite::runOnFailure(@$options['on_failure']) : AkUnitTestSuite::runOnSuccess(@$options['on_success']));
 }