| Total Complexity | 139 |
| Total Lines | 1500 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Assert often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Assert, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class Assert { |
||
| 18 | const IN_TIME_EXECUTION_STRATEGY = 1; |
||
| 19 | const DELAYED_EXECUTION_STRATEGY = 2; |
||
| 20 | /** |
||
| 21 | * @var mixed actual value or variable that will be matched to expectations. |
||
| 22 | */ |
||
| 23 | protected $actual; |
||
| 24 | /** |
||
| 25 | * @var StepsList list of steps that was made prior current assert. |
||
| 26 | */ |
||
| 27 | protected $stepsList; |
||
| 28 | /** |
||
| 29 | * @var string description of expectation. If expectation fails this description will be displayed in console. |
||
| 30 | */ |
||
| 31 | protected $description; |
||
| 32 | /** |
||
| 33 | * @var \SplQueue list of steps that was delayed to be executed after definition. |
||
| 34 | */ |
||
| 35 | protected $delayedAssertSteps; |
||
| 36 | /** |
||
| 37 | * @var int execution strategy. Either {@link DELAYED_EXECUTION_STRATEGY} or {@link IN_TIME_EXECUTION_STRATEGY}. |
||
| 38 | * Identifies whether to run assert methods when they called or later(runtime matchers functionality) |
||
| 39 | */ |
||
| 40 | protected $strategy; |
||
| 41 | /** |
||
| 42 | * @var string internal value that identifies current step name that would be added to {@link stepsList} |
||
| 43 | */ |
||
| 44 | private $currentStepName = ''; |
||
| 45 | |||
| 46 | public function __construct(StepsList $stepsList, $actual, $description = '', $strategy = self::IN_TIME_EXECUTION_STRATEGY) { |
||
| 47 | $this->stepsList = $stepsList; |
||
| 48 | $this->actual = $actual; |
||
| 49 | $this->description = $description; |
||
| 50 | $this->delayedAssertSteps = new \SplQueue(); |
||
| 51 | $this->strategy = $strategy; |
||
| 52 | } |
||
| 53 | |||
| 54 | public function __clone() { |
||
| 55 | $this->delayedAssertSteps = clone $this->delayedAssertSteps; |
||
| 56 | } |
||
| 57 | |||
| 58 | //region --------------------------- OWN METHODS ----------------------------// |
||
| 59 | |||
| 60 | public function getActualValue() { |
||
| 61 | return $this->actual; |
||
| 62 | } |
||
| 63 | |||
| 64 | public function changeDescriptionTo($newDescription) { |
||
| 65 | $this->description = $newDescription; |
||
| 66 | } |
||
| 67 | |||
| 68 | public function changeCurrentStepTo($stepName) { |
||
| 69 | $this->currentStepName = $stepName; |
||
| 70 | } |
||
| 71 | |||
| 72 | public function switchToInTimeExecutionStrategy() { |
||
| 73 | $this->strategy = self::IN_TIME_EXECUTION_STRATEGY; |
||
| 74 | } |
||
| 75 | |||
| 76 | public function switchToDelayedExecutionStrategy() { |
||
| 77 | $this->strategy = self::DELAYED_EXECUTION_STRATEGY; |
||
| 78 | } |
||
| 79 | |||
| 80 | public function runStepsWithActualValue($actualValue) { |
||
| 81 | if ($this->strategy === self::DELAYED_EXECUTION_STRATEGY) { |
||
| 82 | return; |
||
| 83 | } |
||
| 84 | $this->actual = $actualValue; |
||
| 85 | while (!$this->delayedAssertSteps->isEmpty()) { |
||
| 86 | $step = $this->delayedAssertSteps->dequeue(); |
||
| 87 | array_push($step[1], $this->getMessageForAssert()); |
||
| 88 | array_unshift($step[1], $this->actual); |
||
| 89 | $this->executeAssertMethod($step[0], $step[1], $step[2]); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | protected function callAssertMethod($method, $config = []) { |
||
| 94 | $stepName = $this->currentStepName; |
||
| 95 | if ($this->strategy === self::IN_TIME_EXECUTION_STRATEGY) { |
||
| 96 | $this->executeAssertMethod($method, $config, $stepName); |
||
| 97 | } else { |
||
| 98 | $this->delayedAssertSteps->enqueue([$method, $config, $stepName]); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | protected function executeAssertMethod($method, $config, $stepName) { |
||
| 103 | $this->registerExpectation($stepName); |
||
| 104 | if (is_callable([\PHPUnit\Framework\Assert::class, $method])) { |
||
| 105 | call_user_func_array([ |
||
| 106 | \PHPUnit\Framework\Assert::class, |
||
| 107 | $method, |
||
| 108 | ], $this->buildAssertMethodParamsFromConfig($config)); |
||
| 109 | } elseif (method_exists($this, $method)) { |
||
| 110 | call_user_func_array([ |
||
| 111 | $this, |
||
| 112 | $method, |
||
| 113 | ], $this->buildAssertMethodParamsFromConfig($config)); |
||
| 114 | } else { |
||
| 115 | throw new \InvalidArgumentException("Assert method '{$method}' does not exist"); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | protected function buildAssertMethodParamsFromConfig($config) { |
||
| 120 | $params = []; |
||
| 121 | if (array_key_exists('expected', $config)) { |
||
| 122 | $params[] = $config['expected']; |
||
| 123 | } |
||
| 124 | $params[] = $this->actual; |
||
| 125 | if (isset($config['options'])) { |
||
| 126 | $params = array_merge($params, $config['options']); |
||
| 127 | } |
||
| 128 | |||
| 129 | $params[] = $this->getMessageForAssert(); |
||
| 130 | |||
| 131 | if (isset($config['additionalParams'])) { |
||
| 132 | $params = array_merge($params, $config['additionalParams']); |
||
| 133 | } |
||
| 134 | |||
| 135 | return $params; |
||
| 136 | } |
||
| 137 | |||
| 138 | protected function registerExpectation($message) { |
||
| 139 | $this->stepsList->add("$this->description {$message}."); |
||
| 140 | } |
||
| 141 | |||
| 142 | protected function getMessageForAssert() { |
||
| 143 | return $this->stepsList->convertToString(); |
||
| 144 | } |
||
| 145 | |||
| 146 | //endregion |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @param string $exception |
||
| 150 | */ |
||
| 151 | public function expectException($exception) { |
||
| 152 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 153 | 'expected' => $exception, |
||
| 154 | ]); |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param string $exception |
||
| 159 | */ |
||
| 160 | public function expectExceptionObject($exceptionObject) { |
||
| 161 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 162 | 'expected' => $exceptionObject, |
||
| 163 | ]); |
||
| 164 | } |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @param int|string $code |
||
| 168 | * |
||
| 169 | * @throws \Exception |
||
| 170 | */ |
||
| 171 | public function expectExceptionCode($code) { |
||
| 172 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 173 | 'expected' => $code, |
||
| 174 | ]); |
||
| 175 | } |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @param string $message |
||
| 179 | * |
||
| 180 | * @throws \Exception |
||
| 181 | */ |
||
| 182 | public function expectExceptionMessage($message) { |
||
| 183 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 184 | 'expected' => $message, |
||
| 185 | ]); |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @param string $messageRegExp |
||
| 190 | * |
||
| 191 | * @throws \Exception |
||
| 192 | */ |
||
| 193 | public function expectExceptionMessageRegExp($messageRegExp) { |
||
| 194 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 195 | 'expected' => $messageRegExp, |
||
| 196 | ]); |
||
| 197 | } |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Asserts that an array has a specified key. |
||
| 201 | * |
||
| 202 | * @param mixed $key |
||
| 203 | */ |
||
| 204 | public function assertArrayHasKey($key) { |
||
| 205 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 206 | 'expected' => $key, |
||
| 207 | ]); |
||
| 208 | } |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Asserts that an array has a specified subset. |
||
| 212 | * |
||
| 213 | * @param array|ArrayAccess $subset |
||
| 214 | */ |
||
| 215 | public function assertArraySubset($subset, $useStrictMatch) { |
||
| 216 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 217 | 'expected' => $subset, |
||
| 218 | 'options' => [ |
||
| 219 | $useStrictMatch, |
||
| 220 | ], |
||
| 221 | ]); |
||
| 222 | } |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Asserts that an array does not have a specified key. |
||
| 226 | * |
||
| 227 | * @param mixed $key |
||
| 228 | * @param array|ArrayAccess $array |
||
| 229 | * @param string $message |
||
| 230 | */ |
||
| 231 | public function assertArrayNotHasKey($key) { |
||
| 232 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 233 | 'expected' => $key, |
||
| 234 | ]); |
||
| 235 | } |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Asserts that a haystack contains a needle. |
||
| 239 | * |
||
| 240 | * @param mixed $needle |
||
| 241 | * @param bool $ignoreCase |
||
| 242 | * @param bool $checkForObjectIdentity |
||
| 243 | * @param bool $checkForNonObjectIdentity |
||
| 244 | */ |
||
| 245 | public function assertContains($needle, $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false) { |
||
| 246 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 247 | 'expected' => $needle, |
||
| 248 | 'additionalParams' => [ |
||
| 249 | $ignoreCase, |
||
| 250 | $checkForObjectIdentity, |
||
| 251 | $checkForNonObjectIdentity, |
||
| 252 | ], |
||
| 253 | ]); |
||
| 254 | } |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Asserts that a haystack does not contain a needle. |
||
| 258 | * |
||
| 259 | * @param mixed $needle |
||
| 260 | * @param bool $ignoreCase |
||
| 261 | * @param bool $checkForObjectIdentity |
||
| 262 | * @param bool $checkForNonObjectIdentity |
||
| 263 | */ |
||
| 264 | public function assertNotContains($needle, $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false) { |
||
| 265 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 266 | 'expected' => $needle, |
||
| 267 | 'additionalParams' => [ |
||
| 268 | $ignoreCase, |
||
| 269 | $checkForObjectIdentity, |
||
| 270 | $checkForNonObjectIdentity, |
||
| 271 | ], |
||
| 272 | ]); |
||
| 273 | } |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Asserts that a haystack contains only values of a given type. |
||
| 277 | * |
||
| 278 | * @param string $type |
||
| 279 | * @param bool $isNativeType |
||
| 280 | */ |
||
| 281 | public function assertContainsOnly($type, $isNativeType = null) { |
||
| 282 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 283 | 'expected' => $type, |
||
| 284 | 'options' => [ |
||
| 285 | $isNativeType, |
||
| 286 | ], |
||
| 287 | ]); |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Asserts that a haystack does not contain only values of a given type. |
||
| 292 | * |
||
| 293 | * @param string $type |
||
| 294 | * @param bool $isNativeType |
||
| 295 | */ |
||
| 296 | public function assertNotContainsOnly($type, $isNativeType = null) { |
||
| 297 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 298 | 'expected' => $type, |
||
| 299 | 'options' => [ |
||
| 300 | $isNativeType, |
||
| 301 | ], |
||
| 302 | ]); |
||
| 303 | } |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Asserts that a haystack that is stored in a static attribute of a class |
||
| 307 | * or an attribute of an object contains a needle. |
||
| 308 | * |
||
| 309 | * @param mixed $needle |
||
| 310 | * @param string $haystackAttributeName |
||
| 311 | * @param string|object $haystackClassOrObject |
||
| 312 | * @param string $message |
||
| 313 | * @param bool $ignoreCase |
||
| 314 | * @param bool $checkForObjectIdentity |
||
| 315 | * @param bool $checkForNonObjectIdentity |
||
| 316 | */ |
||
| 317 | public function assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false) { |
||
| 318 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 319 | 'expected' => $key, |
||
|
|
|||
| 320 | ]); |
||
| 321 | } |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Asserts that a haystack that is stored in a static attribute of a class |
||
| 325 | * or an attribute of an object does not contain a needle. |
||
| 326 | * |
||
| 327 | * @param mixed $needle |
||
| 328 | * @param string $haystackAttributeName |
||
| 329 | * @param string|object $haystackClassOrObject |
||
| 330 | * @param string $message |
||
| 331 | * @param bool $ignoreCase |
||
| 332 | * @param bool $checkForObjectIdentity |
||
| 333 | * @param bool $checkForNonObjectIdentity |
||
| 334 | */ |
||
| 335 | public function assertAttributeNotContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false) { |
||
| 336 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 337 | 'expected' => $key, |
||
| 338 | ]); |
||
| 339 | } |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Asserts that a haystack contains only instances of a given classname |
||
| 343 | * |
||
| 344 | * @param string $className |
||
| 345 | */ |
||
| 346 | public function assertContainsOnlyInstancesOf($className) { |
||
| 347 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 348 | 'expected' => $className, |
||
| 349 | ]); |
||
| 350 | } |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Asserts that a haystack that is stored in a static attribute of a class |
||
| 354 | * or an attribute of an object contains only values of a given type. |
||
| 355 | * |
||
| 356 | * @param string $type |
||
| 357 | * @param string $haystackAttributeName |
||
| 358 | * @param string|object $haystackClassOrObject |
||
| 359 | * @param bool $isNativeType |
||
| 360 | * @param string $message |
||
| 361 | */ |
||
| 362 | public function assertAttributeContainsOnly($type, $haystackAttributeName, $haystackClassOrObject, $isNativeType = null) { |
||
| 363 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 364 | 'expected' => $key, |
||
| 365 | ]); |
||
| 366 | } |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Asserts that a haystack that is stored in a static attribute of a class |
||
| 370 | * or an attribute of an object does not contain only values of a given |
||
| 371 | * type. |
||
| 372 | * |
||
| 373 | * @param string $type |
||
| 374 | * @param string $haystackAttributeName |
||
| 375 | * @param string|object $haystackClassOrObject |
||
| 376 | * @param bool $isNativeType |
||
| 377 | * @param string $message |
||
| 378 | */ |
||
| 379 | public function assertAttributeNotContainsOnly($type, $haystackAttributeName, $haystackClassOrObject, $isNativeType = null) { |
||
| 380 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 381 | 'expected' => $key, |
||
| 382 | ]); |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Asserts the number of elements of an array, \Countable or \Traversable. |
||
| 387 | * |
||
| 388 | * @param int $expectedCount |
||
| 389 | */ |
||
| 390 | public function assertCount($expectedCount) { |
||
| 391 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 392 | 'expected' => $expectedCount, |
||
| 393 | ]); |
||
| 394 | } |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Asserts the number of elements of an array, \Countable or \Traversable |
||
| 398 | * that is stored in an attribute. |
||
| 399 | * |
||
| 400 | * @param int $expectedCount |
||
| 401 | * @param string $haystackAttributeName |
||
| 402 | * @param string|object $haystackClassOrObject |
||
| 403 | * @param string $message |
||
| 404 | */ |
||
| 405 | public function assertAttributeCount($expectedCount, $haystackAttributeName, $haystackClassOrObject) { |
||
| 406 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 407 | 'expected' => $key, |
||
| 408 | ]); |
||
| 409 | } |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Asserts the number of elements of an array, \Countable or \Traversable. |
||
| 413 | * |
||
| 414 | * @param int $expectedCount |
||
| 415 | * @param mixed $haystack |
||
| 416 | * @param string $message |
||
| 417 | */ |
||
| 418 | public function assertNotCount($expectedCount) { |
||
| 419 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 420 | 'expected' => $expectedCount, |
||
| 421 | ]); |
||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Asserts the number of elements of an array, \Countable or \Traversable |
||
| 426 | * that is stored in an attribute. |
||
| 427 | * |
||
| 428 | * @param int $expectedCount |
||
| 429 | * @param string $haystackAttributeName |
||
| 430 | * @param string|object $haystackClassOrObject |
||
| 431 | * @param string $message |
||
| 432 | */ |
||
| 433 | public function assertAttributeNotCount($expectedCount, $haystackAttributeName, $haystackClassOrObject) { |
||
| 434 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 435 | 'expected' => $key, |
||
| 436 | ]); |
||
| 437 | } |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Asserts that two variables are equal. |
||
| 441 | * |
||
| 442 | * @param mixed $expected |
||
| 443 | * @param float $delta |
||
| 444 | * @param int $maxDepth |
||
| 445 | * @param bool $canonicalize |
||
| 446 | * @param bool $ignoreCase |
||
| 447 | */ |
||
| 448 | public function assertEquals($expected, $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false) { |
||
| 449 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 450 | 'expected' => $expected, |
||
| 451 | 'additionalParams' => [ |
||
| 452 | $delta, |
||
| 453 | $maxDepth, |
||
| 454 | $canonicalize, |
||
| 455 | $ignoreCase, |
||
| 456 | ], |
||
| 457 | ]); |
||
| 458 | } |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Asserts that a variable is equal to an attribute of an object. |
||
| 462 | * |
||
| 463 | * @param mixed $expected |
||
| 464 | * @param string $actualAttributeName |
||
| 465 | * @param string|object $actualClassOrObject |
||
| 466 | * @param string $message |
||
| 467 | * @param float $delta |
||
| 468 | * @param int $maxDepth |
||
| 469 | * @param bool $canonicalize |
||
| 470 | * @param bool $ignoreCase |
||
| 471 | */ |
||
| 472 | public function assertAttributeEquals($expected, $actualAttributeName, $actualClassOrObject, $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false) { |
||
| 473 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 474 | 'expected' => $key, |
||
| 475 | ]); |
||
| 476 | } |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Asserts that two variables are not equal. |
||
| 480 | * |
||
| 481 | * @param mixed $expected |
||
| 482 | * @param float $delta |
||
| 483 | * @param int $maxDepth |
||
| 484 | * @param bool $canonicalize |
||
| 485 | * @param bool $ignoreCase |
||
| 486 | */ |
||
| 487 | public function assertNotEquals($expected, $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false) { |
||
| 488 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 489 | 'expected' => $expected, |
||
| 490 | 'additionalParams' => [ |
||
| 491 | $delta, |
||
| 492 | $maxDepth, |
||
| 493 | $canonicalize, |
||
| 494 | $ignoreCase, |
||
| 495 | ], |
||
| 496 | ]); |
||
| 497 | } |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Asserts that a variable is not equal to an attribute of an object. |
||
| 501 | * |
||
| 502 | * @param mixed $expected |
||
| 503 | * @param string $actualAttributeName |
||
| 504 | * @param string|object $actualClassOrObject |
||
| 505 | * @param string $message |
||
| 506 | * @param float $delta |
||
| 507 | * @param int $maxDepth |
||
| 508 | * @param bool $canonicalize |
||
| 509 | * @param bool $ignoreCase |
||
| 510 | */ |
||
| 511 | public function assertAttributeNotEquals($expected, $actualAttributeName, $actualClassOrObject, $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false) { |
||
| 512 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 513 | 'expected' => $key, |
||
| 514 | ]); |
||
| 515 | } |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Asserts that a variable is empty. |
||
| 519 | * |
||
| 520 | * |
||
| 521 | * @throws AssertionFailedError |
||
| 522 | */ |
||
| 523 | public function assertEmpty() { |
||
| 524 | $this->callAssertMethod(__FUNCTION__); |
||
| 525 | } |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Asserts that a static attribute of a class or an attribute of an object |
||
| 529 | * is empty. |
||
| 530 | * |
||
| 531 | * @param string $haystackAttributeName |
||
| 532 | * @param string|object $haystackClassOrObject |
||
| 533 | * @param string $message |
||
| 534 | */ |
||
| 535 | public function assertAttributeEmpty($haystackAttributeName, $haystackClassOrObject) { |
||
| 538 | ]); |
||
| 539 | } |
||
| 540 | |||
| 541 | /** |
||
| 542 | * Asserts that a variable is not empty. |
||
| 543 | * |
||
| 544 | * @param mixed $actual |
||
| 545 | * @param string $message |
||
| 546 | * |
||
| 547 | * @throws AssertionFailedError |
||
| 548 | */ |
||
| 549 | public function assertNotEmpty() { |
||
| 550 | $this->callAssertMethod(__FUNCTION__, []); |
||
| 551 | } |
||
| 552 | |||
| 553 | /** |
||
| 554 | * Asserts that a static attribute of a class or an attribute of an object |
||
| 555 | * is not empty. |
||
| 556 | * |
||
| 557 | * @param string $haystackAttributeName |
||
| 558 | * @param string|object $haystackClassOrObject |
||
| 559 | * @param string $message |
||
| 560 | */ |
||
| 561 | public function assertAttributeNotEmpty($haystackAttributeName, $haystackClassOrObject) { |
||
| 562 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 563 | 'expected' => $key, |
||
| 564 | ]); |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Asserts that a value is greater than another value. |
||
| 569 | * |
||
| 570 | * @param mixed $expected |
||
| 571 | */ |
||
| 572 | public function assertGreaterThan($expected) { |
||
| 573 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 574 | 'expected' => $expected, |
||
| 575 | ]); |
||
| 576 | } |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Asserts that an attribute is greater than another value. |
||
| 580 | * |
||
| 581 | * @param mixed $expected |
||
| 582 | * @param string $actualAttributeName |
||
| 583 | * @param string|object $actualClassOrObject |
||
| 584 | * @param string $message |
||
| 585 | */ |
||
| 586 | public function assertAttributeGreaterThan($expected, $actualAttributeName, $actualClassOrObject) { |
||
| 587 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 588 | 'expected' => $key, |
||
| 589 | ]); |
||
| 590 | } |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Asserts that a value is greater than or equal to another value. |
||
| 594 | * |
||
| 595 | * @param mixed $expected |
||
| 596 | */ |
||
| 597 | public function assertGreaterThanOrEqual($expected) { |
||
| 598 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 599 | 'expected' => $expected, |
||
| 600 | ]); |
||
| 601 | } |
||
| 602 | |||
| 603 | /** |
||
| 604 | * Asserts that an attribute is greater than or equal to another value. |
||
| 605 | * |
||
| 606 | * @param mixed $expected |
||
| 607 | * @param string $actualAttributeName |
||
| 608 | * @param string|object $actualClassOrObject |
||
| 609 | * @param string $message |
||
| 610 | */ |
||
| 611 | public function assertAttributeGreaterThanOrEqual($expected, $actualAttributeName, $actualClassOrObject) { |
||
| 612 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 613 | 'expected' => $key, |
||
| 614 | ]); |
||
| 615 | } |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Asserts that a value is smaller than another value. |
||
| 619 | * |
||
| 620 | * @param mixed $expected |
||
| 621 | */ |
||
| 622 | public function assertLessThan($expected) { |
||
| 623 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 624 | 'expected' => $expected, |
||
| 625 | ]); |
||
| 626 | } |
||
| 627 | |||
| 628 | /** |
||
| 629 | * Asserts that an attribute is smaller than another value. |
||
| 630 | * |
||
| 631 | * @param mixed $expected |
||
| 632 | * @param string $actualAttributeName |
||
| 633 | * @param string|object $actualClassOrObject |
||
| 634 | * @param string $message |
||
| 635 | */ |
||
| 636 | public function assertAttributeLessThan($expected, $actualAttributeName, $actualClassOrObject) { |
||
| 637 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 638 | 'expected' => $key, |
||
| 639 | ]); |
||
| 640 | } |
||
| 641 | |||
| 642 | /** |
||
| 643 | * Asserts that a value is smaller than or equal to another value. |
||
| 644 | * |
||
| 645 | * @param mixed $expected |
||
| 646 | */ |
||
| 647 | public function assertLessThanOrEqual($expected) { |
||
| 648 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 649 | 'expected' => $expected, |
||
| 650 | ]); |
||
| 651 | } |
||
| 652 | |||
| 653 | /** |
||
| 654 | * Asserts that an attribute is smaller than or equal to another value. |
||
| 655 | * |
||
| 656 | * @param mixed $expected |
||
| 657 | * @param string $actualAttributeName |
||
| 658 | * @param string|object $actualClassOrObject |
||
| 659 | * @param string $message |
||
| 660 | */ |
||
| 661 | public function assertAttributeLessThanOrEqual($expected, $actualAttributeName, $actualClassOrObject) { |
||
| 662 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 663 | 'expected' => $key, |
||
| 664 | ]); |
||
| 665 | } |
||
| 666 | |||
| 667 | /** |
||
| 668 | * Asserts that the contents of one file is equal to the contents of another |
||
| 669 | * file. |
||
| 670 | * |
||
| 671 | * @param string $expected |
||
| 672 | * @param bool $canonicalize |
||
| 673 | * @param bool $ignoreCase |
||
| 674 | */ |
||
| 675 | public function assertFileEquals($expected, $canonicalize = false, $ignoreCase = false) { |
||
| 676 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 677 | 'expected' => $expected, |
||
| 678 | 'additionalParams' => [ |
||
| 679 | $canonicalize, |
||
| 680 | $ignoreCase, |
||
| 681 | ], |
||
| 682 | ]); |
||
| 683 | } |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Asserts that the contents of one file is not equal to the contents of |
||
| 687 | * another file. |
||
| 688 | * |
||
| 689 | * @param string $expected |
||
| 690 | * @param bool $canonicalize |
||
| 691 | * @param bool $ignoreCase |
||
| 692 | */ |
||
| 693 | public function assertFileNotEquals($expected, $canonicalize = false, $ignoreCase = false) { |
||
| 694 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 695 | 'expected' => $expected, |
||
| 696 | 'additionalParams' => [ |
||
| 697 | $canonicalize, |
||
| 698 | $ignoreCase, |
||
| 699 | ], |
||
| 700 | ]); |
||
| 701 | } |
||
| 702 | |||
| 703 | /** |
||
| 704 | * Asserts that the contents of a string is equal |
||
| 705 | * to the contents of a file. |
||
| 706 | * |
||
| 707 | * @param string $expectedFile |
||
| 708 | * @param bool $canonicalize |
||
| 709 | * @param bool $ignoreCase |
||
| 710 | */ |
||
| 711 | public function assertStringEqualsFile($expectedFile, $canonicalize = false, $ignoreCase = false) { |
||
| 712 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 713 | 'expected' => $expectedFile, |
||
| 714 | 'additionalParams' => [ |
||
| 715 | $canonicalize, |
||
| 716 | $ignoreCase, |
||
| 717 | ], |
||
| 718 | ]); |
||
| 719 | } |
||
| 720 | |||
| 721 | /** |
||
| 722 | * Asserts that the contents of a string is not equal |
||
| 723 | * to the contents of a file. |
||
| 724 | * |
||
| 725 | * @param string $expectedFile |
||
| 726 | * @param bool $canonicalize |
||
| 727 | * @param bool $ignoreCase |
||
| 728 | */ |
||
| 729 | public function assertStringNotEqualsFile($expectedFile, $canonicalize = false, $ignoreCase = false) { |
||
| 730 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 731 | 'expected' => $expectedFile, |
||
| 732 | 'additionalParams' => [ |
||
| 733 | $canonicalize, |
||
| 734 | $ignoreCase, |
||
| 735 | ], |
||
| 736 | ]); |
||
| 737 | } |
||
| 738 | |||
| 739 | /** |
||
| 740 | * Asserts that a file/dir is readable. |
||
| 741 | */ |
||
| 742 | public function assertIsReadable() { |
||
| 743 | $this->callAssertMethod(__FUNCTION__); |
||
| 744 | } |
||
| 745 | |||
| 746 | /** |
||
| 747 | * Asserts that a file/dir exists and is not readable. |
||
| 748 | */ |
||
| 749 | public function assertNotIsReadable() { |
||
| 750 | $this->callAssertMethod(__FUNCTION__); |
||
| 751 | } |
||
| 752 | |||
| 753 | /** |
||
| 754 | * Asserts that a file/dir exists and is writable. |
||
| 755 | */ |
||
| 756 | public function assertIsWritable() { |
||
| 757 | $this->callAssertMethod(__FUNCTION__); |
||
| 758 | } |
||
| 759 | |||
| 760 | /** |
||
| 761 | * Asserts that a file/dir exists and is not writable. |
||
| 762 | */ |
||
| 763 | public function assertNotIsWritable() { |
||
| 764 | $this->callAssertMethod(__FUNCTION__); |
||
| 765 | } |
||
| 766 | |||
| 767 | /** |
||
| 768 | * Asserts that a directory exists. |
||
| 769 | */ |
||
| 770 | public function assertDirectoryExists() { |
||
| 771 | $this->callAssertMethod(__FUNCTION__); |
||
| 772 | } |
||
| 773 | |||
| 774 | /** |
||
| 775 | * Asserts that a directory does not exist. |
||
| 776 | */ |
||
| 777 | public function assertDirectoryNotExists() { |
||
| 778 | $this->callAssertMethod(__FUNCTION__); |
||
| 779 | } |
||
| 780 | |||
| 781 | /** |
||
| 782 | * Asserts that a directory exists and is readable. |
||
| 783 | * |
||
| 784 | * @param string $directory |
||
| 785 | * @param string $message |
||
| 786 | */ |
||
| 787 | public function assertDirectoryIsReadable($directory) { |
||
| 788 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 789 | 'expected' => $key, |
||
| 790 | ]); |
||
| 791 | } |
||
| 792 | |||
| 793 | /** |
||
| 794 | * Asserts that a directory exists and is not readable. |
||
| 795 | * |
||
| 796 | * @param string $directory |
||
| 797 | * @param string $message |
||
| 798 | */ |
||
| 799 | public function assertDirectoryNotIsReadable($directory) { |
||
| 800 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 801 | 'expected' => $key, |
||
| 802 | ]); |
||
| 803 | } |
||
| 804 | |||
| 805 | /** |
||
| 806 | * Asserts that a directory exists and is writable. |
||
| 807 | * |
||
| 808 | * @param string $directory |
||
| 809 | * @param string $message |
||
| 810 | */ |
||
| 811 | public function assertDirectoryIsWritable($directory) { |
||
| 812 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 813 | 'expected' => $key, |
||
| 814 | ]); |
||
| 815 | } |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Asserts that a directory exists and is not writable. |
||
| 819 | * |
||
| 820 | * @param string $directory |
||
| 821 | * @param string $message |
||
| 822 | */ |
||
| 823 | public function assertDirectoryNotIsWritable($directory) { |
||
| 826 | ]); |
||
| 827 | } |
||
| 828 | |||
| 829 | /** |
||
| 830 | * Asserts that a file exists. |
||
| 831 | */ |
||
| 832 | public function assertFileExists() { |
||
| 833 | $this->callAssertMethod(__FUNCTION__); |
||
| 834 | } |
||
| 835 | |||
| 836 | /** |
||
| 837 | * Asserts that a file does not exist. |
||
| 838 | */ |
||
| 839 | public function assertFileNotExists() { |
||
| 840 | $this->callAssertMethod(__FUNCTION__); |
||
| 841 | } |
||
| 842 | |||
| 843 | /** |
||
| 844 | * Asserts that a file exists and is readable. |
||
| 845 | * |
||
| 846 | * @param string $file |
||
| 847 | * @param string $message |
||
| 848 | */ |
||
| 849 | public function assertFileIsReadable($file) { |
||
| 850 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 851 | 'expected' => $key, |
||
| 852 | ]); |
||
| 853 | } |
||
| 854 | |||
| 855 | /** |
||
| 856 | * Asserts that a file exists and is not readable. |
||
| 857 | * |
||
| 858 | * @param string $file |
||
| 859 | * @param string $message |
||
| 860 | */ |
||
| 861 | public function assertFileNotIsReadable($file) { |
||
| 862 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 863 | 'expected' => $key, |
||
| 864 | ]); |
||
| 865 | } |
||
| 866 | |||
| 867 | /** |
||
| 868 | * Asserts that a file exists and is writable. |
||
| 869 | * |
||
| 870 | * @param string $file |
||
| 871 | * @param string $message |
||
| 872 | */ |
||
| 873 | public function assertFileIsWritable($file) { |
||
| 874 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 875 | 'expected' => $key, |
||
| 876 | ]); |
||
| 877 | } |
||
| 878 | |||
| 879 | /** |
||
| 880 | * Asserts that a file exists and is not writable. |
||
| 881 | */ |
||
| 882 | public function assertFileNotIsWritable() { |
||
| 883 | $this->callAssertMethod(__FUNCTION__); |
||
| 884 | } |
||
| 885 | |||
| 886 | /** |
||
| 887 | * Asserts that a condition is true. |
||
| 888 | * |
||
| 889 | * @throws AssertionFailedError |
||
| 890 | */ |
||
| 891 | public function assertTrue() { |
||
| 892 | $this->callAssertMethod(__FUNCTION__); |
||
| 893 | } |
||
| 894 | |||
| 895 | /** |
||
| 896 | * Asserts that a condition is not true. |
||
| 897 | * |
||
| 898 | * @throws AssertionFailedError |
||
| 899 | */ |
||
| 900 | public function assertNotTrue() { |
||
| 901 | $this->callAssertMethod(__FUNCTION__); |
||
| 902 | } |
||
| 903 | |||
| 904 | /** |
||
| 905 | * Asserts that a condition is false. |
||
| 906 | * |
||
| 907 | * @throws AssertionFailedError |
||
| 908 | */ |
||
| 909 | public function assertFalse() { |
||
| 910 | $this->callAssertMethod(__FUNCTION__); |
||
| 911 | } |
||
| 912 | |||
| 913 | /** |
||
| 914 | * Asserts that a condition is not false |
||
| 915 | * |
||
| 916 | * @throws AssertionFailedError |
||
| 917 | */ |
||
| 918 | public function assertNotFalse() { |
||
| 920 | } |
||
| 921 | |||
| 922 | /** |
||
| 923 | * Asserts that a variable is null. |
||
| 924 | * |
||
| 925 | * @param mixed $actual |
||
| 926 | */ |
||
| 927 | public function assertNull() { |
||
| 928 | $this->callAssertMethod(__FUNCTION__); |
||
| 929 | } |
||
| 930 | |||
| 931 | /** |
||
| 932 | * Asserts that a variable is not null. |
||
| 933 | */ |
||
| 934 | public function assertNotNull() { |
||
| 935 | $this->callAssertMethod(__FUNCTION__); |
||
| 936 | } |
||
| 937 | |||
| 938 | /** |
||
| 939 | * Asserts that a variable is finite. |
||
| 940 | */ |
||
| 941 | public function assertFinite() { |
||
| 942 | $this->callAssertMethod(__FUNCTION__); |
||
| 943 | } |
||
| 944 | |||
| 945 | /** |
||
| 946 | * Asserts that a variable is infinite. |
||
| 947 | */ |
||
| 948 | public function assertInfinite() { |
||
| 949 | $this->callAssertMethod(__FUNCTION__); |
||
| 950 | } |
||
| 951 | |||
| 952 | /** |
||
| 953 | * Asserts that a variable is nan. |
||
| 954 | */ |
||
| 955 | public function assertNan() { |
||
| 956 | $this->callAssertMethod(__FUNCTION__); |
||
| 957 | } |
||
| 958 | |||
| 959 | /** |
||
| 960 | * Asserts that a class exists |
||
| 961 | */ |
||
| 962 | public function assertClassExists() { |
||
| 963 | $this->callAssertMethod('classExists'); |
||
| 964 | } |
||
| 965 | |||
| 966 | protected function classExists($class, $message) { |
||
| 967 | \PHPUnit\Framework\Assert::assertTrue(class_exists($class), $message); |
||
| 968 | } |
||
| 969 | |||
| 970 | /** |
||
| 971 | * Asserts that a class does not exist |
||
| 972 | */ |
||
| 973 | public function assertClassDoesNotExist() { |
||
| 974 | $this->callAssertMethod('classDoesNotExist'); |
||
| 975 | } |
||
| 976 | |||
| 977 | protected function classDoesNotExist($class, $message) { |
||
| 978 | \PHPUnit\Framework\Assert::assertFalse(class_exists($class), $message); |
||
| 979 | } |
||
| 980 | |||
| 981 | /** |
||
| 982 | * Asserts that a class does not exist |
||
| 983 | */ |
||
| 984 | public function assertClassIsInterface() { |
||
| 985 | $this->callAssertMethod('classIsInterface'); |
||
| 986 | } |
||
| 987 | |||
| 988 | protected function classIsInterface($class, $message) { |
||
| 989 | \PHPUnit\Framework\Assert::assertTrue(interface_exists($class), $message); |
||
| 990 | } |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Asserts that a class does not exist |
||
| 994 | */ |
||
| 995 | public function assertClassIsNotInterface() { |
||
| 996 | $this->callAssertMethod('classIsNotInterface'); |
||
| 997 | } |
||
| 998 | |||
| 999 | protected function classIsNotInterface($class, $message) { |
||
| 1000 | \PHPUnit\Framework\Assert::assertFalse(interface_exists($class), $message); |
||
| 1001 | } |
||
| 1002 | |||
| 1003 | /** |
||
| 1004 | * Asserts that a class has a specified attribute. |
||
| 1005 | * |
||
| 1006 | * @param string $attributeName |
||
| 1007 | */ |
||
| 1008 | public function assertClassHasAttribute($attributeName) { |
||
| 1009 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1010 | 'expected' => $attributeName, |
||
| 1011 | ]); |
||
| 1012 | } |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * Asserts that a class does not have a specified attribute. |
||
| 1016 | * |
||
| 1017 | * @param string $attributeName |
||
| 1018 | */ |
||
| 1019 | public function assertClassNotHasAttribute($attributeName) { |
||
| 1020 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1021 | 'expected' => $attributeName, |
||
| 1022 | ]); |
||
| 1023 | } |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Asserts that a class has a specified static attribute. |
||
| 1027 | * |
||
| 1028 | * @param string $attributeName |
||
| 1029 | */ |
||
| 1030 | public function assertClassHasStaticAttribute($attributeName) { |
||
| 1031 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1032 | 'expected' => $attributeName, |
||
| 1033 | ]); |
||
| 1034 | } |
||
| 1035 | |||
| 1036 | /** |
||
| 1037 | * Asserts that a class does not have a specified static attribute. |
||
| 1038 | * |
||
| 1039 | * @param string $attributeName |
||
| 1040 | */ |
||
| 1041 | public function assertClassNotHasStaticAttribute($attributeName) { |
||
| 1042 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1043 | 'expected' => $attributeName, |
||
| 1044 | ]); |
||
| 1045 | } |
||
| 1046 | |||
| 1047 | /** |
||
| 1048 | * Asserts that an object has a specified attribute. |
||
| 1049 | * |
||
| 1050 | * @param string $attributeName |
||
| 1051 | */ |
||
| 1052 | public function assertObjectHasAttribute($attributeName) { |
||
| 1053 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1054 | 'expected' => $attributeName, |
||
| 1055 | ]); |
||
| 1056 | } |
||
| 1057 | |||
| 1058 | /** |
||
| 1059 | * Asserts that an object does not have a specified attribute. |
||
| 1060 | * |
||
| 1061 | * @param string $attributeName |
||
| 1062 | */ |
||
| 1063 | public function assertObjectNotHasAttribute($attributeName) { |
||
| 1064 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1065 | 'expected' => $attributeName, |
||
| 1066 | ]); |
||
| 1067 | } |
||
| 1068 | |||
| 1069 | /** |
||
| 1070 | * Asserts that two variables have the same type and value. |
||
| 1071 | * Used on objects, it asserts that two variables reference |
||
| 1072 | * the same object. |
||
| 1073 | * |
||
| 1074 | * @param mixed $expected |
||
| 1075 | */ |
||
| 1076 | public function assertSame($expected) { |
||
| 1077 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1078 | 'expected' => $expected, |
||
| 1079 | ]); |
||
| 1080 | } |
||
| 1081 | |||
| 1082 | /** |
||
| 1083 | * Asserts that a variable and an attribute of an object have the same type |
||
| 1084 | * and value. |
||
| 1085 | * |
||
| 1086 | * @param mixed $expected |
||
| 1087 | * @param string $actualAttributeName |
||
| 1088 | * @param string|object $actualClassOrObject |
||
| 1089 | * @param string $message |
||
| 1090 | */ |
||
| 1091 | public function assertAttributeSame($expected, $actualAttributeName, $actualClassOrObject) { |
||
| 1092 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1093 | 'expected' => $key, |
||
| 1094 | ]); |
||
| 1095 | } |
||
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Asserts that two variables do not have the same type and value. |
||
| 1099 | * Used on objects, it asserts that two variables do not reference |
||
| 1100 | * the same object. |
||
| 1101 | * |
||
| 1102 | * @param mixed $expected |
||
| 1103 | */ |
||
| 1104 | public function assertNotSame($expected) { |
||
| 1105 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1106 | 'expected' => $expected, |
||
| 1107 | ]); |
||
| 1108 | } |
||
| 1109 | |||
| 1110 | /** |
||
| 1111 | * Asserts that a variable and an attribute of an object do not have the |
||
| 1112 | * same type and value. |
||
| 1113 | * |
||
| 1114 | * @param mixed $expected |
||
| 1115 | * @param string $actualAttributeName |
||
| 1116 | * @param string|object $actualClassOrObject |
||
| 1117 | * @param string $message |
||
| 1118 | */ |
||
| 1119 | public function assertAttributeNotSame($expected, $actualAttributeName, $actualClassOrObject) { |
||
| 1120 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1121 | 'expected' => $key, |
||
| 1122 | ]); |
||
| 1123 | } |
||
| 1124 | |||
| 1125 | /** |
||
| 1126 | * Asserts that a variable is of a given type. |
||
| 1127 | * |
||
| 1128 | * @param string $expected |
||
| 1129 | */ |
||
| 1130 | public function assertInstanceOf($expected) { |
||
| 1131 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1132 | 'expected' => $expected, |
||
| 1133 | ]); |
||
| 1134 | } |
||
| 1135 | |||
| 1136 | /** |
||
| 1137 | * Asserts that an attribute is of a given type. |
||
| 1138 | * |
||
| 1139 | * @param string $expected |
||
| 1140 | * @param string $attributeName |
||
| 1141 | * @param string|object $classOrObject |
||
| 1142 | * @param string $message |
||
| 1143 | */ |
||
| 1144 | public function assertAttributeInstanceOf($expected, $attributeName, $classOrObject) { |
||
| 1145 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1146 | 'expected' => $key, |
||
| 1147 | ]); |
||
| 1148 | } |
||
| 1149 | |||
| 1150 | /** |
||
| 1151 | * Asserts that a variable is not of a given type. |
||
| 1152 | * |
||
| 1153 | * @param string $expected |
||
| 1154 | */ |
||
| 1155 | public function assertNotInstanceOf($expected) { |
||
| 1156 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1157 | 'expected' => $expected, |
||
| 1158 | ]); |
||
| 1159 | } |
||
| 1160 | |||
| 1161 | /** |
||
| 1162 | * Asserts that an attribute is of a given type. |
||
| 1163 | * |
||
| 1164 | * @param string $expected |
||
| 1165 | * @param string $attributeName |
||
| 1166 | * @param string|object $classOrObject |
||
| 1167 | * @param string $message |
||
| 1168 | */ |
||
| 1169 | public function assertAttributeNotInstanceOf($expected, $attributeName, $classOrObject) { |
||
| 1170 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1171 | 'expected' => $key, |
||
| 1172 | ]); |
||
| 1173 | } |
||
| 1174 | |||
| 1175 | /** |
||
| 1176 | * Asserts that a variable is of a given type. |
||
| 1177 | * |
||
| 1178 | * @param string $expected |
||
| 1179 | */ |
||
| 1180 | public function assertInternalType($expected) { |
||
| 1181 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1182 | 'expected' => $expected, |
||
| 1183 | ]); |
||
| 1184 | } |
||
| 1185 | |||
| 1186 | /** |
||
| 1187 | * Asserts that an attribute is of a given type. |
||
| 1188 | * |
||
| 1189 | * @param string $expected |
||
| 1190 | * @param string $attributeName |
||
| 1191 | * @param string|object $classOrObject |
||
| 1192 | * @param string $message |
||
| 1193 | */ |
||
| 1194 | public function assertAttributeInternalType($expected, $attributeName, $classOrObject) { |
||
| 1195 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1196 | 'expected' => $key, |
||
| 1197 | ]); |
||
| 1198 | } |
||
| 1199 | |||
| 1200 | /** |
||
| 1201 | * Asserts that a variable is not of a given type. |
||
| 1202 | * |
||
| 1203 | * @param string $expected |
||
| 1204 | */ |
||
| 1205 | public function assertNotInternalType($expected) { |
||
| 1206 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1207 | 'expected' => $expected, |
||
| 1208 | ]); |
||
| 1209 | } |
||
| 1210 | |||
| 1211 | /** |
||
| 1212 | * Asserts that an attribute is of a given type. |
||
| 1213 | * |
||
| 1214 | * @param string $expected |
||
| 1215 | * @param string $attributeName |
||
| 1216 | * @param string|object $classOrObject |
||
| 1217 | * @param string $message |
||
| 1218 | */ |
||
| 1219 | public function assertAttributeNotInternalType($expected, $attributeName, $classOrObject) { |
||
| 1220 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1221 | 'expected' => $key, |
||
| 1222 | ]); |
||
| 1223 | } |
||
| 1224 | |||
| 1225 | /** |
||
| 1226 | * Asserts that a string matches a given regular expression. |
||
| 1227 | * |
||
| 1228 | * @param string $pattern |
||
| 1229 | */ |
||
| 1230 | public function assertRegExp($pattern) { |
||
| 1231 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1232 | 'expected' => $pattern, |
||
| 1233 | ]); |
||
| 1234 | } |
||
| 1235 | |||
| 1236 | /** |
||
| 1237 | * Asserts that a string does not match a given regular expression. |
||
| 1238 | * |
||
| 1239 | * @param string $pattern |
||
| 1240 | */ |
||
| 1241 | public function assertNotRegExp($pattern, $string) { |
||
| 1242 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1243 | 'expected' => $key, |
||
| 1244 | ]); |
||
| 1245 | } |
||
| 1246 | |||
| 1247 | /** |
||
| 1248 | * Assert that the size of two arrays (or `\Countable` or `\Traversable` objects) |
||
| 1249 | * is the same. |
||
| 1250 | * |
||
| 1251 | * @param array|\Countable|\Traversable $expected |
||
| 1252 | */ |
||
| 1253 | public function assertSameSize($expected) { |
||
| 1254 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1255 | 'expected' => $expected, |
||
| 1256 | ]); |
||
| 1257 | } |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * Assert that the size of two arrays (or `\Countable` or `\Traversable` objects) |
||
| 1261 | * is not the same. |
||
| 1262 | * |
||
| 1263 | * @param array|\Countable|\Traversable $expected |
||
| 1264 | * @param array|\Countable|\Traversable $actual |
||
| 1265 | * @param string $message |
||
| 1266 | */ |
||
| 1267 | public function assertNotSameSize($expected) { |
||
| 1268 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1269 | 'expected' => $expected, |
||
| 1270 | ]); |
||
| 1271 | } |
||
| 1272 | |||
| 1273 | /** |
||
| 1274 | * Asserts that a string matches a given format string. |
||
| 1275 | * |
||
| 1276 | * @param string $format |
||
| 1277 | */ |
||
| 1278 | public function assertStringMatchesFormat($format) { |
||
| 1279 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1280 | 'expected' => $format, |
||
| 1281 | ]); |
||
| 1282 | } |
||
| 1283 | |||
| 1284 | /** |
||
| 1285 | * Asserts that a string does not match a given format string. |
||
| 1286 | * |
||
| 1287 | * @param string $format |
||
| 1288 | */ |
||
| 1289 | public function assertStringNotMatchesFormat($format) { |
||
| 1290 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1291 | 'expected' => $format, |
||
| 1292 | ]); |
||
| 1293 | } |
||
| 1294 | |||
| 1295 | /** |
||
| 1296 | * Asserts that a string matches a given format file. |
||
| 1297 | * |
||
| 1298 | * @param string $formatFile |
||
| 1299 | */ |
||
| 1300 | public function assertStringMatchesFormatFile($formatFile) { |
||
| 1301 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1302 | 'expected' => $formatFile, |
||
| 1303 | ]); |
||
| 1304 | } |
||
| 1305 | |||
| 1306 | /** |
||
| 1307 | * Asserts that a string does not match a given format string. |
||
| 1308 | * |
||
| 1309 | * @param string $formatFile |
||
| 1310 | */ |
||
| 1311 | public function assertStringNotMatchesFormatFile($formatFile) { |
||
| 1312 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1313 | 'expected' => $formatFile, |
||
| 1314 | ]); |
||
| 1315 | } |
||
| 1316 | |||
| 1317 | /** |
||
| 1318 | * Asserts that a string starts with a given prefix. |
||
| 1319 | * |
||
| 1320 | * @param string $prefix |
||
| 1321 | */ |
||
| 1322 | public function assertStringStartsWith($prefix) { |
||
| 1323 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1324 | 'expected' => $prefix, |
||
| 1325 | ]); |
||
| 1326 | } |
||
| 1327 | |||
| 1328 | /** |
||
| 1329 | * Asserts that a string starts not with a given prefix. |
||
| 1330 | * |
||
| 1331 | * @param string $prefix |
||
| 1332 | */ |
||
| 1333 | public function assertStringStartsNotWith($prefix) { |
||
| 1334 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1335 | 'expected' => $prefix, |
||
| 1336 | ]); |
||
| 1337 | } |
||
| 1338 | |||
| 1339 | /** |
||
| 1340 | * Asserts that a string ends with a given suffix. |
||
| 1341 | * |
||
| 1342 | * @param string $suffix |
||
| 1343 | */ |
||
| 1344 | public function assertStringEndsWith($suffix) { |
||
| 1345 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1346 | 'expected' => $suffix, |
||
| 1347 | ]); |
||
| 1348 | } |
||
| 1349 | |||
| 1350 | /** |
||
| 1351 | * Asserts that a string ends not with a given suffix. |
||
| 1352 | * |
||
| 1353 | * @param string $suffix |
||
| 1354 | * @param string $string |
||
| 1355 | * @param string $message |
||
| 1356 | */ |
||
| 1357 | public function assertStringEndsNotWith($suffix) { |
||
| 1358 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1359 | 'expected' => $suffix, |
||
| 1360 | ]); |
||
| 1361 | } |
||
| 1362 | |||
| 1363 | /** |
||
| 1364 | * Asserts that two XML files are equal. |
||
| 1365 | * |
||
| 1366 | * @param string $expectedFile |
||
| 1367 | */ |
||
| 1368 | public function assertXmlFileEqualsXmlFile($expectedFile) { |
||
| 1369 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1370 | 'expected' => $expectedFile, |
||
| 1371 | ]); |
||
| 1372 | } |
||
| 1373 | |||
| 1374 | /** |
||
| 1375 | * Asserts that two XML files are not equal. |
||
| 1376 | * |
||
| 1377 | * @param string $expectedFile |
||
| 1378 | * @param string $actualFile |
||
| 1379 | * @param string $message |
||
| 1380 | */ |
||
| 1381 | public function assertXmlFileNotEqualsXmlFile($expectedFile) { |
||
| 1382 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1383 | 'expected' => $expectedFile, |
||
| 1384 | ]); |
||
| 1385 | } |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * Asserts that two XML documents are equal. |
||
| 1389 | * |
||
| 1390 | * @param string $expectedFile |
||
| 1391 | */ |
||
| 1392 | public function assertXmlStringEqualsXmlFile($expectedFile) { |
||
| 1393 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1394 | 'expected' => $expectedFile, |
||
| 1395 | ]); |
||
| 1396 | } |
||
| 1397 | |||
| 1398 | /** |
||
| 1399 | * Asserts that two XML documents are not equal. |
||
| 1400 | * |
||
| 1401 | * @param string $expectedFile |
||
| 1402 | */ |
||
| 1403 | public function assertXmlStringNotEqualsXmlFile($expectedFile) { |
||
| 1404 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1405 | 'expected' => $expectedFile, |
||
| 1406 | ]); |
||
| 1407 | } |
||
| 1408 | |||
| 1409 | /** |
||
| 1410 | * Asserts that two XML documents are equal. |
||
| 1411 | * |
||
| 1412 | * @param string|\DOMDocument $expectedXml |
||
| 1413 | * @param string $message |
||
| 1414 | */ |
||
| 1415 | public function assertXmlStringEqualsXmlString($expectedXml) { |
||
| 1416 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1417 | 'expected' => $expectedXml, |
||
| 1418 | ]); |
||
| 1419 | } |
||
| 1420 | |||
| 1421 | /** |
||
| 1422 | * Asserts that two XML documents are not equal. |
||
| 1423 | * |
||
| 1424 | * @param string|\DOMDocument $expectedXml |
||
| 1425 | */ |
||
| 1426 | public function assertXmlStringNotEqualsXmlString($expectedXml) { |
||
| 1427 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1428 | 'expected' => $expectedXml, |
||
| 1429 | ]); |
||
| 1430 | } |
||
| 1431 | |||
| 1432 | /** |
||
| 1433 | * Asserts that a hierarchy of DOMElements matches. |
||
| 1434 | * |
||
| 1435 | * @param \DOMElement $expectedElement |
||
| 1436 | * @param bool $checkAttributes |
||
| 1437 | */ |
||
| 1438 | public function assertEqualXMLStructure(\DOMElement $expectedElement, $checkAttributes = false) { |
||
| 1439 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1440 | 'expected' => $expectedElement, |
||
| 1441 | 'options' => [ |
||
| 1442 | $checkAttributes, |
||
| 1443 | ], |
||
| 1444 | ]); |
||
| 1445 | } |
||
| 1446 | |||
| 1447 | /** |
||
| 1448 | * Asserts that a string is a valid JSON string. |
||
| 1449 | */ |
||
| 1450 | public function assertJson() { |
||
| 1452 | } |
||
| 1453 | |||
| 1454 | /** |
||
| 1455 | * Asserts that two given JSON encoded objects or arrays are equal. |
||
| 1456 | * |
||
| 1457 | * @param string $expectedJson |
||
| 1458 | */ |
||
| 1459 | public function assertJsonStringEqualsJsonString($expectedJson) { |
||
| 1460 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1461 | 'expected' => $expectedJson, |
||
| 1462 | ]); |
||
| 1463 | } |
||
| 1464 | |||
| 1465 | /** |
||
| 1466 | * Asserts that two given JSON encoded objects or arrays are not equal. |
||
| 1467 | * |
||
| 1468 | * @param string $expectedJson |
||
| 1469 | */ |
||
| 1470 | public function assertJsonStringNotEqualsJsonString($expectedJson) { |
||
| 1473 | ]); |
||
| 1474 | } |
||
| 1475 | |||
| 1476 | /** |
||
| 1477 | * Asserts that the generated JSON encoded object and the content of the given file are equal. |
||
| 1478 | * |
||
| 1479 | * @param string $expectedFile |
||
| 1480 | */ |
||
| 1481 | public function assertJsonStringEqualsJsonFile($expectedFile) { |
||
| 1484 | ]); |
||
| 1485 | } |
||
| 1486 | |||
| 1487 | /** |
||
| 1488 | * Asserts that the generated JSON encoded object and the content of the given file are not equal. |
||
| 1489 | * |
||
| 1490 | * @param string $expectedFile |
||
| 1491 | */ |
||
| 1492 | public function assertJsonStringNotEqualsJsonFile($expectedFile) { |
||
| 1493 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1494 | 'expected' => $expectedFile, |
||
| 1495 | ]); |
||
| 1496 | } |
||
| 1497 | |||
| 1498 | /** |
||
| 1499 | * Asserts that two JSON files are equal. |
||
| 1500 | * |
||
| 1501 | * @param string $expectedFile |
||
| 1502 | */ |
||
| 1503 | public function assertJsonFileEqualsJsonFile($expectedFile) { |
||
| 1504 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1505 | 'expected' => $expectedFile, |
||
| 1506 | ]); |
||
| 1507 | } |
||
| 1508 | |||
| 1509 | /** |
||
| 1510 | * Asserts that two JSON files are not equal. |
||
| 1511 | * |
||
| 1512 | * @param string $expectedFile |
||
| 1513 | */ |
||
| 1514 | public function assertJsonFileNotEqualsJsonFile($expectedFile) { |
||
| 1515 | $this->callAssertMethod(__FUNCTION__, [ |
||
| 1516 | 'expected' => $expectedFile, |
||
| 1517 | ]); |
||
| 1518 | } |
||
| 1519 | } |