How to use methodDoesNotExistOrIsDeclaredInTestCase method of TestSuite class

Best Phpunit code snippet using TestSuite.methodDoesNotExistOrIsDeclaredInTestCase

TestCase.php

Source:TestCase.php Github

copy

Full Screen

...583 $hasMetRequirements = true;584 if ($this->inIsolation) {585 $methodsCalledBeforeFirstTest = [];586 foreach ($hookMethods['beforeClass'] as $method) {587 if ($this->methodDoesNotExistOrIsDeclaredInTestCase($method)) {588 continue;589 }590 $this->{$method}();591 $methodCalledBeforeFirstTest = new Event\Code\ClassMethod(592 static::class,593 $method594 );595 $emitter->testBeforeFirstTestMethodCalled(596 static::class,597 $methodCalledBeforeFirstTest598 );599 $methodsCalledBeforeFirstTest[] = $methodCalledBeforeFirstTest;600 }601 if (!empty($methodsCalledBeforeFirstTest)) {602 $emitter->testBeforeFirstTestMethodFinished(603 static::class,604 ...$methodsCalledBeforeFirstTest605 );606 }607 }608 if (method_exists(static::class, $this->name) &&609 MetadataRegistry::parser()->forMethod(static::class, $this->name)->isDoesNotPerformAssertions()->isNotEmpty()) {610 $this->doesNotPerformAssertions = true;611 }612 $methodsCalledBeforeTest = [];613 foreach ($hookMethods['before'] as $method) {614 if ($this->methodDoesNotExistOrIsDeclaredInTestCase($method)) {615 continue;616 }617 $this->{$method}();618 $methodCallBeforeTest = new Event\Code\ClassMethod(619 static::class,620 $method621 );622 $emitter->testBeforeTestMethodCalled(623 static::class,624 $methodCallBeforeTest625 );626 $methodsCalledBeforeTest[] = $methodCallBeforeTest;627 }628 if (!empty($methodsCalledBeforeTest)) {629 $emitter->testBeforeTestMethodFinished(630 static::class,631 ...$methodsCalledBeforeTest632 );633 }634 $methodsCalledPreCondition = [];635 foreach ($hookMethods['preCondition'] as $method) {636 if ($this->methodDoesNotExistOrIsDeclaredInTestCase($method)) {637 continue;638 }639 $this->{$method}();640 $methodCalledPreCondition = new Event\Code\ClassMethod(641 static::class,642 $method643 );644 $emitter->testPreConditionCalled(645 static::class,646 $methodCalledPreCondition647 );648 $methodsCalledPreCondition[] = $methodCalledPreCondition;649 }650 if (!empty($methodsCalledPreCondition)) {651 $emitter->testPreConditionFinished(652 static::class,653 ...$methodsCalledPreCondition654 );655 }656 $emitter->testPrepared(657 $this->valueObjectForEvents()658 );659 $this->wasPrepared = true;660 $this->testResult = $this->runTest();661 if ($this->hasOutput()) {662 $emitter->testOutputPrinted(663 $this->valueObjectForEvents(),664 $this->output()665 );666 }667 $this->verifyMockObjects();668 $methodsCalledPostCondition = [];669 foreach ($hookMethods['postCondition'] as $method) {670 if ($this->methodDoesNotExistOrIsDeclaredInTestCase($method)) {671 continue;672 }673 $this->{$method}();674 $methodCalledPostCondition = new Event\Code\ClassMethod(675 static::class,676 $method677 );678 $emitter->testPostConditionCalled(679 static::class,680 $methodCalledPostCondition681 );682 $methodsCalledPostCondition[] = $methodCalledPostCondition;683 }684 if (!empty($methodsCalledPostCondition)) {685 $emitter->testPostConditionFinished(686 static::class,687 ...$methodsCalledPostCondition688 );689 }690 if (!empty($this->warnings)) {691 throw new Warning(692 implode(693 "\n",694 array_unique($this->warnings)695 )696 );697 }698 $this->status = TestStatus::success();699 } catch (IncompleteTest $e) {700 $this->status = TestStatus::incomplete($e->getMessage());701 $emitter->testAborted(702 $this->valueObjectForEvents(),703 Event\Code\Throwable::from($e)704 );705 } catch (SkippedTest $e) {706 $this->status = TestStatus::skipped($e->getMessage());707 $emitter->testSkipped(708 $this->valueObjectForEvents(),709 $e->getMessage()710 );711 } catch (Warning $e) {712 $this->status = TestStatus::warning($e->getMessage());713 $emitter->testPassedWithWarning(714 $this->valueObjectForEvents(),715 Event\Code\Throwable::from($e)716 );717 } catch (AssertionFailedError $e) {718 $this->status = TestStatus::failure($e->getMessage());719 $emitter->testFailed(720 $this->valueObjectForEvents(),721 Event\Code\Throwable::from($e)722 );723 } catch (Throwable $_e) {724 $e = $_e;725 $this->status = TestStatus::error($_e->getMessage());726 $emitter->testErrored(727 $this->valueObjectForEvents(),728 Event\Code\Throwable::from($_e)729 );730 }731 try {732 $this->stopOutputBuffering();733 } catch (RiskyTest $_e) {734 $e = $e ?? $_e;735 }736 if (!isset($e)) {737 $this->performAssertionsOnOutput();738 }739 if ($this->status()->isSuccess()) {740 Event\Facade::emitter()->testPassed(741 $this->valueObjectForEvents()742 );743 }744 $this->mockObjects = [];745 // Tear down the fixture. An exception raised in tearDown() will be746 // caught and passed on when no exception was raised before.747 try {748 if ($hasMetRequirements) {749 $methodsCalledAfterTest = [];750 foreach ($hookMethods['after'] as $method) {751 if ($this->methodDoesNotExistOrIsDeclaredInTestCase($method)) {752 continue;753 }754 $this->{$method}();755 $methodCalledAfterTest = new Event\Code\ClassMethod(756 static::class,757 $method758 );759 $emitter->testAfterTestMethodCalled(760 static::class,761 $methodCalledAfterTest762 );763 $methodsCalledAfterTest[] = $methodCalledAfterTest;764 }765 if (!empty($methodsCalledAfterTest)) {766 $emitter->testAfterTestMethodFinished(767 static::class,768 ...$methodsCalledAfterTest769 );770 }771 if ($this->inIsolation) {772 $methodsCalledAfterLastTest = [];773 foreach ($hookMethods['afterClass'] as $method) {774 if ($this->methodDoesNotExistOrIsDeclaredInTestCase($method)) {775 continue;776 }777 $this->{$method}();778 $methodCalledAfterLastTest = new Event\Code\ClassMethod(779 static::class,780 $method781 );782 $emitter->testAfterLastTestMethodCalled(783 static::class,784 $methodCalledAfterLastTest785 );786 $methodsCalledAfterLastTest[] = $methodCalledAfterLastTest;787 }788 if (!empty($methodsCalledAfterLastTest)) {789 $emitter->testAfterLastTestMethodFinished(790 static::class,791 ...$methodsCalledAfterLastTest792 );793 }794 }795 }796 } catch (Throwable $_e) {797 $e = $e ?? $_e;798 }799 if (isset($_e)) {800 if ($_e instanceof RiskyTest) {801 $this->status = TestStatus::risky($_e->getMessage());802 } else {803 $this->status = TestStatus::error($_e->getMessage());804 }805 }806 clearstatcache();807 if ($currentWorkingDirectory !== getcwd()) {808 chdir($currentWorkingDirectory);809 }810 $this->restoreGlobalState();811 $this->unregisterCustomComparators();812 $this->cleanupIniSettings();813 $this->cleanupLocaleSettings();814 libxml_clear_errors();815 $this->testValueObjectForEvents = null;816 if (isset($e)) {817 $this->onNotSuccessfulTest($e);818 }819 }820 /**821 * @internal This method is not covered by the backward compatibility promise for PHPUnit822 */823 public function setName(string $name): void824 {825 $this->name = $name;826 if (is_callable($this->sortId(), true)) {827 $this->providedTests = [new ExecutionOrderDependency($this->sortId())];828 }829 }830 /**831 * @psalm-param list<ExecutionOrderDependency> $dependencies832 *833 * @internal This method is not covered by the backward compatibility promise for PHPUnit834 */835 public function setDependencies(array $dependencies): void836 {837 $this->dependencies = $dependencies;838 }839 /**840 * @internal This method is not covered by the backward compatibility promise for PHPUnit841 */842 public function setDependencyInput(array $dependencyInput): void843 {844 $this->dependencyInput = $dependencyInput;845 }846 /**847 * @internal This method is not covered by the backward compatibility promise for PHPUnit848 */849 public function dependencyInput(): array850 {851 return $this->dependencyInput;852 }853 /**854 * @internal This method is not covered by the backward compatibility promise for PHPUnit855 */856 public function setBeStrictAboutChangesToGlobalState(bool $beStrictAboutChangesToGlobalState): void857 {858 $this->beStrictAboutChangesToGlobalState = $beStrictAboutChangesToGlobalState;859 }860 /**861 * @internal This method is not covered by the backward compatibility promise for PHPUnit862 */863 public function setBackupGlobals(bool $backupGlobals): void864 {865 if ($this->backupGlobals === null) {866 $this->backupGlobals = $backupGlobals;867 }868 }869 /**870 * @internal This method is not covered by the backward compatibility promise for PHPUnit871 */872 public function setBackupGlobalsExcludeList(array $backupGlobalsExcludeList): void873 {874 $this->backupGlobalsExcludeList = $backupGlobalsExcludeList;875 }876 /**877 * @internal This method is not covered by the backward compatibility promise for PHPUnit878 */879 public function setBackupStaticProperties(bool $backupStaticProperties): void880 {881 if ($this->backupStaticProperties === null) {882 $this->backupStaticProperties = $backupStaticProperties;883 }884 }885 /**886 * @internal This method is not covered by the backward compatibility promise for PHPUnit887 */888 public function setBackupStaticPropertiesExcludeList(array $backupStaticPropertiesExcludeList): void889 {890 $this->backupStaticPropertiesExcludeList = $backupStaticPropertiesExcludeList;891 }892 /**893 * @internal This method is not covered by the backward compatibility promise for PHPUnit894 */895 public function setRunTestInSeparateProcess(bool $runTestInSeparateProcess): void896 {897 if ($this->runTestInSeparateProcess === null) {898 $this->runTestInSeparateProcess = $runTestInSeparateProcess;899 }900 }901 /**902 * @internal This method is not covered by the backward compatibility promise for PHPUnit903 */904 public function setRunClassInSeparateProcess(bool $runClassInSeparateProcess): void905 {906 if ($this->runClassInSeparateProcess === null) {907 $this->runClassInSeparateProcess = $runClassInSeparateProcess;908 }909 }910 /**911 * @internal This method is not covered by the backward compatibility promise for PHPUnit912 */913 public function setPreserveGlobalState(bool $preserveGlobalState): void914 {915 $this->preserveGlobalState = $preserveGlobalState;916 }917 /**918 * @internal This method is not covered by the backward compatibility promise for PHPUnit919 */920 public function setInIsolation(bool $inIsolation): void921 {922 $this->inIsolation = $inIsolation;923 }924 /**925 * @internal This method is not covered by the backward compatibility promise for PHPUnit926 */927 public function isInIsolation(): bool928 {929 return $this->inIsolation;930 }931 /**932 * @internal This method is not covered by the backward compatibility promise for PHPUnit933 */934 public function result(): mixed935 {936 return $this->testResult;937 }938 /**939 * @internal This method is not covered by the backward compatibility promise for PHPUnit940 */941 public function setResult(mixed $result): void942 {943 $this->testResult = $result;944 }945 /**946 * @internal This method is not covered by the backward compatibility promise for PHPUnit947 */948 public function registerMockObject(MockObject $mockObject): void949 {950 $this->mockObjects[] = $mockObject;951 }952 /**953 * @internal This method is not covered by the backward compatibility promise for PHPUnit954 */955 public function addToAssertionCount(int $count): void956 {957 $this->numberOfAssertionsPerformed += $count;958 }959 /**960 * @internal This method is not covered by the backward compatibility promise for PHPUnit961 */962 public function numberOfAssertionsPerformed(): int963 {964 return $this->numberOfAssertionsPerformed;965 }966 /**967 * @internal This method is not covered by the backward compatibility promise for PHPUnit968 */969 public function usesDataProvider(): bool970 {971 return !empty($this->data);972 }973 /**974 * @internal This method is not covered by the backward compatibility promise for PHPUnit975 */976 public function dataName(): int|string977 {978 return $this->dataName;979 }980 /**981 * @internal This method is not covered by the backward compatibility promise for PHPUnit982 */983 public function getDataSetAsString(): string984 {985 $buffer = '';986 if (!empty($this->data)) {987 if (is_int($this->dataName)) {988 $buffer .= sprintf(' with data set #%d', $this->dataName);989 } else {990 $buffer .= sprintf(' with data set "%s"', $this->dataName);991 }992 }993 return $buffer;994 }995 /**996 * @internal This method is not covered by the backward compatibility promise for PHPUnit997 */998 public function getDataSetAsStringWithData(): string999 {1000 if (empty($this->data)) {1001 return '';1002 }1003 return $this->getDataSetAsString() . sprintf(1004 ' (%s)',1005 (new Exporter)->shortenedRecursiveExport($this->data)1006 );1007 }1008 /**1009 * Gets the data set of a TestCase.1010 *1011 * @internal This method is not covered by the backward compatibility promise for PHPUnit1012 */1013 public function getProvidedData(): array1014 {1015 return $this->data;1016 }1017 /**1018 * @internal This method is not covered by the backward compatibility promise for PHPUnit1019 */1020 public function addWarning(string $warning): void1021 {1022 $this->warnings[] = $warning;1023 }1024 /**1025 * @internal This method is not covered by the backward compatibility promise for PHPUnit1026 */1027 public function sortId(): string1028 {1029 $id = $this->name;1030 if (!str_contains($id, '::')) {1031 $id = static::class . '::' . $id;1032 }1033 if ($this->usesDataProvider()) {1034 $id .= $this->getDataSetAsString();1035 }1036 return $id;1037 }1038 /**1039 * Returns the normalized test name as class::method.1040 *1041 * @psalm-return list<ExecutionOrderDependency>1042 */1043 public function provides(): array1044 {1045 return $this->providedTests;1046 }1047 /**1048 * Returns a list of normalized dependency names, class::method.1049 *1050 * This list can differ from the raw dependencies as the resolver has1051 * no need for the [!][shallow]clone prefix that is filtered out1052 * during normalization.1053 *1054 * @psalm-return list<ExecutionOrderDependency>1055 */1056 public function requires(): array1057 {1058 return $this->dependencies;1059 }1060 /**1061 * @internal This method is not covered by the backward compatibility promise for PHPUnit1062 */1063 public function setData(int|string $dataName, array $data): void1064 {1065 $this->dataName = $dataName;1066 $this->data = $data;1067 }1068 /**1069 * @internal This method is not covered by the backward compatibility promise for PHPUnit1070 */1071 public function valueObjectForEvents(): Event\Code\TestMethod1072 {1073 if ($this->testValueObjectForEvents !== null) {1074 return $this->testValueObjectForEvents;1075 }1076 $this->testValueObjectForEvents = Event\Code\TestMethod::fromTestCase($this);1077 return $this->testValueObjectForEvents;1078 }1079 /**1080 * @internal This method is not covered by the backward compatibility promise for PHPUnit1081 */1082 public function wasPrepared(): bool1083 {1084 return $this->wasPrepared;1085 }1086 /**1087 * Override to run the test and assert its state.1088 *1089 * @throws \SebastianBergmann\ObjectEnumerator\InvalidArgumentException1090 * @throws AssertionFailedError1091 * @throws Exception1092 * @throws ExpectationFailedException1093 * @throws Throwable1094 */1095 protected function runTest(): mixed1096 {1097 $testArguments = array_merge($this->data, $this->dependencyInput);1098 $this->registerMockObjectsFromTestArguments($testArguments);1099 try {1100 $testResult = $this->{$this->name}(...array_values($testArguments));1101 } catch (Throwable $exception) {1102 if (!$this->checkExceptionExpectations($exception)) {1103 throw $exception;1104 }1105 if ($this->expectedException !== null) {1106 if ($this->expectedException === Error::class) {1107 $this->assertThat(1108 $exception,1109 LogicalOr::fromConstraints(1110 new ExceptionConstraint(Error::class),1111 new ExceptionConstraint(\Error::class)1112 )1113 );1114 } else {1115 $this->assertThat(1116 $exception,1117 new ExceptionConstraint(1118 $this->expectedException1119 )1120 );1121 }1122 }1123 if ($this->expectedExceptionMessage !== null) {1124 $this->assertThat(1125 $exception,1126 new ExceptionMessage(1127 $this->expectedExceptionMessage1128 )1129 );1130 }1131 if ($this->expectedExceptionMessageRegExp !== null) {1132 $this->assertThat(1133 $exception,1134 new ExceptionMessageRegularExpression(1135 $this->expectedExceptionMessageRegExp1136 )1137 );1138 }1139 if ($this->expectedExceptionCode !== null) {1140 $this->assertThat(1141 $exception,1142 new ExceptionCode(1143 $this->expectedExceptionCode1144 )1145 );1146 }1147 return null;1148 }1149 if ($this->expectedException !== null) {1150 $this->assertThat(1151 null,1152 new ExceptionConstraint(1153 $this->expectedException1154 )1155 );1156 } elseif ($this->expectedExceptionMessage !== null) {1157 $this->numberOfAssertionsPerformed++;1158 throw new AssertionFailedError(1159 sprintf(1160 'Failed asserting that exception with message "%s" is thrown',1161 $this->expectedExceptionMessage1162 )1163 );1164 } elseif ($this->expectedExceptionMessageRegExp !== null) {1165 $this->numberOfAssertionsPerformed++;1166 throw new AssertionFailedError(1167 sprintf(1168 'Failed asserting that exception with message matching "%s" is thrown',1169 $this->expectedExceptionMessageRegExp1170 )1171 );1172 } elseif ($this->expectedExceptionCode !== null) {1173 $this->numberOfAssertionsPerformed++;1174 throw new AssertionFailedError(1175 sprintf(1176 'Failed asserting that exception with code "%s" is thrown',1177 $this->expectedExceptionCode1178 )1179 );1180 }1181 return $testResult;1182 }1183 /**1184 * This method is a wrapper for the ini_set() function that automatically1185 * resets the modified php.ini setting to its original value after the1186 * test is run.1187 *1188 * @throws Exception1189 */1190 protected function iniSet(string $varName, string $newValue): void1191 {1192 $currentValue = ini_set($varName, $newValue);1193 if ($currentValue !== false) {1194 $this->iniSettings[$varName] = $currentValue;1195 } else {1196 throw new Exception(1197 sprintf(1198 'INI setting "%s" could not be set to "%s".',1199 $varName,1200 $newValue1201 )1202 );1203 }1204 }1205 /**1206 * This method is a wrapper for the setlocale() function that automatically1207 * resets the locale to its original value after the test is run.1208 *1209 * @throws Exception1210 */1211 protected function setLocale(mixed ...$arguments): void1212 {1213 if (count($arguments) < 2) {1214 throw new Exception;1215 }1216 [$category, $locale] = $arguments;1217 if (!in_array($category, self::LOCALE_CATEGORIES, true)) {1218 throw new Exception;1219 }1220 if (!is_array($locale) && !is_string($locale)) {1221 throw new Exception;1222 }1223 $this->locale[$category] = setlocale($category, 0);1224 $result = setlocale(...$arguments);1225 if ($result === false) {1226 throw new Exception(1227 'The locale functionality is not implemented on your platform, ' .1228 'the specified locale does not exist or the category name is ' .1229 'invalid.'1230 );1231 }1232 }1233 /**1234 * Creates a test stub for the specified interface or class.1235 *1236 * @psalm-template RealInstanceType of object1237 * @psalm-param class-string<RealInstanceType> $originalClassName1238 * @psalm-return Stub&RealInstanceType1239 */1240 protected function createStub(string $originalClassName): Stub1241 {1242 $stub = $this->createMockObject($originalClassName);1243 Event\Facade::emitter()->testTestStubCreated($originalClassName);1244 return $stub;1245 }1246 /**1247 * Creates a mock object for the specified interface or class.1248 *1249 * @psalm-template RealInstanceType of object1250 * @psalm-param class-string<RealInstanceType> $originalClassName1251 * @psalm-return MockObject&RealInstanceType1252 */1253 protected function createMock(string $originalClassName): MockObject1254 {1255 $mock = $this->createMockObject($originalClassName);1256 Event\Facade::emitter()->testMockObjectCreated($originalClassName);1257 return $mock;1258 }1259 /**1260 * Creates (and configures) a mock object for the specified interface or class.1261 *1262 * @psalm-template RealInstanceType of object1263 * @psalm-param class-string<RealInstanceType> $originalClassName1264 * @psalm-return MockObject&RealInstanceType1265 */1266 protected function createConfiguredMock(string $originalClassName, array $configuration): MockObject1267 {1268 $o = $this->createMockObject($originalClassName);1269 foreach ($configuration as $method => $return) {1270 $o->method($method)->willReturn($return);1271 }1272 return $o;1273 }1274 /**1275 * Creates a partial mock object for the specified interface or class.1276 *1277 * @psalm-param list<string> $methods1278 *1279 * @psalm-template RealInstanceType of object1280 * @psalm-param class-string<RealInstanceType> $originalClassName1281 * @psalm-return MockObject&RealInstanceType1282 */1283 protected function createPartialMock(string $originalClassName, array $methods): MockObject1284 {1285 $partialMock = $this->getMockBuilder($originalClassName)1286 ->disableOriginalConstructor()1287 ->disableOriginalClone()1288 ->disableArgumentCloning()1289 ->disallowMockingUnknownTypes()1290 ->onlyMethods($methods)1291 ->getMock();1292 Event\Facade::emitter()->testPartialMockObjectCreated(1293 $originalClassName,1294 ...$methods1295 );1296 return $partialMock;1297 }1298 /**1299 * Creates a test proxy for the specified class.1300 *1301 * @psalm-template RealInstanceType of object1302 * @psalm-param class-string<RealInstanceType> $originalClassName1303 * @psalm-return MockObject&RealInstanceType1304 */1305 protected function createTestProxy(string $originalClassName, array $constructorArguments = []): MockObject1306 {1307 $testProxy = $this->getMockBuilder($originalClassName)1308 ->setConstructorArgs($constructorArguments)1309 ->enableProxyingToOriginalMethods()1310 ->getMock();1311 Event\Facade::emitter()->testTestProxyCreated(1312 $originalClassName,1313 $constructorArguments1314 );1315 return $testProxy;1316 }1317 /**1318 * Creates a mock object for the specified abstract class with all abstract1319 * methods of the class mocked. Concrete methods are not mocked by default.1320 * To mock concrete methods, use the 7th parameter ($mockedMethods).1321 *1322 * @psalm-template RealInstanceType of object1323 * @psalm-param class-string<RealInstanceType> $originalClassName1324 * @psalm-return MockObject&RealInstanceType1325 */1326 protected function getMockForAbstractClass(string $originalClassName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = [], bool $cloneArguments = false): MockObject1327 {1328 $this->recordDoubledType($originalClassName);1329 $mockObject = $this->getMockObjectGenerator()->getMockForAbstractClass(1330 $originalClassName,1331 $arguments,1332 $mockClassName,1333 $callOriginalConstructor,1334 $callOriginalClone,1335 $callAutoload,1336 $mockedMethods,1337 $cloneArguments1338 );1339 $this->registerMockObject($mockObject);1340 Event\Facade::emitter()->testMockObjectCreatedForAbstractClass($originalClassName);1341 return $mockObject;1342 }1343 /**1344 * Creates a mock object based on the given WSDL file.1345 *1346 * @psalm-template RealInstanceType of object1347 * @psalm-param class-string<RealInstanceType>|string $originalClassName1348 * @psalm-return MockObject&RealInstanceType1349 */1350 protected function getMockFromWsdl(string $wsdlFile, string $originalClassName = '', string $mockClassName = '', array $methods = [], bool $callOriginalConstructor = true, array $options = []): MockObject1351 {1352 $this->recordDoubledType(SoapClient::class);1353 if ($originalClassName === '') {1354 $fileName = pathinfo(basename(parse_url($wsdlFile, PHP_URL_PATH)), PATHINFO_FILENAME);1355 $originalClassName = preg_replace('/\W/', '', $fileName);1356 }1357 if (!class_exists($originalClassName)) {1358 eval(1359 $this->getMockObjectGenerator()->generateClassFromWsdl(1360 $wsdlFile,1361 $originalClassName,1362 $methods,1363 $options1364 )1365 );1366 }1367 $mockObject = $this->getMockObjectGenerator()->getMock(1368 $originalClassName,1369 $methods,1370 ['', $options],1371 $mockClassName,1372 $callOriginalConstructor,1373 false,1374 false1375 );1376 Event\Facade::emitter()->testMockObjectCreatedFromWsdl(1377 $wsdlFile,1378 $originalClassName,1379 $mockClassName,1380 $methods,1381 $callOriginalConstructor,1382 $options1383 );1384 $this->registerMockObject($mockObject);1385 return $mockObject;1386 }1387 /**1388 * Creates a mock object for the specified trait with all abstract methods1389 * of the trait mocked. Concrete methods to mock can be specified with the1390 * `$mockedMethods` parameter.1391 *1392 * @psalm-param trait-string $traitName1393 */1394 protected function getMockForTrait(string $traitName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = [], bool $cloneArguments = false): MockObject1395 {1396 $this->recordDoubledType($traitName);1397 $mockObject = $this->getMockObjectGenerator()->getMockForTrait(1398 $traitName,1399 $arguments,1400 $mockClassName,1401 $callOriginalConstructor,1402 $callOriginalClone,1403 $callAutoload,1404 $mockedMethods,1405 $cloneArguments1406 );1407 $this->registerMockObject($mockObject);1408 Event\Facade::emitter()->testMockObjectCreatedForTrait($traitName);1409 return $mockObject;1410 }1411 /**1412 * Creates an object that uses the specified trait.1413 *1414 * @psalm-param trait-string $traitName1415 */1416 protected function getObjectForTrait(string $traitName, array $arguments = [], string $traitClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true): object1417 {1418 $this->recordDoubledType($traitName);1419 return $this->getMockObjectGenerator()->getObjectForTrait(1420 $traitName,1421 $traitClassName,1422 $callAutoload,1423 $callOriginalConstructor,1424 $arguments1425 );1426 }1427 /**1428 * Performs assertions shared by all tests of a test case.1429 *1430 * This method is called between setUp() and test.1431 */1432 protected function assertPreConditions(): void1433 {1434 }1435 /**1436 * Performs assertions shared by all tests of a test case.1437 *1438 * This method is called between test and tearDown().1439 */1440 protected function assertPostConditions(): void1441 {1442 }1443 /**1444 * This method is called when a test method did not execute successfully.1445 *1446 * @throws Throwable1447 */1448 protected function onNotSuccessfulTest(Throwable $t): void1449 {1450 throw $t;1451 }1452 protected function recordDoubledType(string $originalClassName): void1453 {1454 $this->doubledTypes[] = $originalClassName;1455 }1456 /**1457 * @throws Throwable1458 */1459 private function verifyMockObjects(): void1460 {1461 foreach ($this->mockObjects as $mockObject) {1462 if ($mockObject->__phpunit_hasMatchers()) {1463 $this->numberOfAssertionsPerformed++;1464 }1465 $mockObject->__phpunit_verify(1466 $this->shouldInvocationMockerBeReset($mockObject)1467 );1468 }1469 }1470 /**1471 * @throws SkippedTest1472 * @throws Warning1473 */1474 private function checkRequirements(): void1475 {1476 if (!$this->name || !method_exists($this, $this->name)) {1477 return;1478 }1479 $missingRequirements = (new Requirements)->requirementsNotSatisfiedFor(1480 static::class,1481 $this->name1482 );1483 if (!empty($missingRequirements)) {1484 $this->markTestSkipped(implode(PHP_EOL, $missingRequirements));1485 }1486 }1487 private function handleDependencies(): bool1488 {1489 if ([] === $this->dependencies || $this->inIsolation) {1490 return true;1491 }1492 $passed = $this->result->passed();1493 $passedKeys = array_keys($passed);1494 $numKeys = count($passedKeys);1495 for ($i = 0; $i < $numKeys; $i++) {1496 $pos = strpos($passedKeys[$i], ' with data set');1497 if ($pos !== false) {1498 $passedKeys[$i] = substr($passedKeys[$i], 0, $pos);1499 }1500 }1501 $passedKeys = array_flip(array_unique($passedKeys));1502 foreach ($this->dependencies as $dependency) {1503 if (!$dependency->isValid()) {1504 $this->markErrorForInvalidDependency();1505 return false;1506 }1507 if ($dependency->targetIsClass()) {1508 $dependencyClassName = $dependency->getTargetClassName();1509 if (array_search($dependencyClassName, $this->result->passedClasses(), true) === false) {1510 $this->markSkippedForMissingDependency($dependency);1511 return false;1512 }1513 continue;1514 }1515 $dependencyTarget = $dependency->getTarget();1516 if (!isset($passedKeys[$dependencyTarget])) {1517 if (!$this->isCallableTestMethod($dependencyTarget)) {1518 $this->markErrorForInvalidDependency($dependency);1519 } else {1520 $this->markSkippedForMissingDependency($dependency);1521 }1522 return false;1523 }1524 if (isset($passed[$dependencyTarget])) {1525 if ($passed[$dependencyTarget]['size']->isKnown() &&1526 $this->size()->isKnown() &&1527 $passed[$dependencyTarget]['size']->isGreaterThan($this->size())) {1528 $this->result->addFailure(1529 $this,1530 new SkippedDueToDependencyOnLargerTestException,1531 01532 );1533 return false;1534 }1535 if ($dependency->deepClone()) {1536 $deepCopy = new DeepCopy;1537 $deepCopy->skipUncloneable(false);1538 $this->dependencyInput[$dependencyTarget] = $deepCopy->copy($passed[$dependencyTarget]['result']);1539 } elseif ($dependency->shallowClone()) {1540 $this->dependencyInput[$dependencyTarget] = clone $passed[$dependencyTarget]['result'];1541 } else {1542 $this->dependencyInput[$dependencyTarget] = $passed[$dependencyTarget]['result'];1543 }1544 } else {1545 $this->dependencyInput[$dependencyTarget] = null;1546 }1547 }1548 return true;1549 }1550 private function markErrorForInvalidDependency(?ExecutionOrderDependency $dependency = null): void1551 {1552 $message = 'This test has an invalid dependency';1553 if ($dependency !== null) {1554 $message = sprintf(1555 'This test depends on "%s" which does not exist',1556 $dependency->getTarget()1557 );1558 }1559 $exception = new InvalidDependencyException($message);1560 Event\Facade::emitter()->testErrored(1561 $this->valueObjectForEvents(),1562 Event\Code\Throwable::from($exception)1563 );1564 $this->status = TestStatus::error($message);1565 $this->result->startTest($this);1566 $this->result->addError(1567 $this,1568 $exception,1569 01570 );1571 $this->result->endTest($this, 0);1572 }1573 private function markSkippedForMissingDependency(ExecutionOrderDependency $dependency): void1574 {1575 $message = sprintf(1576 'This test depends on "%s" to pass',1577 $dependency->getTarget()1578 );1579 Event\Facade::emitter()->testSkipped(1580 $this->valueObjectForEvents(),1581 $message1582 );1583 $this->status = TestStatus::skipped($message);1584 $this->result->startTest($this);1585 $this->result->addFailure(1586 $this,1587 new SkippedDueToMissingDependencyException(1588 $dependency->getTarget()1589 ),1590 01591 );1592 $this->result->endTest($this, 0);1593 }1594 /**1595 * Get the mock object generator, creating it if it doesn't exist.1596 */1597 private function getMockObjectGenerator(): MockGenerator1598 {1599 if ($this->mockObjectGenerator === null) {1600 $this->mockObjectGenerator = new MockGenerator;1601 }1602 return $this->mockObjectGenerator;1603 }1604 private function startOutputBuffering(): void1605 {1606 ob_start();1607 $this->outputBufferingActive = true;1608 $this->outputBufferingLevel = ob_get_level();1609 }1610 /**1611 * @throws RiskyTest1612 */1613 private function stopOutputBuffering(): void1614 {1615 if (ob_get_level() !== $this->outputBufferingLevel) {1616 while (ob_get_level() >= $this->outputBufferingLevel) {1617 ob_end_clean();1618 }1619 throw new RiskyDueToOutputBufferingException;1620 }1621 $this->output = ob_get_clean();1622 $this->outputBufferingActive = false;1623 $this->outputBufferingLevel = ob_get_level();1624 }1625 private function snapshotGlobalState(): void1626 {1627 if ($this->runTestInSeparateProcess || $this->inIsolation ||1628 (!$this->backupGlobals && !$this->backupStaticProperties)) {1629 return;1630 }1631 $snapshot = $this->createGlobalStateSnapshot($this->backupGlobals === true);1632 Event\Facade::emitter()->globalStateCaptured($snapshot);1633 $this->snapshot = $snapshot;1634 }1635 /**1636 * @throws RiskyTest1637 */1638 private function restoreGlobalState(): void1639 {1640 if (!$this->snapshot instanceof Snapshot) {1641 return;1642 }1643 if ($this->beStrictAboutChangesToGlobalState) {1644 $snapshotAfter = $this->createGlobalStateSnapshot($this->backupGlobals === true);1645 try {1646 $this->compareGlobalStateSnapshots(1647 $this->snapshot,1648 $snapshotAfter1649 );1650 } catch (RiskyTest $rte) {1651 Event\Facade::emitter()->globalStateModified(1652 $this->snapshot,1653 $snapshotAfter,1654 $rte->getMessage()1655 );1656 }1657 }1658 $restorer = new Restorer;1659 if ($this->backupGlobals) {1660 $restorer->restoreGlobalVariables($this->snapshot);1661 Event\Facade::emitter()->globalStateRestored($this->snapshot);1662 }1663 if ($this->backupStaticProperties) {1664 $restorer->restoreStaticAttributes($this->snapshot);1665 }1666 $this->snapshot = null;1667 if (isset($rte)) {1668 throw $rte;1669 }1670 }1671 private function createGlobalStateSnapshot(bool $backupGlobals): Snapshot1672 {1673 $excludeList = new GlobalStateExcludeList;1674 foreach ($this->backupGlobalsExcludeList as $globalVariable) {1675 $excludeList->addGlobalVariable($globalVariable);1676 }1677 if (!defined('PHPUNIT_TESTSUITE')) {1678 $excludeList->addClassNamePrefix('PHPUnit');1679 $excludeList->addClassNamePrefix('SebastianBergmann\CodeCoverage');1680 $excludeList->addClassNamePrefix('SebastianBergmann\FileIterator');1681 $excludeList->addClassNamePrefix('SebastianBergmann\Invoker');1682 $excludeList->addClassNamePrefix('SebastianBergmann\Template');1683 $excludeList->addClassNamePrefix('SebastianBergmann\Timer');1684 $excludeList->addClassNamePrefix('Doctrine\Instantiator');1685 $excludeList->addStaticAttribute(ComparatorFactory::class, 'instance');1686 foreach ($this->backupStaticPropertiesExcludeList as $class => $attributes) {1687 foreach ($attributes as $attribute) {1688 $excludeList->addStaticAttribute($class, $attribute);1689 }1690 }1691 }1692 return new Snapshot(1693 $excludeList,1694 $backupGlobals,1695 (bool) $this->backupStaticProperties,1696 false,1697 false,1698 false,1699 false,1700 false,1701 false,1702 false1703 );1704 }1705 /**1706 * @throws RiskyTest1707 */1708 private function compareGlobalStateSnapshots(Snapshot $before, Snapshot $after): void1709 {1710 $backupGlobals = $this->backupGlobals === null || $this->backupGlobals;1711 if ($backupGlobals) {1712 $this->compareGlobalStateSnapshotPart(1713 $before->globalVariables(),1714 $after->globalVariables(),1715 "--- Global variables before the test\n+++ Global variables after the test\n"1716 );1717 $this->compareGlobalStateSnapshotPart(1718 $before->superGlobalVariables(),1719 $after->superGlobalVariables(),1720 "--- Super-global variables before the test\n+++ Super-global variables after the test\n"1721 );1722 }1723 if ($this->backupStaticProperties) {1724 $this->compareGlobalStateSnapshotPart(1725 $before->staticAttributes(),1726 $after->staticAttributes(),1727 "--- Static attributes before the test\n+++ Static attributes after the test\n"1728 );1729 }1730 }1731 /**1732 * @throws RiskyTest1733 */1734 private function compareGlobalStateSnapshotPart(array $before, array $after, string $header): void1735 {1736 if ($before != $after) {1737 $differ = new Differ($header);1738 $exporter = new Exporter;1739 $diff = $differ->diff(1740 $exporter->export($before),1741 $exporter->export($after)1742 );1743 throw new RiskyDueToGlobalStateException($diff);1744 }1745 }1746 /**1747 * @throws \SebastianBergmann\ObjectEnumerator\InvalidArgumentException1748 */1749 private function shouldInvocationMockerBeReset(MockObject $mock): bool1750 {1751 $enumerator = new Enumerator;1752 foreach ($enumerator->enumerate($this->dependencyInput) as $object) {1753 if ($mock === $object) {1754 return false;1755 }1756 }1757 if (!is_array($this->testResult) && !is_object($this->testResult)) {1758 return true;1759 }1760 return !in_array($mock, $enumerator->enumerate($this->testResult), true);1761 }1762 /**1763 * @throws \SebastianBergmann\ObjectEnumerator\InvalidArgumentException1764 * @throws \SebastianBergmann\ObjectReflector\InvalidArgumentException1765 */1766 private function registerMockObjectsFromTestArguments(array $testArguments, array &$visited = []): void1767 {1768 if ($this->registerMockObjectsFromTestArgumentsRecursively) {1769 foreach ((new Enumerator)->enumerate($testArguments) as $object) {1770 if ($object instanceof MockObject) {1771 $this->registerMockObject($object);1772 }1773 }1774 } else {1775 foreach ($testArguments as $testArgument) {1776 if ($testArgument instanceof MockObject) {1777 if (Type::isCloneable($testArgument)) {1778 $testArgument = clone $testArgument;1779 }1780 $this->registerMockObject($testArgument);1781 } elseif (is_array($testArgument) && !in_array($testArgument, $visited, true)) {1782 $visited[] = $testArgument;1783 $this->registerMockObjectsFromTestArguments(1784 $testArgument,1785 $visited1786 );1787 }1788 }1789 }1790 }1791 private function unregisterCustomComparators(): void1792 {1793 $factory = ComparatorFactory::getInstance();1794 foreach ($this->customComparators as $comparator) {1795 $factory->unregister($comparator);1796 }1797 $this->customComparators = [];1798 }1799 private function cleanupIniSettings(): void1800 {1801 foreach ($this->iniSettings as $varName => $oldValue) {1802 ini_set($varName, $oldValue);1803 }1804 $this->iniSettings = [];1805 }1806 private function cleanupLocaleSettings(): void1807 {1808 foreach ($this->locale as $category => $locale) {1809 setlocale($category, $locale);1810 }1811 $this->locale = [];1812 }1813 /**1814 * @throws Exception1815 */1816 private function checkExceptionExpectations(Throwable $throwable): bool1817 {1818 $result = false;1819 if ($this->expectedException !== null || $this->expectedExceptionCode !== null || $this->expectedExceptionMessage !== null || $this->expectedExceptionMessageRegExp !== null) {1820 $result = true;1821 }1822 if ($throwable instanceof Exception) {1823 $result = false;1824 }1825 if (is_string($this->expectedException)) {1826 try {1827 $reflector = new ReflectionClass($this->expectedException);1828 // @codeCoverageIgnoreStart1829 } catch (ReflectionException $e) {1830 throw new Exception(1831 $e->getMessage(),1832 (int) $e->getCode(),1833 $e1834 );1835 }1836 // @codeCoverageIgnoreEnd1837 if ($this->expectedException === 'PHPUnit\Framework\Exception' ||1838 $this->expectedException === '\PHPUnit\Framework\Exception' ||1839 $reflector->isSubclassOf(Exception::class)) {1840 $result = true;1841 }1842 }1843 return $result;1844 }1845 private function shouldRunInSeparateProcess(): bool1846 {1847 return ($this->runTestInSeparateProcess || $this->runClassInSeparateProcess) &&1848 !$this->inIsolation && !$this instanceof PhptTestCase;1849 }1850 private function isCallableTestMethod(string $dependency): bool1851 {1852 [$className, $methodName] = explode('::', $dependency);1853 if (!class_exists($className)) {1854 return false;1855 }1856 try {1857 $class = new ReflectionClass($className);1858 } catch (ReflectionException $e) {1859 return false;1860 }1861 if (!$class->isSubclassOf(__CLASS__)) {1862 return false;1863 }1864 if (!$class->hasMethod($methodName)) {1865 return false;1866 }1867 return TestUtil::isTestMethod(1868 $class->getMethod($methodName)1869 );1870 }1871 /**1872 * @psalm-template RealInstanceType of object1873 * @psalm-param class-string<RealInstanceType> $originalClassName1874 * @psalm-return MockObject&RealInstanceType1875 */1876 private function createMockObject(string $originalClassName): MockObject1877 {1878 return $this->getMockBuilder($originalClassName)1879 ->disableOriginalConstructor()1880 ->disableOriginalClone()1881 ->disableArgumentCloning()1882 ->disallowMockingUnknownTypes()1883 ->getMock();1884 }1885 private function methodDoesNotExistOrIsDeclaredInTestCase(string $methodName): bool1886 {1887 $reflector = new ReflectionObject($this);1888 return !$reflector->hasMethod($methodName) ||1889 $reflector->getMethod($methodName)->getDeclaringClass()->getName() === self::class;1890 }1891 /**1892 * @throws ExpectationFailedException1893 */1894 private function performAssertionsOnOutput(): void1895 {1896 if ($this->outputExpectedRegex !== null) {1897 $this->assertMatchesRegularExpression($this->outputExpectedRegex, $this->output);1898 } elseif ($this->outputExpectedString !== null) {1899 $this->assertEquals($this->outputExpectedString, $this->output);...

