| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 10 require_once('limb/wact/src/annotation/WactClassAnnotationParser.class.php'); 11 require_once(dirname(__FILE__) . '/ListenerStub.class.php'); 12 13 class PartialListener { 14 function endClass(){} 15 } 16 17 Mock :: generate('PartialListener'); 18 19 class WactClassAnnotationParserTest extends UnitTestCase 20 { 21 protected $listener; 22 23 function setUp() { 24 $this->listener = new ListenerStub(); 25 } 26 27 function testAnnotationWithTypeOnly() 28 { 29 $source = <<<EOD 30 <?php 31 /* 32 * @param 33 */ 34 ?> 35 EOD; 36 $tokenizer = new WactClassAnnotationParser(); 37 $tokenizer->process($this->listener, $source); 38 39 $this->assertEqual($this->listener->history, array(array('annotation', 'param', NULL))); 40 } 41 42 function testAnnotationWithTypeAndTitle() 43 { 44 $source = <<<EOD 45 <?php 46 /* 47 * @param one 48 * @param two 49 */ 50 ?> 51 EOD; 52 $tokenizer = new WactClassAnnotationParser(); 53 $tokenizer->process($this->listener, $source); 54 55 $this->assertEqual($this->listener->history, array(array('annotation', 'param', 'one'), 56 array('annotation', 'param', 'two'))); 57 } 58 59 function testPHP5DocStyleAnnotation() { 60 $source = <<<EOD 61 <?php 62 /** 63 * @param one 64 * @param two 65 */ 66 ?> 67 EOD; 68 $tokenizer = new WactClassAnnotationParser(); 69 $tokenizer->process($this->listener, $source); 70 71 $this->assertEqual($this->listener->history, array(array('annotation', 'param', 'one'), 72 array('annotation', 'param', 'two'))); 73 } 74 75 function testIdentedAnnotation() 76 { 77 $source = <<<EOD 78 <?php 79 /** 80 * @param one 81 * @param two 82 */ 83 ?> 84 EOD; 85 $tokenizer = new WactClassAnnotationParser(); 86 $tokenizer->process($this->listener, $source); 87 88 $this->assertEqual($this->listener->history, array(array('annotation', 'param', 'one'), 89 array('annotation', 'param', 'two'))); 90 } 91 92 function testGenericClassToken() 93 { 94 $source = <<<EOD 95 <?php 96 97 class Foo{} 98 99 ?> 100 EOD; 101 $tokenizer = new WactClassAnnotationParser(); 102 $tokenizer->process($this->listener, $source); 103 104 $this->assertEqual($this->listener->history, array(array('beginClass', 'Foo', NULL), 105 array('endClass'))); 106 } 107 108 function testChildClassToken() 109 { 110 $source = <<<EOD 111 <?php 112 113 class Foo extends Bar{} 114 115 ?> 116 EOD; 117 $tokenizer = new WactClassAnnotationParser(); 118 $tokenizer->process($this->listener, $source); 119 120 $this->assertEqual($this->listener->history, array(array('beginClass', 'Foo', 'Bar'), 121 array('endClass'))); 122 } 123 124 function testPropertyToken() 125 { 126 $source = <<<EOD 127 <?php 128 129 class Foo 130 { 131 var \$null; 132 var \$property = 'value'; 133 } 134 135 ?> 136 EOD; 137 $tokenizer = new WactClassAnnotationParser(); 138 $tokenizer->process($this->listener, $source); 139 140 $this->assertEqual($this->listener->history, array(array('beginClass', 'Foo', NULL), 141 array('property', 'null', 'public'), 142 array('property', 'property', 'public'), 143 array('endClass'))); 144 } 145 146 function testMethodToken() 147 { 148 $source = <<<EOD 149 <?php 150 151 class Foo 152 { 153 function Foo() 154 { 155 do{}while(1=1); 156 } 157 } 158 ?> 159 EOD; 160 $tokenizer = new WactClassAnnotationParser(); 161 162 $tokenizer->process($this->listener, $source); 163 164 $this->assertEqual($this->listener->history, array(array('beginClass', 'Foo', NULL), 165 array('method', 'Foo'), 166 array('endClass'))); 167 } 168 169 function testMethodTokendAndIgnoreFunction() 170 { 171 $source = <<<EOD 172 <?php 173 174 class Foo 175 { 176 function Foo(){} 177 } 178 179 function Ignore(){} 180 181 ?> 182 EOD; 183 $tokenizer = new WactClassAnnotationParser(); 184 185 $tokenizer->process($this->listener, $source); 186 187 $this->assertEqual($this->listener->history, array(array('beginClass', 'Foo', NULL), 188 array('method', 'Foo'), 189 array('endClass'))); 190 } 191 192 function testOnlyExistingMethodsOfListenerGetInvoked() 193 { 194 $source = <<<EOD 195 <?php 196 197 class Foo{} 198 ?> 199 EOD; 200 $listener = new MockPartialListener(); 201 $listener->expectOnce('endClass'); 202 203 $tokenizer = new WactClassAnnotationParser(); 204 $tokenizer->process($listener, $source); 205 } 206 } 207 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jan 8 04:06:23 2009 | Cross-referenced by PHPXref 0.7 |