Changeset 325

Show
Ignore:
Timestamp:
08/27/07 09:56:57 (1 year ago)
Author:
bermiferrer
Message:

Adding pre/post test processing for avoiding repetition on unit tests.

Now instead of

<?php
defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true);
require_once(dirname(__FILE__).'/../../../fixtures/config/config.php');

class PostTest extends AkUnitTest {
    function test_Post() {
        $this->assertTrue( true );
    }
}

ak_test('PostTest',true);

?>

You can use

<?php

class PostTestCase extends AkUnitTest {
    function test_Post() {
        $this->assertTrue( true );
    }
}

?>

Notice the difference between PostTest? and PostTestCase?, if you want this to happen automatically for you, your test case class must end in TestCase?. Existing tests will not be affected by this change.

./script/test will take care of loading the configuration and calling the ak_test function for you.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/script/test

    r129 r325  
    2121error_reporting(E_ALL); 
    2222 
     23defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true); 
     24require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'test'.DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); 
     25 
    2326$argv = array_map('trim',$argv); 
    2427array_shift($argv); 
    2528 
    2629$tests_dir = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'test'); 
     30$____skip_tests = array('Simple','Unit','Web','AkWeb'); 
     31 
    2732foreach ($argv as $_test_file){ 
    2833    $_test_file = strstr($_test_file,'.php') ? trim($_test_file, '/') : $_test_file.'.php'; 
     
    3338    }else{ 
    3439        require($_test_file); 
     40            foreach(get_declared_classes() as $____class){ 
     41                if(preg_match('/(.+)TestCase$/i', $____class, $match)){ 
     42                    if(!preg_match('/^('.join('|',$____skip_tests).')$/i',$match[1])){ 
     43                        $____skip_tests[] = $match[1]; 
     44                        Ak::trace(join(',',$____skip_tests)); 
     45                        ak_test($match[1].'TestCase', true); 
     46                    } 
     47                } 
     48            } 
     49        echo $_test_file."\n"; 
    3550    } 
    3651} 
    3752 
    38 echo $_test_file; 
    3953 
    40 echo "\n"; 
     54 
    4155 
    4256?> 
  • trunk/test/app.php

    r266 r325  
    66define('ALL_TESTS_RUNNER',true); 
    77 
    8 define('AK_TEST_DATABASE_ON', true); 
     8defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true); 
     9 
    910require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); 
    1011 
  • trunk/test/unit.php

    r2 r325  
    66define('ALL_TESTS_RUNNER',true); 
    77 
    8 define('AK_TEST_DATABASE_ON', true); 
     8defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true); 
    99require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); 
    1010