PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/protected/vendor/codeception/verify/src/Codeception/Verify.php

https://gitlab.com/I-NOZex/quiz
PHP | 307 lines | 249 code | 55 blank | 3 comment | 17 complexity | c5215bf2d418a681819f4896e918e669 MD5 | raw file
  1. <?php
  2. namespace Codeception;
  3. use PHPUnit_Framework_Assert as a;
  4. class Verify {
  5. protected $actual = null;
  6. protected $description = '';
  7. protected $isFileExpectation = false;
  8. public function __construct($description)
  9. {
  10. $descriptionGiven = (func_num_args() == 2);
  11. if (!$descriptionGiven) {
  12. $this->actual = $description;
  13. } else {
  14. $actual = func_get_args();
  15. $this->actual = $actual[1];
  16. $this->description = $description;
  17. }
  18. }
  19. /**
  20. * @param boolean $isFileExpectation
  21. */
  22. public function setIsFileExpectation($isFileExpectation)
  23. {
  24. $this->isFileExpectation = $isFileExpectation;
  25. }
  26. public function equals($expected)
  27. {
  28. if ( ! $this->isFileExpectation ) {
  29. a::assertEquals($expected, $this->actual, $this->description);
  30. } else {
  31. a::assertFileEquals($expected, $this->actual, $this->description);
  32. }
  33. }
  34. public function notEquals($expected)
  35. {
  36. if ( ! $this->isFileExpectation ) {
  37. a::assertNotEquals($expected, $this->actual, $this->description);
  38. } else {
  39. a::assertFileNotEquals($expected, $this->actual, $this->description);
  40. }
  41. }
  42. public function contains($needle)
  43. {
  44. a::assertContains($needle, $this->actual, $this->description);
  45. }
  46. public function notContains($needle)
  47. {
  48. a::assertNotContains($needle, $this->actual, $this->description);
  49. }
  50. public function greaterThan($expected)
  51. {
  52. a::assertGreaterThan($expected, $this->actual, $this->description);
  53. }
  54. public function lessThan($expected)
  55. {
  56. a::assertLessThan($expected, $this->actual, $this->description);
  57. }
  58. public function greaterOrEquals($expected)
  59. {
  60. a::assertGreaterThanOrEqual($expected, $this->actual, $this->description);
  61. }
  62. public function lessOrEquals($expected)
  63. {
  64. a::assertLessThanOrEqual($expected, $this->actual, $this->description);
  65. }
  66. public function true()
  67. {
  68. a::assertTrue($this->actual, $this->description);
  69. }
  70. public function false()
  71. {
  72. a::assertFalse($this->actual, $this->description);
  73. }
  74. public function null()
  75. {
  76. a::assertNull($this->actual, $this->description);
  77. }
  78. public function notNull()
  79. {
  80. a::assertNotNull($this->actual, $this->description);
  81. }
  82. public function isEmpty()
  83. {
  84. a::assertEmpty($this->actual, $this->description);
  85. }
  86. public function notEmpty()
  87. {
  88. a::assertNotEmpty($this->actual, $this->description);
  89. }
  90. public function hasKey($key)
  91. {
  92. a::assertArrayHasKey($key, $this->actual, $this->description);
  93. }
  94. public function hasntKey($key)
  95. {
  96. a::assertArrayNotHasKey($key, $this->actual, $this->description);
  97. }
  98. public function isInstanceOf($class)
  99. {
  100. a::assertInstanceOf($class, $this->actual, $this->description);
  101. }
  102. public function isNotInstanceOf($class)
  103. {
  104. a::assertNotInstanceOf($class, $this->actual, $this->description);
  105. }
  106. public function internalType($type)
  107. {
  108. a::assertInternalType($type, $this->actual, $this->description);
  109. }
  110. public function notInternalType($type)
  111. {
  112. a::assertNotInternalType($type, $this->actual, $this->description);
  113. }
  114. public function hasAttribute($attribute)
  115. {
  116. if (is_string($attribute)) {
  117. a::assertClassHasAttribute($attribute, $this->actual, $this->description);
  118. } else {
  119. a::assertObjectHasAttribute($attribute, $this->actual, $this->description);
  120. }
  121. }
  122. public function notHasAttribute($attribute)
  123. {
  124. if (is_string($attribute)) {
  125. a::assertClassNotHasAttribute($attribute, $this->actual, $this->description);
  126. } else {
  127. a::assertObjectNotHasAttribute($attribute, $this->actual, $this->description);
  128. }
  129. }
  130. public function hasStaticAttribute($attribute)
  131. {
  132. a::assertClassHasStaticAttribute($attribute, $this->actual, $this->description);
  133. }
  134. public function notHasStaticAttribute($attribute)
  135. {
  136. a::assertClassNotHasStaticAttribute($attribute, $this->actual, $this->description);
  137. }
  138. public function containsOnly($type, $isNativeType = NULL)
  139. {
  140. a::assertContainsOnly($type, $this->actual, $isNativeType, $this->description);
  141. }
  142. public function notContainsOnly($type, $isNativeType = NULL)
  143. {
  144. a::assertNotContainsOnly($type, $this->actual, $isNativeType, $this->description);
  145. }
  146. public function containsOnlyInstancesOf($class)
  147. {
  148. a::assertContainsOnlyInstancesOf($class, $this->actual, $this->description);
  149. }
  150. public function count($array)
  151. {
  152. a::assertCount($array, $this->actual, $this->description);
  153. }
  154. public function notCount($array)
  155. {
  156. a::assertNotCount($array, $this->actual, $this->description);
  157. }
  158. public function equalXMLStructure($xml, $checkAttributes = FALSE)
  159. {
  160. a::assertEqualXMLStructure($xml, $this->actual, $checkAttributes, $this->description);
  161. }
  162. public function exists()
  163. {
  164. if (!$this->isFileExpectation ) {
  165. throw new \Exception('exists() expectation should be called with expect_file()');
  166. }
  167. a::assertFileExists($this->actual, $this->description);
  168. }
  169. public function notExists()
  170. {
  171. if (!$this->isFileExpectation ) {
  172. throw new \Exception('notExists() expectation should be called with expect_file()');
  173. }
  174. a::assertFileNotExists($this->actual, $this->description);
  175. }
  176. public function equalsJsonFile($file)
  177. {
  178. if (!$this->isFileExpectation ) {
  179. a::assertJsonStringEqualsJsonFile($file, $this->actual, $this->description);
  180. } else {
  181. a::assertJsonFileEqualsJsonFile($file, $this->actual, $this->description);
  182. }
  183. }
  184. public function equalsJsonString($string)
  185. {
  186. a::assertJsonStringEqualsJsonString($string, $this->actual, $this->description);
  187. }
  188. public function regExp($expression)
  189. {
  190. a::assertRegExp($expression, $this->actual, $this->description);
  191. }
  192. public function matchesFormat($format)
  193. {
  194. a::assertStringMatchesFormat($format, $this->actual, $this->description);
  195. }
  196. public function notMatchesFormat($format)
  197. {
  198. a::assertStringNotMatchesFormat($format, $this->actual, $this->description);
  199. }
  200. public function matchesFormatFile($formatFile)
  201. {
  202. a::assertStringMatchesFormatFile($formatFile, $this->actual, $this->description);
  203. }
  204. public function notMatchesFormatFile($formatFile)
  205. {
  206. a::assertStringNotMatchesFormatFile($formatFile, $this->actual, $this->description);
  207. }
  208. public function same($expected)
  209. {
  210. a::assertSame($expected, $this->actual, $this->description);
  211. }
  212. public function notSame($expected)
  213. {
  214. a::assertNotSame($expected, $this->actual, $this->description);
  215. }
  216. public function endsWith($suffix)
  217. {
  218. a::assertStringEndsWith($suffix, $this->actual, $this->description);
  219. }
  220. public function notEndsWith($suffix)
  221. {
  222. a::assertStringEndsNotWith($suffix, $this->actual, $this->description);
  223. }
  224. public function equalsFile($file)
  225. {
  226. a::assertStringEqualsFile($file, $this->actual, $this->description);
  227. }
  228. public function notEqualsFile($file)
  229. {
  230. a::assertStringNotEqualsFile($file, $this->actual, $this->description);
  231. }
  232. public function startsWith($prefix)
  233. {
  234. a::assertStringStartsWith($prefix, $this->actual, $this->description);
  235. }
  236. public function notStartsWith($prefix)
  237. {
  238. a::assertStringStartsNotWith($prefix, $this->actual, $this->description);
  239. }
  240. public function equalsXmlFile($file)
  241. {
  242. if (!$this->isFileExpectation ) {
  243. a::assertXmlStringEqualsXmlFile($file, $this->actual, $this->description);
  244. } else {
  245. a::assertXmlFileEqualsXmlFile($file, $this->actual, $this->description);
  246. }
  247. }
  248. public function equalsXmlString($xmlString)
  249. {
  250. a::assertXmlStringEqualsXmlString($xmlString, $this->actual, $this->description);
  251. }
  252. }