Changeset 938
- Timestamp:
- 07/23/08 18:40:49 (3 months ago)
- Files:
-
- branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/VERSION (modified) (1 diff)
- branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/examples/RoutingTest.php (modified) (3 diffs)
- branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/lib/AkTestRequest.php (modified) (2 diffs)
- branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/lib/PHPUnit_Controller_TestCase.php (modified) (1 diff)
- branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/lib/PHPUnit_Routing_TestCase.php (modified) (4 diffs)
- branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/scripts/test_runner.php (modified) (7 diffs)
- branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/tests/fixtures/routes.php (modified) (1 diff)
- branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/tests/lib/RoutingTest.php (modified) (7 diffs)
- branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/tests/lib/TestRequestTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/VERSION
r670 r938 1 0.2. 41 0.2.5 branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/examples/RoutingTest.php
r663 r938 8 8 function testStandardRoute() 9 9 { 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'); 11 15 $this->assertController('blog'); 12 16 $this->assertAction('index'); … … 15 19 function test404() 16 20 { 17 $this->get(' should/not/match/anything/or');21 $this->get('/should/not/match/anything/or'); 18 22 $this->assert404(); 19 23 } … … 24 28 $this->connect('/:artist/:album',array('controller'=>'artist','action'=>'list')); 25 29 26 $this->get(' autechre/quaristice')->resolvesTo('autechre','quaristice','artist','list');30 $this->get('/autechre/quaristice')->resolvesTo('autechre','quaristice','artist','list'); 27 31 28 $this->get(' boys/girls');32 $this->get('/boys/girls'); 29 33 $this->assertController('artist'); 30 34 $this->assertAction('list'); branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/lib/AkTestRequest.php
r791 r938 4 4 { 5 5 6 private $parameters_from_url;7 8 6 static function createInstance($method,$params) 9 7 { 10 8 $Request = new AkTestRequest(); 11 9 $Request->addParamsToRequest($params); 12 $Request->setRequestMethod($method);13 $Request->parameters_from_url = $params;14 10 return $Request; 15 11 } … … 23 19 } 24 20 25 function setRequestMethod($method)26 {27 $this->_requestedMethod = $method;28 }29 30 // mocked31 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 46 21 } 47 22 branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/lib/PHPUnit_Controller_TestCase.php
r669 r938 49 49 { 50 50 $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; 52 66 } 53 67 branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/lib/PHPUnit_Routing_TestCase.php
r670 r938 14 14 protected $params; 15 15 private $reciprocity = false; 16 private $errors = false; 16 17 17 18 function setUp() … … 40 41 } 41 42 42 function connect($url_pattern, $options = array(), $requirements = null)43 function connect($url_pattern, $options = array(), $requirements = array()) 43 44 { 44 45 $this->Router->connect($url_pattern, $options, $requirements); 45 46 } 46 47 47 function testReciprocity($bool = true)48 function checkReciprocity($bool = true) 48 49 { 49 50 return $this->reciprocity = $bool; … … 52 53 /** 53 54 * @param string $url 54 * @return AkRouterSpec55 * @return PHPUnit_Routing_TestCase 55 56 */ 56 57 function get($url) 57 58 { 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; 61 67 } 62 68 return $this; 63 69 } 64 70 65 private function encloseWithSlashes($string)71 private function createRequest($url,$method='get') 66 72 { 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; 68 82 } 69 83 … … 97 111 private function ensureNoMatch() 98 112 { 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."); 100 114 } 101 115 102 116 private function ensureMatch() 103 117 { 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; 105 124 } 106 125 branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/scripts/test_runner.php
r663 r938 9 9 private $test_suite; 10 10 private $options = array('verbose'=>false); 11 private $filename_filter; 12 private $consider_covers_files = 'white'; // white, black, or false 11 13 12 14 static function main($args=null) … … 56 58 while (count($args) > 0){ 57 59 $arg = array_shift($args); 58 if ($this-> tryToAddToSuite($this->suite(),$arg)) continue;60 if ($this->addFile($this->suite(),$arg)) continue; 59 61 else switch ($arg){ 60 62 case '-v': … … 62 64 break; 63 65 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; 64 84 default: 65 $this-> drawHelp();85 $this->addFilter($arg); 66 86 break; 67 87 } … … 69 89 } 70 90 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; 76 135 $suite->addTestFile((string)$file,false); 77 136 }elseif (is_dir($file)){ … … 83 142 } 84 143 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 85 185 /** 86 186 * @return PHPUnit_Framework_TestSuite … … 91 191 $files = new RecursiveDirectoryIterator($path); 92 192 foreach ($files as $file){ 93 $this-> tryToAddToSuite($suite,$file);193 $this->addFile($suite,$file); 94 194 } 95 195 return $suite; … … 106 206 Usage: 107 207 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. 208 test_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 217 This script creates TestSuites on-the fly and runs them. 218 It will exclude filenames or folders which start with an underscore. As a 219 convention it will not run filenames which end with <_TestCase.php> but instead 220 include them. This is so because 'TestCases' use to be abstract classes which 221 contain common methods or a special Test-Api. 222 223 You can exclude or include groups, methods and/or files. 224 A minus [-] means 'except', a plus means 'only'. E.g.: 225 226 > test_runner -v -slow -test*Postgre + DbAdap*.php tests/ 227 228 This will search through all files in the folder <tests/> and its subfolders, 229 include the one which filename begins with <DbAdap> and exclude the tests which 230 belong to a group called <slow> or which method name matches <test.*Postgre>. 231 232 So how does this work. We take the sign -|+ to decide if we exclude or include 233 the following parameter. The parameter gets parsed: if it begins with <test> we 234 take it as an method-name, if it ends with <.php> we say its a filename, 235 otherwise it should be a group name. You can use a <*> to match "any character". 236 You 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 244 If you have xdebug you can generate a code-coverage report with 245 246 > test_runner --report folder_to_save_to 247 248 You can whitelist or blacklist files from this report with +c and -c. If you 249 place a file with the name <covers> somewhere in your test-folders with the 250 following content f.i. 251 252 LIB/AkRequest/* 253 APP/controllers/person_controller.php 254 255 it will take all the specified files and folders to this list. The script expands 256 following constants: LIB, BASE, APP, FWK (=Framework dir). 257 113 258 114 259 BANNER; 260 echo '(xdebug '.(extension_loaded('xdebug') ? 'enabled)' : 'disabled)'); 115 261 exit; 116 262 branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/tests/fixtures/routes.php
r663 r938 3 3 // You can find more about routes on /lib/AkRouters.php and /test/test_AkRouter.php 4 4 5 $Map->connect('/:controller/:action/:id', array('controller' => 'page', 'action' => 'index', 'id'=>OPTIONAL),array('id'=>'/\d{1,}/'));6 5 $Map->connect('/', array('controller' => 'page', 'action' => 'index')); 7 6 $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,}')); 10 10 11 11 ?> branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/tests/lib/RoutingTest.php
r669 r938 11 11 function testShouldResolveUrl() 12 12 { 13 $this->get(' blog/add/1');13 $this->get('/blog/add/1'); 14 14 15 15 $this->assertController('blog'); … … 20 20 function testShouldResolveToAdminModule() 21 21 { 22 $this->get('/admin/user/add /');22 $this->get('/admin/user/add'); 23 23 24 24 $this->assertParameterEquals('admin','module'); … … 29 29 function testRouteToAdminLogs() 30 30 { 31 $this->get('/admin/logs/warnings /show/1');32 $this->assertModule('admin /logs');33 $this->assertController(' warnings');34 $this->assertAction(' show');35 $this->assert Id(1);31 $this->get('/admin/logs/warnings'); 32 $this->assertModule('admin'); 33 $this->assertController('logs'); 34 $this->assertAction('list'); 35 $this->assertParameterEquals('warnings','type'); 36 36 } 37 37 38 38 function testRouteToArtistAlbumTags() 39 39 { 40 $this->get(' autechre/quaristice/tags');40 $this->get('/autechre/quaristice/tags'); 41 41 $this->assertController('tags'); 42 42 $this->assertArtist('autechre'); … … 46 46 function testAssertIdIsNotSet() 47 47 { 48 $this->get(' blog/add/');48 $this->get('/blog/add/'); 49 49 $this->assertParameterNotSet('id'); 50 50 } … … 52 52 function testAssertUnrecognizedUrl() 53 53 { 54 $this->get(' blog/post/something/here/or/leave');54 $this->get('/blog/post/something/here/or/leave'); 55 55 $this->assert404(); 56 56 } … … 58 58 function testShouldMoanAboutWrongController() 59 59 { 60 $this->get(' blog');60 $this->get('/blog'); 61 61 try { 62 62 $this->assertController('post_or_whatever'); … … 71 71 function testShouldMoanAboutWrongAction() 72 72 { 73 $this->get(' blog/add');73 $this->get('/blog/add'); 74 74 try { 75 75 $this->assertAction('remove_or_whatever'); branches/new-router/app/vendor/plugins/PHPUnit_TestSuite/tests/lib/TestRequestTest.php
r669 r938 5 5 6 6 /** 7 * @var Ak TestRequest7 * @var AkRequest 8 8 */ 9 9 var $Request; 10 10 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()); # localhost29 #var_dump($Request->getHostWithPort()); # localhost30 #var_dump($Request->getMethod()); # env->request_method31 #var_dump($Request->getLocaleFromUrl()); #32 #var_dump($Request->getPath()); # env->request_uri33 #var_dump($Request->getPathParameters());# possibly orhpaned34 }35 36 11 function testGetRequest() 37 12 { … … 79 54 { 80 55 $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; 82 70 } 83 71
