Complex classes like TestCase 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 TestCase, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 99 | abstract class TestCase extends Assert implements Test, SelfDescribing |
||
| 100 | { |
||
| 101 | /** |
||
| 102 | * Enable or disable the backup and restoration of the $GLOBALS array. |
||
| 103 | * Overwrite this attribute in a child class of TestCase. |
||
| 104 | * Setting this attribute in setUp() has no effect! |
||
| 105 | * |
||
| 106 | * @var bool |
||
| 107 | */ |
||
| 108 | protected $backupGlobals; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @var array |
||
| 112 | */ |
||
| 113 | protected $backupGlobalsBlacklist = []; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Enable or disable the backup and restoration of static attributes. |
||
| 117 | * Overwrite this attribute in a child class of TestCase. |
||
| 118 | * Setting this attribute in setUp() has no effect! |
||
| 119 | * |
||
| 120 | * @var bool |
||
| 121 | */ |
||
| 122 | protected $backupStaticAttributes; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @var array |
||
| 126 | */ |
||
| 127 | protected $backupStaticAttributesBlacklist = []; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Whether or not this test is to be run in a separate PHP process. |
||
| 131 | * |
||
| 132 | * @var bool |
||
| 133 | */ |
||
| 134 | protected $runTestInSeparateProcess; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Whether or not this test should preserve the global state when |
||
| 138 | * running in a separate PHP process. |
||
| 139 | * |
||
| 140 | * @var bool |
||
| 141 | */ |
||
| 142 | protected $preserveGlobalState = true; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Whether or not this test is running in a separate PHP process. |
||
| 146 | * |
||
| 147 | * @var bool |
||
| 148 | */ |
||
| 149 | private $inIsolation = false; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @var array |
||
| 153 | */ |
||
| 154 | private $data; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @var string |
||
| 158 | */ |
||
| 159 | private $dataName; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @var bool |
||
| 163 | */ |
||
| 164 | private $useErrorHandler; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * The name of the expected Exception. |
||
| 168 | * |
||
| 169 | * @var string |
||
| 170 | */ |
||
| 171 | private $expectedException; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * The message of the expected Exception. |
||
| 175 | * |
||
| 176 | * @var string |
||
| 177 | */ |
||
| 178 | private $expectedExceptionMessage = ''; |
||
| 179 | |||
| 180 | /** |
||
| 181 | * The regex pattern to validate the expected Exception message. |
||
| 182 | * |
||
| 183 | * @var string |
||
| 184 | */ |
||
| 185 | private $expectedExceptionMessageRegExp = ''; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * The code of the expected Exception. |
||
| 189 | * |
||
| 190 | * @var int|string |
||
| 191 | */ |
||
| 192 | private $expectedExceptionCode; |
||
| 193 | |||
| 194 | /** |
||
| 195 | * The name of the test case. |
||
| 196 | * |
||
| 197 | * @var string |
||
| 198 | */ |
||
| 199 | private $name; |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @var array |
||
| 203 | */ |
||
| 204 | private $dependencies = []; |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @var array |
||
| 208 | */ |
||
| 209 | private $dependencyInput = []; |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @var array |
||
| 213 | */ |
||
| 214 | private $iniSettings = []; |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @var array |
||
| 218 | */ |
||
| 219 | private $locale = []; |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @var array |
||
| 223 | */ |
||
| 224 | private $mockObjects = []; |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @var array |
||
| 228 | */ |
||
| 229 | private $mockObjectGenerator; |
||
| 230 | |||
| 231 | /** |
||
| 232 | * @var int |
||
| 233 | */ |
||
| 234 | private $status; |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @var string |
||
| 238 | */ |
||
| 239 | private $statusMessage = ''; |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @var int |
||
| 243 | */ |
||
| 244 | private $numAssertions = 0; |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @var TestResult |
||
| 248 | */ |
||
| 249 | private $result; |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @var mixed |
||
| 253 | */ |
||
| 254 | private $testResult; |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @var string |
||
| 258 | */ |
||
| 259 | private $output = ''; |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @var string |
||
| 263 | */ |
||
| 264 | private $outputExpectedRegex; |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @var string |
||
| 268 | */ |
||
| 269 | private $outputExpectedString; |
||
| 270 | |||
| 271 | /** |
||
| 272 | * @var mixed |
||
| 273 | */ |
||
| 274 | private $outputCallback = false; |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @var bool |
||
| 278 | */ |
||
| 279 | private $outputBufferingActive = false; |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @var int |
||
| 283 | */ |
||
| 284 | private $outputBufferingLevel; |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @var SebastianBergmann\GlobalState\Snapshot |
||
| 288 | */ |
||
| 289 | private $snapshot; |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @var Prophecy\Prophet |
||
| 293 | */ |
||
| 294 | private $prophet; |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @var bool |
||
| 298 | */ |
||
| 299 | private $beStrictAboutChangesToGlobalState = false; |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @var bool |
||
| 303 | */ |
||
| 304 | private $registerMockObjectsFromTestArgumentsRecursively = false; |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @var string[] |
||
| 308 | */ |
||
| 309 | private $warnings = []; |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @var array |
||
| 313 | */ |
||
| 314 | private $groups = []; |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @var bool |
||
| 318 | */ |
||
| 319 | private $doesNotPerformAssertions = false; |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Constructs a test case with the given name. |
||
| 323 | * |
||
| 324 | * @param string $name |
||
| 325 | * @param array $data |
||
| 326 | * @param string $dataName |
||
| 327 | */ |
||
| 328 | public function __construct($name = null, array $data = [], $dataName = '') |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Returns a string representation of the test case. |
||
| 340 | * |
||
| 341 | * @return string |
||
| 342 | */ |
||
| 343 | public function toString() |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Counts the number of test cases executed by run(TestResult result). |
||
| 358 | * |
||
| 359 | * @return int |
||
| 360 | */ |
||
| 361 | public function count() |
||
| 365 | |||
| 366 | public function getGroups() |
||
| 370 | |||
| 371 | /** |
||
| 372 | * @param array $groups |
||
| 373 | */ |
||
| 374 | public function setGroups(array $groups) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Returns the annotations for this test. |
||
| 381 | * |
||
| 382 | * @return array |
||
| 383 | */ |
||
| 384 | public function getAnnotations() |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Gets the name of a TestCase. |
||
| 394 | * |
||
| 395 | * @param bool $withDataSet |
||
| 396 | * |
||
| 397 | * @return string |
||
| 398 | */ |
||
| 399 | public function getName($withDataSet = true) |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Returns the size of the test. |
||
| 410 | * |
||
| 411 | * @return int |
||
| 412 | */ |
||
| 413 | public function getSize() |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @return bool |
||
| 423 | */ |
||
| 424 | public function hasSize() |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @return bool |
||
| 431 | */ |
||
| 432 | public function isSmall() |
||
| 436 | |||
| 437 | /** |
||
| 438 | * @return bool |
||
| 439 | */ |
||
| 440 | public function isMedium() |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @return bool |
||
| 447 | */ |
||
| 448 | public function isLarge() |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @return string |
||
| 455 | */ |
||
| 456 | public function getActualOutput() |
||
| 464 | |||
| 465 | /** |
||
| 466 | * @return bool |
||
| 467 | */ |
||
| 468 | public function hasOutput() |
||
| 480 | |||
| 481 | /** |
||
| 482 | * @return bool |
||
| 483 | */ |
||
| 484 | public function doesNotPerformAssertions() |
||
| 488 | |||
| 489 | /** |
||
| 490 | * @param string $expectedRegex |
||
| 491 | * |
||
| 492 | * @throws Exception |
||
| 493 | */ |
||
| 494 | public function expectOutputRegex($expectedRegex) |
||
| 504 | |||
| 505 | /** |
||
| 506 | * @param string $expectedString |
||
| 507 | */ |
||
| 508 | public function expectOutputString($expectedString) |
||
| 518 | |||
| 519 | /** |
||
| 520 | * @return bool |
||
| 521 | */ |
||
| 522 | public function hasExpectationOnOutput() |
||
| 526 | |||
| 527 | /** |
||
| 528 | * @return string |
||
| 529 | */ |
||
| 530 | public function getExpectedException() |
||
| 534 | |||
| 535 | /** |
||
| 536 | * @return int|string |
||
| 537 | */ |
||
| 538 | public function getExpectedExceptionCode() |
||
| 542 | |||
| 543 | /** |
||
| 544 | * @return string |
||
| 545 | */ |
||
| 546 | public function getExpectedExceptionMessage() |
||
| 550 | |||
| 551 | /** |
||
| 552 | * @param string $exception |
||
| 553 | */ |
||
| 554 | public function expectException($exception) |
||
| 562 | |||
| 563 | /** |
||
| 564 | * @param int|string $code |
||
| 565 | * |
||
| 566 | * @throws Exception |
||
| 567 | */ |
||
| 568 | public function expectExceptionCode($code) |
||
| 580 | |||
| 581 | /** |
||
| 582 | * @param string $message |
||
| 583 | * |
||
| 584 | * @throws Exception |
||
| 585 | */ |
||
| 586 | public function expectExceptionMessage($message) |
||
| 598 | |||
| 599 | /** |
||
| 600 | * @param string $messageRegExp |
||
| 601 | * |
||
| 602 | * @throws Exception |
||
| 603 | */ |
||
| 604 | public function expectExceptionMessageRegExp($messageRegExp) |
||
| 612 | |||
| 613 | /** |
||
| 614 | * @param bool $flag |
||
| 615 | */ |
||
| 616 | public function setRegisterMockObjectsFromTestArgumentsRecursively($flag) |
||
| 624 | |||
| 625 | protected function setExpectedExceptionFromAnnotation() |
||
| 649 | |||
| 650 | /** |
||
| 651 | * @param bool $useErrorHandler |
||
| 652 | */ |
||
| 653 | public function setUseErrorHandler($useErrorHandler) |
||
| 657 | |||
| 658 | protected function setUseErrorHandlerFromAnnotation() |
||
| 672 | |||
| 673 | protected function checkRequirements() |
||
| 688 | |||
| 689 | /** |
||
| 690 | * Returns the status of this test. |
||
| 691 | * |
||
| 692 | * @return int |
||
| 693 | */ |
||
| 694 | public function getStatus() |
||
| 698 | |||
| 699 | public function markAsRisky() |
||
| 703 | |||
| 704 | /** |
||
| 705 | * Returns the status message of this test. |
||
| 706 | * |
||
| 707 | * @return string |
||
| 708 | */ |
||
| 709 | public function getStatusMessage() |
||
| 713 | |||
| 714 | /** |
||
| 715 | * Returns whether or not this test has failed. |
||
| 716 | * |
||
| 717 | * @return bool |
||
| 718 | */ |
||
| 719 | public function hasFailed() |
||
| 726 | |||
| 727 | /** |
||
| 728 | * Runs the test case and collects the results in a TestResult object. |
||
| 729 | * If no TestResult object is passed a new one will be created. |
||
| 730 | * |
||
| 731 | * @param TestResult $result |
||
| 732 | * |
||
| 733 | * @return TestResult |
||
| 734 | * |
||
| 735 | * @throws Exception |
||
| 736 | */ |
||
| 737 | public function run(TestResult $result = null) |
||
| 866 | |||
| 867 | /** |
||
| 868 | * Runs the bare test sequence. |
||
| 869 | */ |
||
| 870 | public function runBare() |
||
| 1012 | |||
| 1013 | /** |
||
| 1014 | * Override to run the test and assert its state. |
||
| 1015 | * |
||
| 1016 | * @return mixed |
||
| 1017 | * |
||
| 1018 | * @throws Exception|Exception |
||
| 1019 | * @throws Exception |
||
| 1020 | */ |
||
| 1021 | protected function runTest() |
||
| 1119 | |||
| 1120 | /** |
||
| 1121 | * Verifies the mock object expectations. |
||
| 1122 | */ |
||
| 1123 | protected function verifyMockObjects() |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Sets the name of a TestCase. |
||
| 1158 | * |
||
| 1159 | * @param string |
||
| 1160 | */ |
||
| 1161 | public function setName($name) |
||
| 1165 | |||
| 1166 | /** |
||
| 1167 | * Sets the dependencies of a TestCase. |
||
| 1168 | * |
||
| 1169 | * @param array $dependencies |
||
| 1170 | */ |
||
| 1171 | public function setDependencies(array $dependencies) |
||
| 1175 | |||
| 1176 | /** |
||
| 1177 | * Returns true if the tests has dependencies |
||
| 1178 | * |
||
| 1179 | * @return bool |
||
| 1180 | */ |
||
| 1181 | public function hasDependencies() |
||
| 1185 | |||
| 1186 | /** |
||
| 1187 | * Sets |
||
| 1188 | * |
||
| 1189 | * @param array $dependencyInput |
||
| 1190 | */ |
||
| 1191 | public function setDependencyInput(array $dependencyInput) |
||
| 1195 | |||
| 1196 | /** |
||
| 1197 | * @param bool $beStrictAboutChangesToGlobalState |
||
| 1198 | */ |
||
| 1199 | public function setBeStrictAboutChangesToGlobalState($beStrictAboutChangesToGlobalState) |
||
| 1203 | |||
| 1204 | /** |
||
| 1205 | * Calling this method in setUp() has no effect! |
||
| 1206 | * |
||
| 1207 | * @param bool $backupGlobals |
||
| 1208 | */ |
||
| 1209 | public function setBackupGlobals($backupGlobals) |
||
| 1215 | |||
| 1216 | /** |
||
| 1217 | * Calling this method in setUp() has no effect! |
||
| 1218 | * |
||
| 1219 | * @param bool $backupStaticAttributes |
||
| 1220 | */ |
||
| 1221 | public function setBackupStaticAttributes($backupStaticAttributes) |
||
| 1228 | |||
| 1229 | /** |
||
| 1230 | * @param bool $runTestInSeparateProcess |
||
| 1231 | * |
||
| 1232 | * @throws Exception |
||
| 1233 | */ |
||
| 1234 | public function setRunTestInSeparateProcess($runTestInSeparateProcess) |
||
| 1244 | |||
| 1245 | /** |
||
| 1246 | * @param bool $preserveGlobalState |
||
| 1247 | * |
||
| 1248 | * @throws Exception |
||
| 1249 | */ |
||
| 1250 | public function setPreserveGlobalState($preserveGlobalState) |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * @param bool $inIsolation |
||
| 1261 | * |
||
| 1262 | * @throws Exception |
||
| 1263 | */ |
||
| 1264 | public function setInIsolation($inIsolation) |
||
| 1272 | |||
| 1273 | /** |
||
| 1274 | * @return bool |
||
| 1275 | */ |
||
| 1276 | public function isInIsolation() |
||
| 1280 | |||
| 1281 | /** |
||
| 1282 | * @return mixed |
||
| 1283 | */ |
||
| 1284 | public function getResult() |
||
| 1288 | |||
| 1289 | /** |
||
| 1290 | * @param mixed $result |
||
| 1291 | */ |
||
| 1292 | public function setResult($result) |
||
| 1296 | |||
| 1297 | /** |
||
| 1298 | * @param callable $callback |
||
| 1299 | * |
||
| 1300 | * @throws Exception |
||
| 1301 | */ |
||
| 1302 | public function setOutputCallback($callback) |
||
| 1310 | |||
| 1311 | /** |
||
| 1312 | * @return TestResult |
||
| 1313 | */ |
||
| 1314 | public function getTestResultObject() |
||
| 1318 | |||
| 1319 | /** |
||
| 1320 | * @param TestResult $result |
||
| 1321 | */ |
||
| 1322 | public function setTestResultObject(TestResult $result) |
||
| 1326 | |||
| 1327 | /** |
||
| 1328 | * @param PHPUnit_Framework_MockObject_MockObject $mockObject |
||
| 1329 | */ |
||
| 1330 | public function registerMockObject(PHPUnit_Framework_MockObject_MockObject $mockObject) |
||
| 1334 | |||
| 1335 | /** |
||
| 1336 | * This method is a wrapper for the ini_set() function that automatically |
||
| 1337 | * resets the modified php.ini setting to its original value after the |
||
| 1338 | * test is run. |
||
| 1339 | * |
||
| 1340 | * @param string $varName |
||
| 1341 | * @param string $newValue |
||
| 1342 | * |
||
| 1343 | * @throws Exception |
||
| 1344 | */ |
||
| 1345 | protected function iniSet($varName, $newValue) |
||
| 1365 | |||
| 1366 | /** |
||
| 1367 | * This method is a wrapper for the setlocale() function that automatically |
||
| 1368 | * resets the locale to its original value after the test is run. |
||
| 1369 | * |
||
| 1370 | * @param int $category |
||
| 1371 | * @param string $locale |
||
| 1372 | * |
||
| 1373 | * @throws Exception |
||
| 1374 | */ |
||
| 1375 | protected function setLocale() |
||
| 1414 | |||
| 1415 | /** |
||
| 1416 | * Returns a builder object to create mock objects using a fluent interface. |
||
| 1417 | * |
||
| 1418 | * @param string $className |
||
| 1419 | * |
||
| 1420 | * @return PHPUnit_Framework_MockObject_MockBuilder |
||
| 1421 | */ |
||
| 1422 | public function getMockBuilder($className) |
||
| 1426 | |||
| 1427 | /** |
||
| 1428 | * Returns a test double for the specified class. |
||
| 1429 | * |
||
| 1430 | * @param string $originalClassName |
||
| 1431 | * |
||
| 1432 | * @return PHPUnit_Framework_MockObject_MockObject |
||
| 1433 | * |
||
| 1434 | * @throws Exception |
||
| 1435 | */ |
||
| 1436 | protected function createMock($originalClassName) |
||
| 1445 | |||
| 1446 | /** |
||
| 1447 | * Returns a configured test double for the specified class. |
||
| 1448 | * |
||
| 1449 | * @param string $originalClassName |
||
| 1450 | * @param array $configuration |
||
| 1451 | * |
||
| 1452 | * @return PHPUnit_Framework_MockObject_MockObject |
||
| 1453 | * |
||
| 1454 | * @throws Exception |
||
| 1455 | */ |
||
| 1456 | protected function createConfiguredMock($originalClassName, array $configuration) |
||
| 1466 | |||
| 1467 | /** |
||
| 1468 | * Returns a partial test double for the specified class. |
||
| 1469 | * |
||
| 1470 | * @param string $originalClassName |
||
| 1471 | * @param array $methods |
||
| 1472 | * |
||
| 1473 | * @return PHPUnit_Framework_MockObject_MockObject |
||
| 1474 | * |
||
| 1475 | * @throws Exception |
||
| 1476 | */ |
||
| 1477 | protected function createPartialMock($originalClassName, array $methods) |
||
| 1487 | |||
| 1488 | /** |
||
| 1489 | * Returns a test proxy for the specified class. |
||
| 1490 | * |
||
| 1491 | * @param string $originalClassName |
||
| 1492 | * @param array $constructorArguments |
||
| 1493 | * |
||
| 1494 | * @return PHPUnit_Framework_MockObject_MockObject |
||
| 1495 | * |
||
| 1496 | * @throws Exception |
||
| 1497 | */ |
||
| 1498 | protected function createTestProxy($originalClassName, array $constructorArguments = []) |
||
| 1505 | |||
| 1506 | /** |
||
| 1507 | * Mocks the specified class and returns the name of the mocked class. |
||
| 1508 | * |
||
| 1509 | * @param string $originalClassName |
||
| 1510 | * @param array $methods |
||
| 1511 | * @param array $arguments |
||
| 1512 | * @param string $mockClassName |
||
| 1513 | * @param bool $callOriginalConstructor |
||
| 1514 | * @param bool $callOriginalClone |
||
| 1515 | * @param bool $callAutoload |
||
| 1516 | * @param bool $cloneArguments |
||
| 1517 | * |
||
| 1518 | * @return string |
||
| 1519 | * |
||
| 1520 | * @throws Exception |
||
| 1521 | */ |
||
| 1522 | protected function getMockClass($originalClassName, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = false, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false) |
||
| 1537 | |||
| 1538 | /** |
||
| 1539 | * Returns a mock object for the specified abstract class with all abstract |
||
| 1540 | * methods of the class mocked. Concrete methods are not mocked by default. |
||
| 1541 | * To mock concrete methods, use the 7th parameter ($mockedMethods). |
||
| 1542 | * |
||
| 1543 | * @param string $originalClassName |
||
| 1544 | * @param array $arguments |
||
| 1545 | * @param string $mockClassName |
||
| 1546 | * @param bool $callOriginalConstructor |
||
| 1547 | * @param bool $callOriginalClone |
||
| 1548 | * @param bool $callAutoload |
||
| 1549 | * @param array $mockedMethods |
||
| 1550 | * @param bool $cloneArguments |
||
| 1551 | * |
||
| 1552 | * @return PHPUnit_Framework_MockObject_MockObject |
||
| 1553 | * |
||
| 1554 | * @throws Exception |
||
| 1555 | */ |
||
| 1556 | protected function getMockForAbstractClass($originalClassName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = false) |
||
| 1573 | |||
| 1574 | /** |
||
| 1575 | * Returns a mock object based on the given WSDL file. |
||
| 1576 | * |
||
| 1577 | * @param string $wsdlFile |
||
| 1578 | * @param string $originalClassName |
||
| 1579 | * @param string $mockClassName |
||
| 1580 | * @param array $methods |
||
| 1581 | * @param bool $callOriginalConstructor |
||
| 1582 | * @param array $options An array of options passed to SOAPClient::_construct |
||
| 1583 | * |
||
| 1584 | * @return PHPUnit_Framework_MockObject_MockObject |
||
| 1585 | */ |
||
| 1586 | protected function getMockFromWsdl($wsdlFile, $originalClassName = '', $mockClassName = '', array $methods = [], $callOriginalConstructor = true, array $options = []) |
||
| 1617 | |||
| 1618 | /** |
||
| 1619 | * Returns a mock object for the specified trait with all abstract methods |
||
| 1620 | * of the trait mocked. Concrete methods to mock can be specified with the |
||
| 1621 | * `$mockedMethods` parameter. |
||
| 1622 | * |
||
| 1623 | * @param string $traitName |
||
| 1624 | * @param array $arguments |
||
| 1625 | * @param string $mockClassName |
||
| 1626 | * @param bool $callOriginalConstructor |
||
| 1627 | * @param bool $callOriginalClone |
||
| 1628 | * @param bool $callAutoload |
||
| 1629 | * @param array $mockedMethods |
||
| 1630 | * @param bool $cloneArguments |
||
| 1631 | * |
||
| 1632 | * @return PHPUnit_Framework_MockObject_MockObject |
||
| 1633 | * |
||
| 1634 | * @throws Exception |
||
| 1635 | */ |
||
| 1636 | protected function getMockForTrait($traitName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = false) |
||
| 1653 | |||
| 1654 | /** |
||
| 1655 | * Returns an object for the specified trait. |
||
| 1656 | * |
||
| 1657 | * @param string $traitName |
||
| 1658 | * @param array $arguments |
||
| 1659 | * @param string $traitClassName |
||
| 1660 | * @param bool $callOriginalConstructor |
||
| 1661 | * @param bool $callOriginalClone |
||
| 1662 | * @param bool $callAutoload |
||
| 1663 | * |
||
| 1664 | * @return object |
||
| 1665 | * |
||
| 1666 | * @throws Exception |
||
| 1667 | */ |
||
| 1668 | protected function getObjectForTrait($traitName, array $arguments = [], $traitClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true) |
||
| 1679 | |||
| 1680 | /** |
||
| 1681 | * @param string|null $classOrInterface |
||
| 1682 | * |
||
| 1683 | * @return \Prophecy\Prophecy\ObjectProphecy |
||
| 1684 | * |
||
| 1685 | * @throws \LogicException |
||
| 1686 | */ |
||
| 1687 | protected function prophesize($classOrInterface = null) |
||
| 1691 | |||
| 1692 | /** |
||
| 1693 | * Adds a value to the assertion counter. |
||
| 1694 | * |
||
| 1695 | * @param int $count |
||
| 1696 | */ |
||
| 1697 | public function addToAssertionCount($count) |
||
| 1701 | |||
| 1702 | /** |
||
| 1703 | * Returns the number of assertions performed by this test. |
||
| 1704 | * |
||
| 1705 | * @return int |
||
| 1706 | */ |
||
| 1707 | public function getNumAssertions() |
||
| 1711 | |||
| 1712 | /** |
||
| 1713 | * Returns a matcher that matches when the method is executed |
||
| 1714 | * zero or more times. |
||
| 1715 | * |
||
| 1716 | * @return PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount |
||
| 1717 | */ |
||
| 1718 | public static function any() |
||
| 1722 | |||
| 1723 | /** |
||
| 1724 | * Returns a matcher that matches when the method is never executed. |
||
| 1725 | * |
||
| 1726 | * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount |
||
| 1727 | */ |
||
| 1728 | public static function never() |
||
| 1732 | |||
| 1733 | /** |
||
| 1734 | * Returns a matcher that matches when the method is executed |
||
| 1735 | * at least N times. |
||
| 1736 | * |
||
| 1737 | * @param int $requiredInvocations |
||
| 1738 | * |
||
| 1739 | * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastCount |
||
| 1740 | */ |
||
| 1741 | public static function atLeast($requiredInvocations) |
||
| 1747 | |||
| 1748 | /** |
||
| 1749 | * Returns a matcher that matches when the method is executed at least once. |
||
| 1750 | * |
||
| 1751 | * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce |
||
| 1752 | */ |
||
| 1753 | public static function atLeastOnce() |
||
| 1757 | |||
| 1758 | /** |
||
| 1759 | * Returns a matcher that matches when the method is executed exactly once. |
||
| 1760 | * |
||
| 1761 | * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount |
||
| 1762 | */ |
||
| 1763 | public static function once() |
||
| 1767 | |||
| 1768 | /** |
||
| 1769 | * Returns a matcher that matches when the method is executed |
||
| 1770 | * exactly $count times. |
||
| 1771 | * |
||
| 1772 | * @param int $count |
||
| 1773 | * |
||
| 1774 | * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount |
||
| 1775 | */ |
||
| 1776 | public static function exactly($count) |
||
| 1780 | |||
| 1781 | /** |
||
| 1782 | * Returns a matcher that matches when the method is executed |
||
| 1783 | * at most N times. |
||
| 1784 | * |
||
| 1785 | * @param int $allowedInvocations |
||
| 1786 | * |
||
| 1787 | * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtMostCount |
||
| 1788 | */ |
||
| 1789 | public static function atMost($allowedInvocations) |
||
| 1795 | |||
| 1796 | /** |
||
| 1797 | * Returns a matcher that matches when the method is executed |
||
| 1798 | * at the given index. |
||
| 1799 | * |
||
| 1800 | * @param int $index |
||
| 1801 | * |
||
| 1802 | * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex |
||
| 1803 | */ |
||
| 1804 | public static function at($index) |
||
| 1808 | |||
| 1809 | /** |
||
| 1810 | * @param mixed $value |
||
| 1811 | * |
||
| 1812 | * @return PHPUnit_Framework_MockObject_Stub_Return |
||
| 1813 | */ |
||
| 1814 | public static function returnValue($value) |
||
| 1818 | |||
| 1819 | /** |
||
| 1820 | * @param array $valueMap |
||
| 1821 | * |
||
| 1822 | * @return PHPUnit_Framework_MockObject_Stub_ReturnValueMap |
||
| 1823 | */ |
||
| 1824 | public static function returnValueMap(array $valueMap) |
||
| 1828 | |||
| 1829 | /** |
||
| 1830 | * @param int $argumentIndex |
||
| 1831 | * |
||
| 1832 | * @return PHPUnit_Framework_MockObject_Stub_ReturnArgument |
||
| 1833 | */ |
||
| 1834 | public static function returnArgument($argumentIndex) |
||
| 1840 | |||
| 1841 | /** |
||
| 1842 | * @param mixed $callback |
||
| 1843 | * |
||
| 1844 | * @return PHPUnit_Framework_MockObject_Stub_ReturnCallback |
||
| 1845 | */ |
||
| 1846 | public static function returnCallback($callback) |
||
| 1850 | |||
| 1851 | /** |
||
| 1852 | * Returns the current object. |
||
| 1853 | * |
||
| 1854 | * This method is useful when mocking a fluent interface. |
||
| 1855 | * |
||
| 1856 | * @return PHPUnit_Framework_MockObject_Stub_ReturnSelf |
||
| 1857 | */ |
||
| 1858 | public static function returnSelf() |
||
| 1862 | |||
| 1863 | /** |
||
| 1864 | * @param Throwable $exception |
||
| 1865 | * |
||
| 1866 | * @return PHPUnit_Framework_MockObject_Stub_Exception |
||
| 1867 | */ |
||
| 1868 | public static function throwException(Throwable $exception) |
||
| 1872 | |||
| 1873 | /** |
||
| 1874 | * @param mixed $value , ... |
||
| 1875 | * |
||
| 1876 | * @return PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls |
||
| 1877 | */ |
||
| 1878 | public static function onConsecutiveCalls() |
||
| 1884 | |||
| 1885 | /** |
||
| 1886 | * @return bool |
||
| 1887 | */ |
||
| 1888 | public function usesDataProvider() |
||
| 1892 | |||
| 1893 | /** |
||
| 1894 | * @return string |
||
| 1895 | */ |
||
| 1896 | public function dataDescription() |
||
| 1900 | |||
| 1901 | /** |
||
| 1902 | * Gets the data set description of a TestCase. |
||
| 1903 | * |
||
| 1904 | * @param bool $includeData |
||
| 1905 | * |
||
| 1906 | * @return string |
||
| 1907 | */ |
||
| 1908 | protected function getDataSetAsString($includeData = true) |
||
| 1928 | |||
| 1929 | /** |
||
| 1930 | * Gets the data set of a TestCase. |
||
| 1931 | * |
||
| 1932 | * @return array |
||
| 1933 | */ |
||
| 1934 | protected function getProvidedData() |
||
| 1938 | |||
| 1939 | /** |
||
| 1940 | * Creates a default TestResult object. |
||
| 1941 | * |
||
| 1942 | * @return TestResult |
||
| 1943 | */ |
||
| 1944 | protected function createResult() |
||
| 1948 | |||
| 1949 | protected function handleDependencies() |
||
| 2030 | |||
| 2031 | /** |
||
| 2032 | * This method is called before the first test of this test class is run. |
||
| 2033 | */ |
||
| 2034 | public static function setUpBeforeClass() |
||
| 2037 | |||
| 2038 | /** |
||
| 2039 | * Sets up the fixture, for example, open a network connection. |
||
| 2040 | * This method is called before a test is executed. |
||
| 2041 | */ |
||
| 2042 | protected function setUp() |
||
| 2045 | |||
| 2046 | /** |
||
| 2047 | * Performs assertions shared by all tests of a test case. |
||
| 2048 | * |
||
| 2049 | * This method is called before the execution of a test starts |
||
| 2050 | * and after setUp() is called. |
||
| 2051 | */ |
||
| 2052 | protected function assertPreConditions() |
||
| 2055 | |||
| 2056 | /** |
||
| 2057 | * Performs assertions shared by all tests of a test case. |
||
| 2058 | * |
||
| 2059 | * This method is called before the execution of a test ends |
||
| 2060 | * and before tearDown() is called. |
||
| 2061 | */ |
||
| 2062 | protected function assertPostConditions() |
||
| 2065 | |||
| 2066 | /** |
||
| 2067 | * Tears down the fixture, for example, close a network connection. |
||
| 2068 | * This method is called after a test is executed. |
||
| 2069 | */ |
||
| 2070 | protected function tearDown() |
||
| 2073 | |||
| 2074 | /** |
||
| 2075 | * This method is called after the last test of this test class is run. |
||
| 2076 | */ |
||
| 2077 | public static function tearDownAfterClass() |
||
| 2080 | |||
| 2081 | /** |
||
| 2082 | * This method is called when a test method did not execute successfully. |
||
| 2083 | * |
||
| 2084 | * @param Throwable $t |
||
| 2085 | * |
||
| 2086 | * @throws Throwable |
||
| 2087 | */ |
||
| 2088 | protected function onNotSuccessfulTest(Throwable $t) |
||
| 2092 | |||
| 2093 | /** |
||
| 2094 | * Performs custom preparations on the process isolation template. |
||
| 2095 | * |
||
| 2096 | * @param Text_Template $template |
||
| 2097 | */ |
||
| 2098 | protected function prepareTemplate(Text_Template $template) |
||
| 2101 | |||
| 2102 | /** |
||
| 2103 | * Get the mock object generator, creating it if it doesn't exist. |
||
| 2104 | * |
||
| 2105 | * @return PHPUnit_Framework_MockObject_Generator |
||
| 2106 | */ |
||
| 2107 | private function getMockObjectGenerator() |
||
| 2115 | |||
| 2116 | private function startOutputBuffering() |
||
| 2123 | |||
| 2124 | private function stopOutputBuffering() |
||
| 2152 | |||
| 2153 | private function snapshotGlobalState() |
||
| 2163 | |||
| 2164 | private function restoreGlobalState() |
||
| 2197 | |||
| 2198 | /** |
||
| 2199 | * @param bool $backupGlobals |
||
| 2200 | * |
||
| 2201 | * @return Snapshot |
||
| 2202 | */ |
||
| 2203 | private function createGlobalStateSnapshot($backupGlobals) |
||
| 2243 | |||
| 2244 | /** |
||
| 2245 | * @param Snapshot $before |
||
| 2246 | * @param Snapshot $after |
||
| 2247 | * |
||
| 2248 | * @throws RiskyTestError |
||
| 2249 | */ |
||
| 2250 | private function compareGlobalStateSnapshots(Snapshot $before, Snapshot $after) |
||
| 2276 | |||
| 2277 | /** |
||
| 2278 | * @param array $before |
||
| 2279 | * @param array $after |
||
| 2280 | * @param string $header |
||
| 2281 | * |
||
| 2282 | * @throws RiskyTestError |
||
| 2283 | */ |
||
| 2284 | private function compareGlobalStateSnapshotPart(array $before, array $after, $header) |
||
| 2300 | |||
| 2301 | /** |
||
| 2302 | * @return Prophecy\Prophet |
||
| 2303 | */ |
||
| 2304 | private function getProphet() |
||
| 2312 | |||
| 2313 | /** |
||
| 2314 | * @param PHPUnit_Framework_MockObject_MockObject $mock |
||
| 2315 | * |
||
| 2316 | * @return bool |
||
| 2317 | */ |
||
| 2318 | private function shouldInvocationMockerBeReset(PHPUnit_Framework_MockObject_MockObject $mock) |
||
| 2340 | |||
| 2341 | /** |
||
| 2342 | * @param array $testArguments |
||
| 2343 | * @param array $originalTestArguments |
||
| 2344 | */ |
||
| 2345 | private function registerMockObjectsFromTestArguments(array $testArguments, array &$visited = []) |
||
| 2374 | |||
| 2375 | private function setDoesNotPerformAssertionsFromAnnotation() |
||
| 2383 | |||
| 2384 | /** |
||
| 2385 | * @param PHPUnit_Framework_MockObject_MockObject $testArgument |
||
| 2386 | * |
||
| 2387 | * @return bool |
||
| 2388 | */ |
||
| 2389 | private function isCloneable(PHPUnit_Framework_MockObject_MockObject $testArgument) |
||
| 2404 | } |
||
| 2405 |