Full Screen

Full Screen

TestSuite.php

Source:TestSuite.php Github

copy

Full Screen

...342 $methodsCalledBeforeFirstTest = [];343 if (class_exists($this->name, false)) {344 try {345 foreach ($hookMethods['beforeClass'] as $beforeClassMethod) {346 if ($this->methodDoesNotExistOrIsDeclaredInTestCase($beforeClassMethod)) {347 continue;348 }349 if ($missingRequirements = (new Requirements)->requirementsNotSatisfiedFor($this->name, $beforeClassMethod)) {350 $this->markTestSuiteSkipped(implode(PHP_EOL, $missingRequirements));351 }352 call_user_func([$this->name, $beforeClassMethod]);353 $methodCalledBeforeFirstTest = new Event\Code\ClassMethod(354 $this->name,355 $beforeClassMethod356 );357 Event\Facade::emitter()->testBeforeFirstTestMethodCalled(358 $this->name,359 $methodCalledBeforeFirstTest360 );361 $methodsCalledBeforeFirstTest[] = $methodCalledBeforeFirstTest;362 }363 } catch (SkippedTestSuiteError $error) {364 foreach ($this->tests() as $test) {365 $result->startTest($test);366 $result->addFailure($test, $error, 0);367 $result->endTest($test, 0);368 }369 $result->endTestSuite($this);370 return;371 } catch (Throwable $t) {372 $errorAdded = false;373 foreach ($this->tests() as $test) {374 if ($result->shouldStop()) {375 break;376 }377 $result->startTest($test);378 if (!$errorAdded) {379 $result->addError($test, $t, 0);380 $errorAdded = true;381 } else {382 $result->addFailure(383 $test,384 new SkippedDueToErrorInHookMethodException,385 0386 );387 }388 $result->endTest($test, 0);389 }390 $result->endTestSuite($this);391 return;392 }393 }394 if (!empty($methodsCalledBeforeFirstTest)) {395 Event\Facade::emitter()->testBeforeFirstTestMethodFinished(396 $this->name,397 ...$methodsCalledBeforeFirstTest398 );399 }400 foreach ($this as $test) {401 if ($result->shouldStop()) {402 break;403 }404 if ($test instanceof TestCase || $test instanceof self) {405 if ($this->backupGlobals !== null) {406 $test->setBackupGlobals($this->backupGlobals);407 }408 if ($this->backupStaticProperties !== null) {409 $test->setBackupStaticProperties($this->backupStaticProperties);410 }411 if ($this->beStrictAboutChangesToGlobalState !== null) {412 $test->setBeStrictAboutChangesToGlobalState($this->beStrictAboutChangesToGlobalState);413 }414 $test->setRunTestInSeparateProcess($this->runTestInSeparateProcess);415 }416 $test->run($result);417 }418 $methodsCalledAfterLastTest = [];419 if (class_exists($this->name, false)) {420 foreach ($hookMethods['afterClass'] as $afterClassMethod) {421 if ($this->methodDoesNotExistOrIsDeclaredInTestCase($afterClassMethod)) {422 continue;423 }424 try {425 call_user_func([$this->name, $afterClassMethod]);426 $methodCalledAfterLastTest = new Event\Code\ClassMethod(427 $this->name,428 $afterClassMethod429 );430 Event\Facade::emitter()->testAfterLastTestMethodCalled(431 $this->name,432 $methodCalledAfterLastTest433 );434 $methodsCalledAfterLastTest[] = $methodCalledAfterLastTest;435 } catch (Throwable $t) {436 $message = "Exception in {$this->name}::{$afterClassMethod}" . PHP_EOL . $t->getMessage();437 $error = new SyntheticError($message, 0, $t->getFile(), $t->getLine(), $t->getTrace());438 $placeholderTest = clone $test;439 $placeholderTest->setName($afterClassMethod);440 $result->startTest($placeholderTest);441 $result->addFailure($placeholderTest, $error, 0);442 $result->endTest($placeholderTest, 0);443 }444 }445 }446 if (!empty($methodsCalledAfterLastTest)) {447 Event\Facade::emitter()->testAfterLastTestMethodFinished(448 $this->name,449 ...$methodsCalledAfterLastTest450 );451 }452 $result->endTestSuite($this);453 Event\Facade::emitter()->testSuiteFinished(454 $testSuiteValueObjectForEvents,455 (new TestResultMapper)->map($result)456 );457 }458 public function setRunTestInSeparateProcess(bool $runTestInSeparateProcess): void459 {460 $this->runTestInSeparateProcess = $runTestInSeparateProcess;461 }462 public function setName(string $name): void463 {464 $this->name = $name;465 }466 /**467 * Returns the tests as an enumeration.468 *469 * @psalm-return list<Test>470 */471 public function tests(): array472 {473 return $this->tests;474 }475 /**476 * Set tests of the test suite.477 *478 * @psalm-param list<Test> $tests479 */480 public function setTests(array $tests): void481 {482 $this->tests = $tests;483 }484 /**485 * Mark the test suite as skipped.486 *487 * @throws SkippedTestSuiteError488 *489 * @psalm-return never-return490 */491 public function markTestSuiteSkipped(string $message = ''): void492 {493 throw new SkippedTestSuiteError($message);494 }495 public function setBeStrictAboutChangesToGlobalState(bool $beStrictAboutChangesToGlobalState): void496 {497 if (null === $this->beStrictAboutChangesToGlobalState) {498 $this->beStrictAboutChangesToGlobalState = $beStrictAboutChangesToGlobalState;499 }500 }501 public function setBackupGlobals(bool $backupGlobals): void502 {503 if (null === $this->backupGlobals) {504 $this->backupGlobals = $backupGlobals;505 }506 }507 public function setBackupStaticProperties(bool $backupStaticProperties): void508 {509 if (null === $this->backupStaticProperties) {510 $this->backupStaticProperties = $backupStaticProperties;511 }512 }513 /**514 * Returns an iterator for this test suite.515 */516 public function getIterator(): Iterator517 {518 $iterator = new TestSuiteIterator($this);519 if ($this->iteratorFilter !== null) {520 $iterator = $this->iteratorFilter->factory($iterator, $this);521 }522 return $iterator;523 }524 public function injectFilter(Factory $filter): void525 {526 $this->iteratorFilter = $filter;527 foreach ($this as $test) {528 if ($test instanceof self) {529 $test->injectFilter($filter);530 }531 }532 }533 /**534 * @psalm-return array<int,string>535 */536 public function warnings(): array537 {538 return array_unique($this->warnings);539 }540 /**541 * @psalm-return list<ExecutionOrderDependency>542 */543 public function provides(): array544 {545 if ($this->providedTests === null) {546 $this->providedTests = [];547 if (is_callable($this->sortId(), true)) {548 $this->providedTests[] = new ExecutionOrderDependency($this->sortId());549 }550 foreach ($this->tests as $test) {551 if (!($test instanceof Reorderable)) {552 // @codeCoverageIgnoreStart553 continue;554 // @codeCoverageIgnoreEnd555 }556 $this->providedTests = ExecutionOrderDependency::mergeUnique($this->providedTests, $test->provides());557 }558 }559 return $this->providedTests;560 }561 /**562 * @psalm-return list<ExecutionOrderDependency>563 */564 public function requires(): array565 {566 if ($this->requiredTests === null) {567 $this->requiredTests = [];568 foreach ($this->tests as $test) {569 if (!($test instanceof Reorderable)) {570 // @codeCoverageIgnoreStart571 continue;572 // @codeCoverageIgnoreEnd573 }574 $this->requiredTests = ExecutionOrderDependency::mergeUnique(575 ExecutionOrderDependency::filterInvalid($this->requiredTests),576 $test->requires()577 );578 }579 $this->requiredTests = ExecutionOrderDependency::diff($this->requiredTests, $this->provides());580 }581 return $this->requiredTests;582 }583 public function sortId(): string584 {585 return $this->getName() . '::class';586 }587 /**588 * @throws Exception589 */590 protected function addTestMethod(ReflectionClass $class, ReflectionMethod $method): void591 {592 $methodName = $method->getName();593 $test = (new TestBuilder)->build($class, $methodName);594 if ($test instanceof TestCase || $test instanceof DataProviderTestSuite) {595 $test->setDependencies(596 Dependencies::dependencies($class->getName(), $methodName)597 );598 }599 $this->addTest(600 $test,601 (new Groups)->groups($class->getName(), $methodName)602 );603 }604 private function clearCaches(): void605 {606 $this->numTests = -1;607 $this->providedTests = null;608 $this->requiredTests = null;609 }610 private function containsOnlyVirtualGroups(array $groups): bool611 {612 foreach ($groups as $group) {613 if (!str_starts_with($group, '__phpunit_')) {614 return false;615 }616 }617 return true;618 }619 private function methodDoesNotExistOrIsDeclaredInTestCase(string $methodName): bool620 {621 $reflector = new ReflectionClass($this->name);622 return !$reflector->hasMethod($methodName) ||623 $reflector->getMethod($methodName)->getDeclaringClass()->getName() === TestCase::class;624 }625}...

Full Screen

Full Screen

methodDoesNotExistOrIsDeclaredInTestCase

Using AI Code Generation

copy

Full Screen

1$obj = new TestSuite();2$obj->methodDoesNotExistOrIsDeclaredInTestCase();3$obj = new TestSuite();4$obj->methodDoesNotExistOrIsDeclaredInTestCase();5$obj = new TestSuite();6$obj->methodDoesNotExistOrIsDeclaredInTestCase();7$obj = new TestSuite();8$obj->methodDoesNotExistOrIsDeclaredInTestCase();9$obj = new TestSuite();10$obj->methodDoesNotExistOrIsDeclaredInTestCase();11$obj = new TestSuite();12$obj->methodDoesNotExistOrIsDeclaredInTestCase();13$obj = new TestSuite();14$obj->methodDoesNotExistOrIsDeclaredInTestCase();15$obj = new TestSuite();16$obj->methodDoesNotExistOrIsDeclaredInTestCase();17$obj = new TestSuite();18$obj->methodDoesNotExistOrIsDeclaredInTestCase();19$obj = new TestSuite();20$obj->methodDoesNotExistOrIsDeclaredInTestCase();21$obj = new TestSuite();22$obj->methodDoesNotExistOrIsDeclaredInTestCase();23$obj = new TestSuite();24$obj->methodDoesNotExistOrIsDeclaredInTestCase();

Full Screen

Full Screen

methodDoesNotExistOrIsDeclaredInTestCase

Using AI Code Generation

copy

Full Screen

1$testSuite = new TestSuite();2$testSuite->methodDoesNotExistOrIsDeclaredInTestCase('testMethod');3$testSuite = new TestSuite();4$testSuite->methodDoesNotExistOrIsDeclaredInTestCase('testMethod');5$testSuite = new TestSuite();6$testSuite->methodDoesNotExistOrIsDeclaredInTestCase('testMethod');7$testSuite = new TestSuite();8$testSuite->methodDoesNotExistOrIsDeclaredInTestCase('testMethod');9$testSuite = new TestSuite();10$testSuite->methodDoesNotExistOrIsDeclaredInTestCase('testMethod');11$testSuite = new TestSuite();12$testSuite->methodDoesNotExistOrIsDeclaredInTestCase('testMethod');13$testSuite = new TestSuite();14$testSuite->methodDoesNotExistOrIsDeclaredInTestCase('testMethod');15$testSuite = new TestSuite();16$testSuite->methodDoesNotExistOrIsDeclaredInTestCase('testMethod');17$testSuite = new TestSuite();18$testSuite->methodDoesNotExistOrIsDeclaredInTestCase('testMethod');19$testSuite = new TestSuite();20$testSuite->methodDoesNotExistOrIsDeclaredInTestCase('testMethod');21$testSuite = new TestSuite();

Full Screen

Full Screen

methodDoesNotExistOrIsDeclaredInTestCase

Using AI Code Generation

copy

Full Screen

1require_once 'PHPUnit/Framework/TestSuite.php';2require_once 'PHPUnit/TextUI/TestRunner.php';3require_once 'PHPUnit/Util/Filter.php';4require_once 'PHPUnit/Util/Printer.php';5require_once 'PHPUnit/Util/Test.php';6require_once 'PHPUnit/Util/Log/JSON.php';7require_once 'PHPUnit/Util/Log/JUnit.php';8require_once 'PHPUnit/Util/Log/TAP.php';9require_once 'PHPUnit/Util/Log/TeamCity.php';10require_once 'PHPUnit/Util/Log/TestDox/Text.php';11require_once 'PHPUnit/Util/Log/TestDox/HTML.php';12require_once 'PHPUnit/Util/Log/TestDox/CSV.php';13require_once 'PHPUnit/Util/Log/TestDox/JSON.php';14require_once 'PHPUnit/Util/Log/TestDox/Xml.php';15require_once 'PHPUnit/Util/Log/TestDox/Markdown.php';16require_once 'PHPUnit/Util/Log/TestDox/TextUIResultPrinter.php';17require_once 'PHPUnit/Util/Log/TestDox/TextResultPrinter.php';18require_once 'PHPUnit/Util/Log/TestDox/HtmlResultPrinter.php';19require_once 'PHPUnit/Util/Log/JSON.php';20require_once 'PHPUnit/Util/Log/JUnit.php';21require_once 'PHPUnit/Util/Log/TAP.php';22require_once 'PHPUnit/Util/Log/TeamCity.php';23require_once 'PHPUnit/Util/Log/TestDox/Text.php';24require_once 'PHPUnit/Util/Log/TestDox/HTML.php';25require_once 'PHPUnit/Util/Log/TestDox/CSV.php';26require_once 'PHPUnit/Util/Log/TestDox/JSON.php';27require_once 'PHPUnit/Util/Log/TestDox/Xml.php';28require_once 'PHPUnit/Util/Log/TestDox/Markdown.php';29require_once 'PHPUnit/Util/Log/TestDox/TextUIResultPrinter.php';30require_once 'PHPUnit/Util/Log/TestDox/TextResultPrinter.php';31require_once 'PHPUnit/Util/Log/TestDox/HtmlResultPrinter.php';32require_once 'PHPUnit/Util/Log/JSON.php';33require_once 'PHPUnit/Util/Log/JUnit.php';34require_once 'PHPUnit/Util/Log/TAP.php';35require_once 'PHPUnit/Util/Log/TeamCity.php';36require_once 'PHPUnit/Util/Log/TestDox/Text.php';

Full Screen

Full Screen

methodDoesNotExistOrIsDeclaredInTestCase

Using AI Code Generation

copy

Full Screen

1require_once 'PHPUnit/Framework/TestSuite.php';2require_once 'PHPUnit/TextUI/TestRunner.php';3require_once 'PHPUnit/Util/Filter.php';4require_once 'PHPUnit/Util/Printer.php';5require_once 'PHPUnit/Util/Test.php';6require_once 'PHPUnit/Util/Log/JSON.php';7require_once 'PHPUnit/Util/Log/JUnit.php';8require_once 'PHPUnit/Util/Log/TAP.php';9require_once 'PHPUnit/Util/Log/TeamCity.php';10require_once 'PHPUnit/Util/Log/TestDox/Text.php';11require_once 'PHPUnit/Util/Log/TestDox/HTML.php';12require_once 'PHPUnit/Util/Log/TestDox/CSV.php';13require_once 'PHPUnit/Util/Log/TestDox/JSON.php';14require_once 'PHPUnit/Util/Log/TestDox/Xml.php';15require_once 'PHPUnit/Util/Log/TestDox/Markdown.php';16require_once 'PHPUnit/Util/Log/TestDox/TextUIResultPrinter.php';17require_once 'PHPUnit/Util/Log/TestDox/TextResultPrinter.php';18require_once 'PHPUnit/Util/Log/TestDox/HtmlResultPrinter.php';19require_once 'PHPUnit/Util/Log/JSON.php';20require_once 'PHPUnit/Util/Log/JUnit.php';21require_once 'PHPUnit/Util/Log/TAP.php';22require_once 'PHPUnit/Util/Log/TeamCity.php';23require_once 'PHPUnit/Util/Log/TestDox/Text.php';24require_once 'PHPUnit/Util/Log/TestDox/HTML.php';25require_once 'PHPUnit/Util/Log/TestDox/CSV.php';26require_once 'PHPUnit/Util/Log/TestDox/JSON.php';27require_once 'PHPUnit/Util/Log/TestDox/Xml.php';28require_once 'PHPUnit/Util/Log/TestDox/Markdown.php';29require_once 'PHPUnit/Util/Log/TestDox/TextUIResultPrinter.php';30require_once 'PHPUnit/Util/Log/TestDox/TextResultPrinter.php';31require_once 'PHPUnit/Util/Log/TestDox/HtmlResultPrinter.php';32require_once 'PHPUnit/Util/Log/JSON.php';33require_once 'PHPUnit/Util/Log/JUnit.php';34require_once 'PHPUnit/Util/Log/TAP.php';35require_once 'PHPUnit/Util/Log/TeamCity.php';36require_once 'PHPUnit/Util/Log/TestDox/Text.php';

Full Screen

Full Screen

methodDoesNotExistOrIsDeclaredInTestCase

Using AI Code Generation

copy

Full Screen

1$testSuite = new TestSuite();2$testSuite->methodDoesNotExistOrIsDeclaredInTestCase('TestCase', 'methodDoesNotExistOrIsDeclaredInTestCase');3Fatal error: Call to undefined method TestSuite::methodDoesNotExistOrIsDeclaredInTestCase()4Related Posts: PHP | ReflectionMethod::invokeArgs() Function5PHP | ReflectionMethod::invoke() Function6PHP | ReflectionMethod::getClosure() Function7PHP | ReflectionMethod::getModifiers() Function8PHP | ReflectionMethod::setAccessible() Function9PHP | ReflectionMethod::isAbstract() Function10PHP | ReflectionMethod::isConstructor() Function11PHP | ReflectionMethod::isDestructor() Function12PHP | ReflectionMethod::isFinal() Function13PHP | ReflectionMethod::isPrivate() Function14PHP | ReflectionMethod::isProtected() Function15PHP | ReflectionMethod::isPublic() Function16PHP | ReflectionMethod::isStatic() Function17PHP | ReflectionMethod::isUserDefined() Function18PHP | ReflectionMethod::getDeclaringClass() Function19PHP | ReflectionMethod::getDocComment() Function20PHP | ReflectionMethod::getEndLine() Function21PHP | ReflectionMethod::getFileName() Function22PHP | ReflectionMethod::getName() Function23PHP | ReflectionMethod::getNumberOfParameters() Function24PHP | ReflectionMethod::getNumberOfRequiredParameters() Function25PHP | ReflectionMethod::getParameters() Function26PHP | ReflectionMethod::getReturnType() Function27PHP | ReflectionMethod::getStartLine() Function28PHP | ReflectionMethod::getStaticVariables() Function29PHP | ReflectionMethod::returnsReference() Function30PHP | ReflectionMethod::__toString() Function31PHP | ReflectionMethod::__construct() Function32PHP | ReflectionMethod::__clone() Function33PHP | ReflectionMethod::__wakeup() Function34PHP | ReflectionMethod::__set_state() Function35PHP | ReflectionMethod::__sleep() Function36PHP | ReflectionMethod::__invoke() Function37PHP | ReflectionMethod::__call() Function38PHP | ReflectionMethod::__callStatic() Function39PHP | ReflectionMethod::__get() Function40PHP | ReflectionMethod::__set() Function41PHP | ReflectionMethod::__isset() Function42PHP | ReflectionMethod::__unset() Function43PHP | ReflectionMethod::__debugInfo() Function44PHP | ReflectionMethod::__destruct() Function45PHP | ReflectionMethod::__serialize() Function46PHP | ReflectionMethod::__unserialize() Function47PHP | ReflectionMethod::__set_state() Function

Full Screen

Full Screen

methodDoesNotExistOrIsDeclaredInTestCase

Using AI Code Generation

copy

Full Screen

1$testSuite = new TestSuite();2$testSuite->methodDoesNotExistOrIsDeclaredInTestCase('TestCase', 'methodDoesNotExistOrIsDeclaredInTestCase');3Fatal error: Call to undefined method TestSuite::methodDoesNotExistOrIsDeclaredInTestCase()4Related Posts: PHP | ReflectionMethod::invokeArgs() Function5PHP | ReflectionMethod::invoke() Function6PHP | ReflectionMethod::getClosure() Function7PHP | ReflectionMethod::getModifiers() Function8PHP | ReflectionMethod::setAccessible() Function9PHP | ReflectionMethod::isAbstract() Function10PHP | ReflectionMethod::isConstructor() Function11PHP | ReflectionMethod::isDestructor() Function12PHP | ReflectionMethod::isFinal() Function13PHP | ReflectionMethod::isPrivate() Function14PHP | ReflectionMethod::isProtected() Function15PHP | ReflectionMethod::isPublic() Function16PHP | ReflectionMethod::isStatic() Function17PHP | ReflectionMethod::isUserDefined() Function

Full Screen

Full Screen

methodDoesNotExistOrIsDeclaredInTestCase

Using AI Code Generation

copy

Full Screen

1$testSuite = new TestSuite();2$testSuite->methodDoesNotExistOrIsDeclaredInTestCase("TestCase", "testMethod");3$testSuite = ew TestSuite();4$testSute->methodDoesNotExistOrIsDeclaredInTestCase("TestCase", "testMethod");5$testSuite = new TestSuite();6$testSuite->methodDoesNotExistOrIsDeclaredInTestCase("TestCase", "testMethod");7$testSuite = new TestSuite();8$testSuite->methodDoesNotExistOrIsDeclaredInTestCase("TestCase", "testMethod");9$testSuite = new TestSuite();10$testSuite->methodDoesNotExistOrIsDeclaredInTestCase("TestCase", "testMethod");11PHP | ReflectionMethod::getDeclaringClass() Function12PHP | ReflectionMethod::getDocComment() Function13PHP | ReflectionMethod::getEndLine() Function14PHP | ReflectionMethod::getFileName() Function15PHP | ReflectionMethod::getName() Function16PHP | ReflectionMethod::getNumberOfParameters() Function17PHP | ReflectionMethod::getNumberOfRequiredParameters() Function18PHP | ReflectionMethod::getParameters() Function19PHP | ReflectionMethod::getReturnType() Function20PHP | ReflectionMethod::getStartLine() Function21PHP | ReflectionMethod::getStaticVariables() Function22PHP | ReflectionMethod::returnsReference() Function23PHP | ReflectionMethod::__toString() Function24PHP | ReflectionMethod::__construct() Function25PHP | ReflectionMethod::__clone() Function26PHP | ReflectionMethod::__wakeup() Function27PHP | ReflectionMethod::__set_state() Function28PHP | ReflectionMethod::__sleep() Function29PHP | ReflectionMethod::__invoke() Function30PHP | ReflectionMethod::__call() Function31PHP | ReflectionMethod::__callStatic() Function32PHP | ReflectionMethod::__get() Function33PHP | ReflectionMethod::__set() Function34PHP | ReflectionMethod::__isset() Function35PHP | ReflectionMethod::__unset() Function36PHP | ReflectionMethod::__debugInfo() Function37PHP | ReflectionMethod::__destruct() Function38PHP | ReflectionMethod::__serialize() Function39PHP | ReflectionMethod::__unserialize() Function40PHP | ReflectionMethod::__set_state() Function

Full Screen

Full Screen

methodDoesNotExistOrIsDeclaredInTestCase

Using AI Code Generation

copy

Full Screen

1require_once 'PHPUnit/Framework.php';2require_once 'PHPUnit/Extensions/Story/TestCase.php';3{4 public function methodDoesNotExistOrIsDeclaredInTestCase($method)5 {6 $class = new ReflectionClass($this->getName());7 if ($class->hasMethod($method)) {8 return true;9 }10 $class = new ReflectionClass('PHPUnit_Extensions_Story_TestCase');11 if ($class->hasMethod($method)) {12 return true;13 }14 return false;15 }16}17require_once 'PHPUnit/Framework.php';18require_once 'PHPUnit/Extensions/Story/TestCase.php';19require_once 'TestSuite.php';20{21 public function methodDoesNotExistOrIsDeclaredInTestCase($method)22 {23 $class = new ReflectionClass($this->getName());24 if ($class->hasMethod($method)) {25 return true;26 }27 $class = new ReflectionClass('PHPUnit_Extensions_Story_TestCase');28 if ($class->hasMethod($method)) {29 return true;30 }31 return false;32 }33}34$testSuite = new TestSuite('TestSuite');35$testSuite->addTestFile('1.php');36$testSuite->addTestFile('2.php');37$testSuite->run();38$testSuite = new PHPUnit_Framework_TestSuite('TestSuite');39$testSuite->addTestFile('1.php');40$testSuite->addTestFile('2.php');41PHPUnit_TextUI_TestRunner::run($testSuite);42$testSuite = new PHPUnit_Framework_TestSuite('TestSuite');43$testSuite->addTestFile('1.php');44$testSuite->addTestFile('2.php');45PHPUnit_TextUI_TestRunner::run($testSuite);46$testSuite = new PHPUnit_Framework_TestSuite('TestSuite');47$testSuite->addTestFile('1.php');48$testSuite->addTestFile('2.php');49PHPUnit_TextUI_TestRunner::run($testSuite);50$testSuite = new PHPUnit_Framework_TestSuite('TestSuite');51$testSuite->addTestFile('1.php');52$testSuite->addTestFile('2

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Phpunit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger methodDoesNotExistOrIsDeclaredInTestCase code on LambdaTest Cloud Grid

Execute automation tests with methodDoesNotExistOrIsDeclaredInTestCase on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful