Changeset 938

Show
Ignore:
Timestamp:
07/23/08 18:40:49 (3 months ago)
Author:
kaste
Message:

Updated and merged PHPUnit_TestSuite v0.2.5 that is r924.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/VERSION

    r670 r938  
    1 0.2.4 
     10.2.5 
  • branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/examples/RoutingTest.php

    r663 r938  
    88    function testStandardRoute() 
    99    { 
    10         $this->get('blog/index'); 
     10        // after parametrizing the url, check if the router  
     11        // can build the same given url from these parameters  
     12        $this->checkReciprocity();  
     13         
     14        $this->get('/blog'); 
    1115        $this->assertController('blog'); 
    1216        $this->assertAction('index'); 
     
    1519    function test404() 
    1620    { 
    17         $this->get('should/not/match/anything/or'); 
     21        $this->get('/should/not/match/anything/or'); 
    1822        $this->assert404(); 
    1923    } 
     
    2428        $this->connect('/:artist/:album',array('controller'=>'artist','action'=>'list')); 
    2529 
    26         $this->get('autechre/quaristice')->resolvesTo('autechre','quaristice','artist','list'); 
     30        $this->get('/autechre/quaristice')->resolvesTo('autechre','quaristice','artist','list'); 
    2731         
    28         $this->get('boys/girls'); 
     32        $this->get('/boys/girls'); 
    2933        $this->assertController('artist'); 
    3034        $this->assertAction('list'); 
  • branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/lib/AkTestRequest.php

    r791 r938  
    44{ 
    55 
    6     private $parameters_from_url; 
    7      
    86    static function createInstance($method,$params) 
    97    { 
    108        $Request = new AkTestRequest(); 
    119        $Request->addParamsToRequest($params); 
    12         $Request->setRequestMethod($method); 
    13         $Request->parameters_from_url = $params;     
    1410        return $Request; 
    1511    } 
     
    2319    } 
    2420     
    25     function setRequestMethod($method) 
    26     { 
    27         $this->_requestedMethod = $method; 
    28     } 
    29      
    30     // mocked 
    31     function getMethod() 
    32     { 
    33         return $this->_requestedMethod; 
    34     } 
    35      
    36     function getRelativeUrlRoot() 
    37     { 
    38         return ''; 
    39     } 
    40      
    41     function getParametersFromRequestedUrl() 
    42     { 
    43         return $this->parameters_from_url; 
    44     } 
    45      
    4621} 
    4722 
  • branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/lib/PHPUnit_Controller_TestCase.php

    r669 r938  
    4949    { 
    5050        $params = array_merge(array('controller'=>$this->controller_name,'action'=>$action),$options); 
    51         return $this->Request = AkTestRequest::createInstance($method,$params); 
     51 
     52        $Request = $this->getMock('AkRequest',array('getMethod','getParametersFromRequestedUrl'),array(),'',false); 
     53        $Request->expects($this->any()) 
     54                ->method('getMethod') 
     55                ->will($this->returnValue($method)); 
     56        $Request->expects($this->any()) 
     57                ->method('getParametersFromRequestedUrl') 
     58                ->will($this->returnValue($params)); 
     59                 
     60        // HACK  fix ->getParams 
     61        foreach ($params as $k=>$v){ 
     62            $Request->$k = $v; 
     63            $Request->_request[$k] = $v; 
     64        }//HACK 
     65        return $this->Request = $Request; 
    5266    } 
    5367     
  • branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/lib/PHPUnit_Routing_TestCase.php

    r670 r938  
    1414    protected $params; 
    1515    private   $reciprocity = false; 
     16    private   $errors = false; 
    1617 
    1718    function setUp() 
     
    4041    } 
    4142 
    42     function connect($url_pattern, $options = array(), $requirements = null
     43    function connect($url_pattern, $options = array(), $requirements = array()
    4344    { 
    4445        $this->Router->connect($url_pattern, $options, $requirements); 
    4546    } 
    4647     
    47     function testReciprocity($bool = true) 
     48    function checkReciprocity($bool = true) 
    4849    { 
    4950        return $this->reciprocity = $bool; 
     
    5253    /** 
    5354     * @param string $url 
    54      * @return AkRouterSpec 
     55     * @return PHPUnit_Routing_TestCase 
    5556     */ 
    5657    function get($url) 
    5758    { 
    58         $this->params = $this->Router->toParams($url); 
    59         if ($this->reciprocity && $this->params){ 
    60             $this->assertEquals($this->encloseWithSlashes($url), $this->Router->toUrl($this->params)); 
     59        $Request = $this->createRequest($url); 
     60        try { 
     61            $this->params = $this->Router->match($Request); 
     62            if ($this->reciprocity){ 
     63                $this->assertEquals($url, $this->Router->urlize($this->params)->path()); 
     64            } 
     65        }catch (NoMatchingRouteException $e){ 
     66            $this->errors = true; 
    6167        } 
    6268        return $this; 
    6369    } 
    6470     
    65     private function encloseWithSlashes($string
     71    private function createRequest($url,$method='get'
    6672    { 
    67         return $string == '/' || $string == '' ? '/' : '/'.trim($string,'/').'/'; 
     73        $Request = $this->getMock('AkRequest',array('getMethod','getRequestedUrl'),array(),'',false); 
     74        $Request->expects($this->any()) 
     75                ->method('getMethod') 
     76                ->will($this->returnValue($method)); 
     77        $Request->expects($this->any()) 
     78                ->method('getRequestedUrl') 
     79                ->will($this->returnValue($url)); 
     80                 
     81        return $Request; 
    6882    } 
    6983     
     
    97111    private function ensureNoMatch() 
    98112    { 
    99         if ($this->params) $this->fail("Expected no match, actually got a match."); 
     113        if (!$this->hasErrors()) $this->fail("Expected no match, actually got a match."); 
    100114    } 
    101115     
    102116    private function ensureMatch() 
    103117    { 
    104         if (!$this->params) $this->fail("Expected a match, actually got no match."); 
     118        if ($this->hasErrors()) $this->fail("Expected a match, actually got no match."); 
     119    } 
     120     
     121    private function hasErrors() 
     122    { 
     123        return $this->errors; 
    105124    } 
    106125     
  • branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/scripts/test_runner.php

    r663 r938  
    99    private $test_suite; 
    1010    private $options = array('verbose'=>false); 
     11    private $filename_filter; 
     12    private $consider_covers_files = 'white';  // white, black, or false 
    1113     
    1214    static function main($args=null) 
     
    5658        while (count($args) > 0){ 
    5759            $arg = array_shift($args); 
    58             if ($this->tryToAddToSuite($this->suite(),$arg)) continue; 
     60            if ($this->addFile($this->suite(),$arg)) continue; 
    5961            else switch ($arg){ 
    6062                case '-v': 
     
    6264                    break; 
    6365                case '-?': 
     66                    $this->drawHelp(); 
     67                    break; 
     68                case '-c': 
     69                case '+c': 
     70                case '!c': 
     71                    $sign = $arg{0}; 
     72                    if ($sign=='-') $this->consider_covers_files = 'black'; 
     73                    elseif ($sign=='+') $this->consider_covers_files = 'white'; 
     74                    elseif ($sign=='!') $this->consider_covers_files = false; 
     75                    break; 
     76                case '--report': 
     77                    if (!extension_loaded('xdebug')) continue; 
     78                    $this->options['reportDirectory'] = array_shift($args); 
     79                    break; 
     80                case '-': 
     81                case '+': 
     82                    $this->addFilter($arg.array_shift($args)); 
     83                    break; 
    6484                default: 
    65                     $this->drawHelp(); 
     85                    $this->addFilter($arg); 
    6686                    break; 
    6787            } 
     
    6989    } 
    7090     
    71     function tryToAddToSuite(PHPUnit_Framework_TestSuite &$suite,$file) 
    72     { 
    73         if (substr($file,0,1)=='_'){ 
    74             return false; 
    75         }elseif (is_file($file)){ 
     91    private function addFilter($arg) 
     92    { 
     93        switch ($arg{0}){ 
     94            case '-': $mode = 'sub'; break; 
     95            case '+': $mode = 'add'; break; 
     96            default: return false;  
     97        } 
     98 
     99        $param = substr($arg,1); 
     100        switch ($this->typeOfFilter($param)){ 
     101            case 'method': 
     102                $pattern = str_replace('*','.*',$param); 
     103                if ($mode=='add'){ 
     104                    $pattern = "/^$pattern/"; 
     105                    $this->options['filter'] = $pattern; 
     106                }else{ 
     107                    //conditional regex-pattern:  
     108                    //if <$pattern> matches, the actual method-name must begin with 'tset' which is always false 
     109                    $pattern = "/^(?(?=$pattern)tset)/"; 
     110                    $this->options['filter'] = $pattern; 
     111                } 
     112                break; 
     113            case 'group': 
     114                $mode == 'add' ? $this->options['groups'][] = $param : $this->options['excludeGroups'][] = $param; 
     115                break; 
     116            case 'filename': 
     117                $pattern = str_replace(array('\\','.','*'),array('\\\\','\.','.*'),$param); 
     118                 
     119                $this->filename_filter = $mode == 'add' ? "/$pattern$/" : "/^(?(?=.*$pattern$).*hph$)/";   
     120                break; 
     121        } 
     122    } 
     123     
     124    private function typeOfFilter($param) 
     125    { 
     126        if (substr($param,0,4)=='test') return 'method'; 
     127        if (substr($param,-4)=='.php')  return 'filename'; 
     128        return 'group'; 
     129    } 
     130     
     131    private function addFile(PHPUnit_Framework_TestSuite &$suite,$file) 
     132    { 
     133        if (is_file($file)){ 
     134            if (!$this->ensureValidFilename((string)$file)) return false; 
    76135            $suite->addTestFile((string)$file,false); 
    77136        }elseif (is_dir($file)){ 
     
    83142    } 
    84143     
     144    private function ensureValidFilename($file) 
     145    { 
     146        if ($file{0}=='_') return false; 
     147         
     148        if (basename($file)=='covers'){ 
     149            $this->handleCoverageFilter($file); 
     150            return false; 
     151        } 
     152        if (substr($file,-13)=='_TestCase.php'){ 
     153            require_once $file; 
     154            return false; 
     155        } 
     156         
     157        if (substr($file,-4)!='.php') return false; 
     158         
     159        if ($this->filename_filter){ 
     160            if (preg_match($this->filename_filter,$file)) return true; 
     161            return false; 
     162        } 
     163         
     164        return true; 
     165    } 
     166     
     167    private function handleCoverageFilter($file) 
     168    { 
     169        if ($this->consider_covers_files == false) return; 
     170        $data = file_get_contents($file); 
     171        foreach (explode("\n",$data) as $line){ 
     172            $file = str_replace(array('BASE','APP','LIB','FWK','*'),array(AK_BASE_DIR,AK_APP_DIR,AK_LIB_DIR,AK_FRAMEWORK_DIR,''),$line); 
     173            if (is_file($file)){ 
     174                $this->consider_covers_files == 'white' ? 
     175                    PHPUnit_Util_Filter::addFileToWhitelist($file) : 
     176                    PHPUnit_Util_Filter::addFileToFilter($file); 
     177            }elseif (is_dir($file)){ 
     178                $this->consider_covers_files == 'white' ? 
     179                    PHPUnit_Util_Filter::addDirectoryToWhitelist($file) : 
     180                    PHPUnit_Util_Filter::addDirectoryToFilter($file); 
     181            } 
     182        } 
     183    } 
     184     
    85185    /** 
    86186     * @return PHPUnit_Framework_TestSuite 
     
    91191        $files = new RecursiveDirectoryIterator($path); 
    92192        foreach ($files as $file){ 
    93             $this->tryToAddToSuite($suite,$file); 
     193            $this->addFile($suite,$file); 
    94194        } 
    95195        return $suite; 
     
    106206Usage: 
    107207 
    108 test_runner [-v] [tests/test-suites/folders] 
    109    -v   verbose 
    110    -?   this help 
    111  
    112 This script creates TestSuites on-the fly and runs them. It will exclude filenames or folders which start with an underscore. 
     208test_runner [-v|?] [-|+group] [-|+method] [-|+filename] <filenames|folders> 
     209   -v              verbose 
     210   -?              this help 
     211   -+group         see below 
     212   -+method 
     213   -+file 
     214   --report folder write html-coverage-report to the specified folder 
     215   -+!c            black- or whitelist or ignore covers-file (s.b.)  
     216 
     217This script creates TestSuites on-the fly and runs them.  
     218It will exclude filenames or folders which start with an underscore. As a  
     219convention it will not run filenames which end with <_TestCase.php> but instead 
     220include them. This is so because 'TestCases' use to be abstract classes which  
     221contain common methods or a special Test-Api. 
     222 
     223You can exclude or include groups, methods and/or files. 
     224A minus [-] means 'except', a plus means 'only'. E.g.:  
     225 
     226>  test_runner -v -slow -test*Postgre + DbAdap*.php tests/ 
     227 
     228This will search through all files in the folder <tests/> and its subfolders,  
     229include the one which filename begins with <DbAdap> and exclude the tests which 
     230belong to a group called <slow> or which method name matches <test.*Postgre>. 
     231 
     232So how does this work. We take the sign -|+ to decide if we exclude or include  
     233the following parameter. The parameter gets parsed: if it begins with <test> we 
     234take it as an method-name, if it ends with <.php> we say its a filename,  
     235otherwise it should be a group name. You can use a <*> to match "any character". 
     236You can specify multiple groups, but only one methodname or filename pattern. 
     237 
     238> test_runner tests/ -postgre -sqlite 
     239> test_runner tests/ +mysql 
     240> test_runner tests/ + Request*.php 
     241> test_runner tests/AkRequest/ tests/AkRouter/ 
     242> test_runner tests/ +test*Cast*Null 
     243 
     244If you have xdebug you can generate a code-coverage report with 
     245 
     246> test_runner --report folder_to_save_to 
     247 
     248You can whitelist or blacklist files from this report with +c and -c. If you 
     249place a file with the name <covers> somewhere in your test-folders with the  
     250following content f.i. 
     251 
     252 LIB/AkRequest/* 
     253 APP/controllers/person_controller.php 
     254 
     255it will take all the specified files and folders to this list. The script expands  
     256following constants: LIB, BASE, APP, FWK (=Framework dir). 
     257 
    113258 
    114259BANNER; 
     260        echo '(xdebug '.(extension_loaded('xdebug') ? 'enabled)' : 'disabled)'); 
    115261        exit; 
    116262         
  • branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/tests/fixtures/routes.php

    r663 r938  
    33// You can find more about routes on /lib/AkRouters.php and /test/test_AkRouter.php 
    44 
    5 $Map->connect('/:controller/:action/:id', array('controller' => 'page', 'action' => 'index', 'id'=>OPTIONAL),array('id'=>'/\d{1,}/')); 
    65$Map->connect('/', array('controller' => 'page', 'action' => 'index')); 
    76$Map->connect('/:artist/:album/tags',array('controller'=>'tags')); 
    8 $Map->connect('/admin/logs/:controller/:action/:id',array('module'=>'admin/logs')); 
    9 $Map->connect('/:module/:controller/:action/:id',array('action'=>COMPULSORY)); 
     7$Map->connect('/admin/logs/:type',array('module'=>'admin','controller'=>'logs','action'=>'list','type'=>'all')); 
     8$Map->connect('/admin/:controller/:action/:id',array('module'=>'admin','action'=>COMPULSORY)); 
     9$Map->connect('/:controller/:action/:id', array('controller' => 'page', 'action' => 'index'),array('id'=>'\d{1,}')); 
    1010 
    1111?> 
  • branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/tests/lib/RoutingTest.php

    r669 r938  
    1111    function testShouldResolveUrl() 
    1212    { 
    13         $this->get('blog/add/1'); 
     13        $this->get('/blog/add/1'); 
    1414 
    1515        $this->assertController('blog'); 
     
    2020    function testShouldResolveToAdminModule() 
    2121    { 
    22         $this->get('/admin/user/add/'); 
     22        $this->get('/admin/user/add'); 
    2323 
    2424        $this->assertParameterEquals('admin','module'); 
     
    2929    function testRouteToAdminLogs() 
    3030    { 
    31         $this->get('/admin/logs/warnings/show/1'); 
    32         $this->assertModule('admin/logs'); 
    33         $this->assertController('warnings'); 
    34         $this->assertAction('show'); 
    35         $this->assertId(1); 
     31        $this->get('/admin/logs/warnings'); 
     32        $this->assertModule('admin'); 
     33        $this->assertController('logs'); 
     34        $this->assertAction('list'); 
     35        $this->assertParameterEquals('warnings','type'); 
    3636    } 
    3737     
    3838    function testRouteToArtistAlbumTags() 
    3939    { 
    40         $this->get('autechre/quaristice/tags'); 
     40        $this->get('/autechre/quaristice/tags'); 
    4141        $this->assertController('tags'); 
    4242        $this->assertArtist('autechre'); 
     
    4646    function testAssertIdIsNotSet() 
    4747    { 
    48         $this->get('blog/add/'); 
     48        $this->get('/blog/add/'); 
    4949        $this->assertParameterNotSet('id'); 
    5050    } 
     
    5252    function testAssertUnrecognizedUrl() 
    5353    { 
    54         $this->get('blog/post/something/here/or/leave'); 
     54        $this->get('/blog/post/something/here/or/leave'); 
    5555        $this->assert404(); 
    5656    } 
     
    5858    function testShouldMoanAboutWrongController() 
    5959    { 
    60         $this->get('blog'); 
     60        $this->get('/blog'); 
    6161        try { 
    6262            $this->assertController('post_or_whatever'); 
     
    7171    function testShouldMoanAboutWrongAction() 
    7272    { 
    73         $this->get('blog/add'); 
     73        $this->get('/blog/add'); 
    7474        try { 
    7575            $this->assertAction('remove_or_whatever'); 
  • branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/tests/lib/TestRequestTest.php

    r669 r938  
    55 
    66    /** 
    7      * @var AkTestRequest 
     7     * @var AkRequest 
    88     */ 
    99    var $Request; 
    1010     
    11     function testInvestigateRequest() 
    12     { 
    13         $Request = new AkRequest(); 
    14         $Request->_request['ak'] = 'blog/show/1'; 
    15         $Request->_request['q']  = 'wer'; 
    16          
    17         $Router = new AkRouter(); 
    18         $Router->connect(':controller/:action/:id'); 
    19         $Request->checkForRoutedRequests($Router); 
    20  
    21         $this->assertEquals(array( 
    22             'controller'=>'blog', 
    23             'action'=>'show', 
    24             'id'=>1, 
    25             'q'=>'wer', 
    26             'ak'=>'blog/show/1'),$Request->getParameters());     # we don't need the 'ak'-key, do we? 
    27         #var_dump($Request->getRequestUri());    # http://localhost/ 
    28         #var_dump($Request->getHost());          # localhost 
    29         #var_dump($Request->getHostWithPort());  # localhost 
    30         #var_dump($Request->getMethod());        # env->request_method 
    31         #var_dump($Request->getLocaleFromUrl()); # 
    32         #var_dump($Request->getPath());          # env->request_uri     
    33         #var_dump($Request->getPathParameters());# possibly orhpaned        
    34     } 
    35          
    3611    function testGetRequest() 
    3712    { 
     
    7954    { 
    8055        $params = array_merge(array('controller'=>$this->controller_name,'action'=>$action),$options); 
    81         return $this->Request = AkTestRequest::createInstance($method,$params); 
     56 
     57        $Request = $this->getMock('AkRequest',array('getMethod','getParametersFromRequestedUrl'),array(),'',false); 
     58        $Request->expects($this->any()) 
     59                ->method('getMethod') 
     60                ->will($this->returnValue($method)); 
     61        $Request->expects($this->any()) 
     62                ->method('getParametersFromRequestedUrl') 
     63                ->will($this->returnValue($params)); 
     64                 
     65        // HACK  fix ->getParams 
     66        foreach ($params as $k=>$v){ 
     67            $Request->_request[$k] = $v; 
     68        }//HACK 
     69        return $this->Request = $Request; 
    8270    } 
    8371