PageRenderTime 65ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/units/classes/php/tokenizer/iterators/phpScript.php

http://github.com/mageekguy/atoum
PHP | 309 lines | 288 code | 21 blank | 0 comment | 0 complexity | f366092a191aceb71d88556f1f6be966 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\php\tokenizer\iterators;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\php\tokenizer,
  6. mageekguy\atoum\php\tokenizer\iterators
  7. ;
  8. require_once __DIR__ . '/../../../../runner.php';
  9. class phpScript extends atoum\test
  10. {
  11. public function testClass()
  12. {
  13. $this
  14. ->testedClass
  15. ->isSubClassOf('mageekguy\atoum\php\tokenizer\iterators\phpNamespace')
  16. ;
  17. }
  18. public function test__construct()
  19. {
  20. $this
  21. ->if($this->newTestedInstance)
  22. ->then
  23. ->array($this->testedInstance->getConstants())->isEmpty()
  24. ->array($this->testedInstance->getClasses())->isEmpty()
  25. ->array($this->testedInstance->getNamespaces())->isEmpty()
  26. ->array($this->testedInstance->getImportations())->isEmpty()
  27. ;
  28. }
  29. public function testReset()
  30. {
  31. $this
  32. ->if($this->newTestedInstance)
  33. ->then
  34. ->object($this->testedInstance->reset())->isTestedInstance
  35. ->array($this->testedInstance->getConstants())->isEmpty()
  36. ->array($this->testedInstance->getClasses())->isEmpty()
  37. ->array($this->testedInstance->getNamespaces())->isEmpty()
  38. ->if(
  39. $this->testedInstance->appendConstant(new iterators\phpConstant()),
  40. $this->testedInstance->appendClass(new iterators\phpClass()),
  41. $this->testedInstance->appendNamespace(new iterators\phpNamespace())
  42. )
  43. ->then
  44. ->array($this->testedInstance->getConstants())->isNotEmpty()
  45. ->array($this->testedInstance->getClasses())->isNotEmpty()
  46. ->array($this->testedInstance->getNamespaces())->isNotEmpty()
  47. ->object($this->testedInstance->reset())->isTestedInstance
  48. ->array($this->testedInstance->getConstants())->isEmpty()
  49. ->array($this->testedInstance->getClasses())->isEmpty()
  50. ->array($this->testedInstance->getNamespaces())->isEmpty()
  51. ;
  52. }
  53. public function testAppendConstant()
  54. {
  55. $this
  56. ->if(
  57. $this->newTestedInstance,
  58. $constantIterator = new iterators\phpConstant(),
  59. $constantIterator
  60. ->append($token1 = new tokenizer\token(uniqid()))
  61. ->append($token2 = new tokenizer\token(uniqid()))
  62. )
  63. ->then
  64. ->object($this->testedInstance->appendConstant($constantIterator))->isTestedInstance
  65. ->array($this->testedInstance->getConstants())->isEqualTo(array($constantIterator))
  66. ->castToString($this->testedInstance)->isEqualTo($token1 . $token2)
  67. ;
  68. }
  69. public function testGetConstants()
  70. {
  71. $this
  72. ->if($this->newTestedInstance)
  73. ->then
  74. ->array($this->testedInstance->getConstants())->isEmpty()
  75. ->if($this->testedInstance->appendConstant($constantIterator = new iterators\phpConstant()))
  76. ->then
  77. ->array($this->testedInstance->getConstants())->isEqualTo(array($constantIterator))
  78. ->if($this->testedInstance->appendConstant($otherConstantIterator = new iterators\phpConstant()))
  79. ->then
  80. ->array($this->testedInstance->getConstants())->isEqualTo(array($constantIterator, $otherConstantIterator))
  81. ;
  82. }
  83. public function testGetConstant()
  84. {
  85. $this
  86. ->if($this->newTestedInstance)
  87. ->then
  88. ->variable($this->testedInstance->getConstant(rand(0, PHP_INT_MAX)))->isNull()
  89. ->if($this->testedInstance->appendConstant($constantIterator = new iterators\phpConstant()))
  90. ->then
  91. ->variable($this->testedInstance->getConstant(0))->isIdenticalTo($constantIterator)
  92. ->variable($this->testedInstance->getConstant(rand(1, PHP_INT_MAX)))->isNull()
  93. ->if($this->testedInstance->appendConstant($otherConstantIterator = new iterators\phpConstant()))
  94. ->then
  95. ->variable($this->testedInstance->getConstant(0))->isIdenticalTo($constantIterator)
  96. ->variable($this->testedInstance->getConstant(1))->isIdenticalTo($otherConstantIterator)
  97. ->variable($this->testedInstance->getConstant(rand(2, PHP_INT_MAX)))->isNull()
  98. ;
  99. }
  100. public function testAppendClass()
  101. {
  102. $this
  103. ->if(
  104. $this->newTestedInstance,
  105. $classIterator = new iterators\phpClass(),
  106. $classIterator
  107. ->append($token1 = new tokenizer\token(uniqid()))
  108. ->append($token2 = new tokenizer\token(uniqid()))
  109. )
  110. ->then
  111. ->object($this->testedInstance->appendClass($classIterator))->isTestedInstance
  112. ->array($this->testedInstance->getClasses())->isEqualTo(array($classIterator))
  113. ->castToString($this->testedInstance)->isEqualTo($token1 . $token2)
  114. ;
  115. }
  116. public function testGetClasses()
  117. {
  118. $this
  119. ->if($this->newTestedInstance)
  120. ->then
  121. ->array($this->testedInstance->getClasses())->isEmpty()
  122. ->if($this->testedInstance->appendClass($classIterator = new iterators\phpClass()))
  123. ->then
  124. ->array($this->testedInstance->getClasses())->isEqualTo(array($classIterator))
  125. ->if($this->testedInstance->appendClass($otherClassIterator = new iterators\phpClass()))
  126. ->then
  127. ->array($this->testedInstance->getClasses())->isEqualTo(array($classIterator, $otherClassIterator))
  128. ;
  129. }
  130. public function testGetClass()
  131. {
  132. $this
  133. ->if($this->newTestedInstance)
  134. ->then
  135. ->variable($this->testedInstance->getClass(rand(0, PHP_INT_MAX)))->isNull()
  136. ->if($this->testedInstance->appendClass($classIterator = new iterators\phpClass()))
  137. ->then
  138. ->variable($this->testedInstance->getClass(0))->isIdenticalTo($classIterator)
  139. ->variable($this->testedInstance->getClass(rand(1, PHP_INT_MAX)))->isNull()
  140. ->if($this->testedInstance->appendClass($otherClassIterator = new iterators\phpClass()))
  141. ->then
  142. ->variable($this->testedInstance->getClass(0))->isIdenticalTo($classIterator)
  143. ->variable($this->testedInstance->getClass(1))->isIdenticalTo($otherClassIterator)
  144. ->variable($this->testedInstance->getClass(rand(2, PHP_INT_MAX)))->isNull()
  145. ;
  146. }
  147. public function testAppendNamespace()
  148. {
  149. $this
  150. ->if(
  151. $this->newTestedInstance,
  152. $namespaceIterator = new iterators\phpNamespace(),
  153. $namespaceIterator
  154. ->append($token1 = new tokenizer\token(uniqid()))
  155. ->append($token2 = new tokenizer\token(uniqid()))
  156. )
  157. ->then
  158. ->object($this->testedInstance->appendNamespace($namespaceIterator))->isTestedInstance
  159. ->array($this->testedInstance->getNamespaces())->isEqualTo(array($namespaceIterator))
  160. ->castToString($this->testedInstance)->isEqualTo($token1 . $token2)
  161. ;
  162. }
  163. public function testGetNamespaces()
  164. {
  165. $this
  166. ->if($this->newTestedInstance)
  167. ->then
  168. ->array($this->testedInstance->getNamespaces())->isEmpty()
  169. ->if($this->testedInstance->appendNamespace($namespaceIterator = new iterators\phpNamespace()))
  170. ->then
  171. ->array($this->testedInstance->getNamespaces())->isEqualTo(array($namespaceIterator))
  172. ->if($this->testedInstance->appendNamespace($otherNamespaceIterator = new iterators\phpNamespace()))
  173. ->then
  174. ->array($this->testedInstance->getNamespaces())->isEqualTo(array($namespaceIterator, $otherNamespaceIterator))
  175. ;
  176. }
  177. public function testGetNamespace()
  178. {
  179. $this
  180. ->if($this->newTestedInstance)
  181. ->then
  182. ->variable($this->testedInstance->getNamespace(rand(0, PHP_INT_MAX)))->isNull()
  183. ->if($this->testedInstance->appendNamespace($namespaceIterator = new iterators\phpNamespace()))
  184. ->then
  185. ->variable($this->testedInstance->getNamespace(0))->isIdenticalTo($namespaceIterator)
  186. ->variable($this->testedInstance->getNamespace(rand(1, PHP_INT_MAX)))->isNull()
  187. ->if($this->testedInstance->appendNamespace($otherNamespaceIterator = new iterators\phpNamespace()))
  188. ->then
  189. ->variable($this->testedInstance->getNamespace(0))->isIdenticalTo($namespaceIterator)
  190. ->variable($this->testedInstance->getNamespace(1))->isIdenticalTo($otherNamespaceIterator)
  191. ->variable($this->testedInstance->getNamespace(rand(2, PHP_INT_MAX)))->isNull()
  192. ;
  193. }
  194. public function testAppendImportation()
  195. {
  196. $this
  197. ->if(
  198. $this->newTestedInstance,
  199. $importationIterator = new iterators\phpImportation(),
  200. $importationIterator
  201. ->append($token1 = new tokenizer\token(uniqid()))
  202. ->append($token2 = new tokenizer\token(uniqid()))
  203. )
  204. ->then
  205. ->object($this->testedInstance->appendImportation($importationIterator))->isTestedInstance
  206. ->array($this->testedInstance->getImportations())->isEqualTo(array($importationIterator))
  207. ->castToString($this->testedInstance)->isEqualTo($token1 . $token2)
  208. ;
  209. }
  210. public function testGetImportations()
  211. {
  212. $this
  213. ->if($this->newTestedInstance)
  214. ->then
  215. ->array($this->testedInstance->getImportations())->isEmpty()
  216. ->if($this->testedInstance->appendImportation($importationIterator = new iterators\phpImportation()))
  217. ->then
  218. ->array($this->testedInstance->getImportations())->isEqualTo(array($importationIterator))
  219. ->if($this->testedInstance->appendImportation($otherImportationIterator = new iterators\phpImportation()))
  220. ->then
  221. ->array($this->testedInstance->getImportations())->isEqualTo(array($importationIterator, $otherImportationIterator))
  222. ;
  223. }
  224. public function testGetImportation()
  225. {
  226. $this
  227. ->if($this->newTestedInstance)
  228. ->then
  229. ->variable($this->testedInstance->getImportation(rand(0, PHP_INT_MAX)))->isNull()
  230. ->if($this->testedInstance->appendImportation($importationIterator = new iterators\phpImportation()))
  231. ->then
  232. ->variable($this->testedInstance->getImportation(0))->isIdenticalTo($importationIterator)
  233. ->variable($this->testedInstance->getImportation(rand(1, PHP_INT_MAX)))->isNull()
  234. ->if($this->testedInstance->appendImportation($otherImportationIterator = new iterators\phpImportation()))
  235. ->then
  236. ->variable($this->testedInstance->getImportation(0))->isIdenticalTo($importationIterator)
  237. ->variable($this->testedInstance->getImportation(1))->isIdenticalTo($otherImportationIterator)
  238. ->variable($this->testedInstance->getImportation(rand(2, PHP_INT_MAX)))->isNull()
  239. ;
  240. }
  241. public function testAppendFunction()
  242. {
  243. $this
  244. ->if(
  245. $this->newTestedInstance,
  246. $functionIterator = new iterators\phpFunction(),
  247. $functionIterator
  248. ->append($token1 = new tokenizer\token(uniqid()))
  249. ->append($token2 = new tokenizer\token(uniqid()))
  250. )
  251. ->then
  252. ->object($this->testedInstance->appendFunction($functionIterator))->isTestedInstance
  253. ->array($this->testedInstance->getFunctions())->isEqualTo(array($functionIterator))
  254. ->castToString($this->testedInstance)->isEqualTo($token1 . $token2)
  255. ;
  256. }
  257. public function testGetFunctions()
  258. {
  259. $this
  260. ->if($this->newTestedInstance)
  261. ->then
  262. ->array($this->testedInstance->getFunctions())->isEmpty()
  263. ->if($this->testedInstance->appendFunction($functionIterator = new iterators\phpFunction()))
  264. ->then
  265. ->array($this->testedInstance->getFunctions())->isEqualTo(array($functionIterator))
  266. ->if($this->testedInstance->appendFunction($otherFunctionIterator = new iterators\phpFunction()))
  267. ->then
  268. ->array($this->testedInstance->getFunctions())->isEqualTo(array($functionIterator, $otherFunctionIterator))
  269. ;
  270. }
  271. public function testGetFunction()
  272. {
  273. $this
  274. ->if($this->newTestedInstance)
  275. ->then
  276. ->variable($this->testedInstance->getFunction(rand(0, PHP_INT_MAX)))->isNull()
  277. ->if($this->testedInstance->appendFunction($functionIterator = new iterators\phpFunction()))
  278. ->then
  279. ->variable($this->testedInstance->getFunction(0))->isIdenticalTo($functionIterator)
  280. ->variable($this->testedInstance->getFunction(rand(1, PHP_INT_MAX)))->isNull()
  281. ->if($this->testedInstance->appendFunction($otherFunctionIterator = new iterators\phpFunction()))
  282. ->then
  283. ->variable($this->testedInstance->getFunction(0))->isIdenticalTo($functionIterator)
  284. ->variable($this->testedInstance->getFunction(1))->isIdenticalTo($otherFunctionIterator)
  285. ->variable($this->testedInstance->getFunction(rand(2, PHP_INT_MAX)))->isNull()
  286. ;
  287. }
  288. }