Best Phpunit code snippet using TestSuite.setName
TestSuite.php
Source:TestSuite.php
...130 );131 }132 // @codeCoverageIgnoreEnd133 } else {134 $this->setName($theClass);135 return;136 }137 }138 if (!$theClass->isSubclassOf(TestCase::class)) {139 $this->setName((string) $theClass);140 return;141 }142 if ($name !== '') {143 $this->setName($name);144 } else {145 $this->setName($theClass->getName());146 }147 $constructor = $theClass->getConstructor();148 if ($constructor !== null &&149 !$constructor->isPublic()) {150 $this->addTest(151 new WarningTestCase(152 \sprintf(153 'Class "%s" has no public constructor.',154 $theClass->getName()155 )156 )157 );158 return;159 }160 foreach ($theClass->getMethods() as $method) {161 if ($method->getDeclaringClass()->getName() === Assert::class) {162 continue;163 }164 if ($method->getDeclaringClass()->getName() === TestCase::class) {165 continue;166 }167 $this->addTestMethod($theClass, $method);168 }169 if (empty($this->tests)) {170 $this->addTest(171 new WarningTestCase(172 \sprintf(173 'No tests found in class "%s".',174 $theClass->getName()175 )176 )177 );178 }179 $this->testCase = true;180 }181 /**182 * Returns a string representation of the test suite.183 */184 public function toString(): string185 {186 return $this->getName();187 }188 /**189 * Adds a test to the suite.190 *191 * @param array $groups192 */193 public function addTest(Test $test, $groups = []): void194 {195 try {196 $class = new \ReflectionClass($test);197 // @codeCoverageIgnoreStart198 } catch (\ReflectionException $e) {199 throw new Exception(200 $e->getMessage(),201 (int) $e->getCode(),202 $e203 );204 }205 // @codeCoverageIgnoreEnd206 if (!$class->isAbstract()) {207 $this->tests[] = $test;208 $this->numTests = -1;209 if ($test instanceof self && empty($groups)) {210 $groups = $test->getGroups();211 }212 if (empty($groups)) {213 $groups = ['default'];214 }215 foreach ($groups as $group) {216 if (!isset($this->groups[$group])) {217 $this->groups[$group] = [$test];218 } else {219 $this->groups[$group][] = $test;220 }221 }222 if ($test instanceof TestCase) {223 $test->setGroups($groups);224 }225 }226 }227 /**228 * Adds the tests from the given class to the suite.229 *230 * @param object|string $testClass231 *232 * @throws Exception233 */234 public function addTestSuite($testClass): void235 {236 if (!(\is_object($testClass) || (\is_string($testClass) && \class_exists($testClass)))) {237 throw InvalidArgumentException::create(238 1,239 'class name or object'240 );241 }242 if (!\is_object($testClass)) {243 try {244 $testClass = new \ReflectionClass($testClass);245 // @codeCoverageIgnoreStart246 } catch (\ReflectionException $e) {247 throw new Exception(248 $e->getMessage(),249 (int) $e->getCode(),250 $e251 );252 }253 // @codeCoverageIgnoreEnd254 }255 if ($testClass instanceof self) {256 $this->addTest($testClass);257 } elseif ($testClass instanceof \ReflectionClass) {258 $suiteMethod = false;259 if (!$testClass->isAbstract() && $testClass->hasMethod(BaseTestRunner::SUITE_METHODNAME)) {260 try {261 $method = $testClass->getMethod(262 BaseTestRunner::SUITE_METHODNAME263 );264 // @codeCoverageIgnoreStart265 } catch (\ReflectionException $e) {266 throw new Exception(267 $e->getMessage(),268 (int) $e->getCode(),269 $e270 );271 }272 // @codeCoverageIgnoreEnd273 if ($method->isStatic()) {274 $this->addTest(275 $method->invoke(null, $testClass->getName())276 );277 $suiteMethod = true;278 }279 }280 if (!$suiteMethod && !$testClass->isAbstract() && $testClass->isSubclassOf(TestCase::class)) {281 $this->addTest(new self($testClass));282 }283 } else {284 throw new Exception;285 }286 }287 /**288 * Wraps both <code>addTest()</code> and <code>addTestSuite</code>289 * as well as the separate import statements for the user's convenience.290 *291 * If the named file cannot be read or there are no new tests that can be292 * added, a <code>PHPUnit\Framework\WarningTestCase</code> will be created instead,293 * leaving the current test run untouched.294 *295 * @throws Exception296 */297 public function addTestFile(string $filename): void298 {299 if (\file_exists($filename) && \substr($filename, -5) === '.phpt') {300 $this->addTest(301 new PhptTestCase($filename)302 );303 return;304 }305 // The given file may contain further stub classes in addition to the306 // test class itself. Figure out the actual test class.307 $filename = FileLoader::checkAndLoad($filename);308 $newClasses = \array_diff(\get_declared_classes(), $this->declaredClasses);309 // The diff is empty in case a parent class (with test methods) is added310 // AFTER a child class that inherited from it. To account for that case,311 // accumulate all discovered classes, so the parent class may be found in312 // a later invocation.313 if (!empty($newClasses)) {314 // On the assumption that test classes are defined first in files,315 // process discovered classes in approximate LIFO order, so as to316 // avoid unnecessary reflection.317 $this->foundClasses = \array_merge($newClasses, $this->foundClasses);318 $this->declaredClasses = \get_declared_classes();319 }320 // The test class's name must match the filename, either in full, or as321 // a PEAR/PSR-0 prefixed short name ('NameSpace_ShortName'), or as a322 // PSR-1 local short name ('NameSpace\ShortName'). The comparison must be323 // anchored to prevent false-positive matches (e.g., 'OtherShortName').324 $shortName = \basename($filename, '.php');325 $shortNameRegEx = '/(?:^|_|\\\\)' . \preg_quote($shortName, '/') . '$/';326 foreach ($this->foundClasses as $i => $className) {327 if (\preg_match($shortNameRegEx, $className)) {328 try {329 $class = new \ReflectionClass($className);330 // @codeCoverageIgnoreStart331 } catch (\ReflectionException $e) {332 throw new Exception(333 $e->getMessage(),334 (int) $e->getCode(),335 $e336 );337 }338 // @codeCoverageIgnoreEnd339 if ($class->getFileName() == $filename) {340 $newClasses = [$className];341 unset($this->foundClasses[$i]);342 break;343 }344 }345 }346 foreach ($newClasses as $className) {347 try {348 $class = new \ReflectionClass($className);349 // @codeCoverageIgnoreStart350 } catch (\ReflectionException $e) {351 throw new Exception(352 $e->getMessage(),353 (int) $e->getCode(),354 $e355 );356 }357 // @codeCoverageIgnoreEnd358 if (\dirname($class->getFileName()) === __DIR__) {359 continue;360 }361 if (!$class->isAbstract()) {362 if ($class->hasMethod(BaseTestRunner::SUITE_METHODNAME)) {363 try {364 $method = $class->getMethod(365 BaseTestRunner::SUITE_METHODNAME366 );367 // @codeCoverageIgnoreStart368 } catch (\ReflectionException $e) {369 throw new Exception(370 $e->getMessage(),371 (int) $e->getCode(),372 $e373 );374 }375 // @codeCoverageIgnoreEnd376 if ($method->isStatic()) {377 $this->addTest($method->invoke(null, $className));378 }379 } elseif ($class->implementsInterface(Test::class)) {380 $this->addTestSuite($class);381 }382 }383 }384 $this->numTests = -1;385 }386 /**387 * Wrapper for addTestFile() that adds multiple test files.388 *389 * @throws Exception390 */391 public function addTestFiles(iterable $fileNames): void392 {393 foreach ($fileNames as $filename) {394 $this->addTestFile((string) $filename);395 }396 }397 /**398 * Counts the number of test cases that will be run by this test.399 */400 public function count(bool $preferCache = false): int401 {402 if ($preferCache && $this->cachedNumTests !== null) {403 return $this->cachedNumTests;404 }405 $numTests = 0;406 foreach ($this as $test) {407 $numTests += \count($test);408 }409 $this->cachedNumTests = $numTests;410 return $numTests;411 }412 /**413 * Returns the name of the suite.414 */415 public function getName(): string416 {417 return $this->name;418 }419 /**420 * Returns the test groups of the suite.421 */422 public function getGroups(): array423 {424 return \array_keys($this->groups);425 }426 public function getGroupDetails(): array427 {428 return $this->groups;429 }430 /**431 * Set tests groups of the test case432 */433 public function setGroupDetails(array $groups): void434 {435 $this->groups = $groups;436 }437 /**438 * Runs the tests and collects their result in a TestResult.439 *440 * @throws \PHPUnit\Framework\CodeCoverageException441 * @throws \SebastianBergmann\CodeCoverage\CoveredCodeNotExecutedException442 * @throws \SebastianBergmann\CodeCoverage\InvalidArgumentException443 * @throws \SebastianBergmann\CodeCoverage\MissingCoversAnnotationException444 * @throws \SebastianBergmann\CodeCoverage\RuntimeException445 * @throws \SebastianBergmann\CodeCoverage\UnintentionallyCoveredCodeException446 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException447 * @throws Warning448 */449 public function run(TestResult $result = null): TestResult450 {451 if ($result === null) {452 $result = $this->createResult();453 }454 if (\count($this) === 0) {455 return $result;456 }457 /** @psalm-var class-string $className */458 $className = $this->name;459 $hookMethods = TestUtil::getHookMethods($className);460 $result->startTestSuite($this);461 try {462 foreach ($hookMethods['beforeClass'] as $beforeClassMethod) {463 if ($this->testCase &&464 \class_exists($this->name, false) &&465 \method_exists($this->name, $beforeClassMethod)) {466 if ($missingRequirements = TestUtil::getMissingRequirements($this->name, $beforeClassMethod)) {467 $this->markTestSuiteSkipped(\implode(\PHP_EOL, $missingRequirements));468 }469 \call_user_func([$this->name, $beforeClassMethod]);470 }471 }472 } catch (SkippedTestSuiteError $error) {473 foreach ($this->tests() as $test) {474 $result->startTest($test);475 $result->addFailure($test, $error, 0);476 $result->endTest($test, 0);477 }478 $result->endTestSuite($this);479 return $result;480 } catch (\Throwable $t) {481 $errorAdded = false;482 foreach ($this->tests() as $test) {483 if ($result->shouldStop()) {484 break;485 }486 $result->startTest($test);487 if (!$errorAdded) {488 $result->addError($test, $t, 0);489 $errorAdded = true;490 } else {491 $result->addFailure(492 $test,493 new SkippedTestError('Test skipped because of an error in hook method'),494 0495 );496 }497 $result->endTest($test, 0);498 }499 $result->endTestSuite($this);500 return $result;501 }502 foreach ($this as $test) {503 if ($result->shouldStop()) {504 break;505 }506 if ($test instanceof TestCase || $test instanceof self) {507 $test->setBeStrictAboutChangesToGlobalState($this->beStrictAboutChangesToGlobalState);508 $test->setBackupGlobals($this->backupGlobals);509 $test->setBackupStaticAttributes($this->backupStaticAttributes);510 $test->setRunTestInSeparateProcess($this->runTestInSeparateProcess);511 }512 $test->run($result);513 }514 try {515 foreach ($hookMethods['afterClass'] as $afterClassMethod) {516 if ($this->testCase &&517 \class_exists($this->name, false) &&518 \method_exists($this->name, $afterClassMethod)) {519 \call_user_func([$this->name, $afterClassMethod]);520 }521 }522 } catch (\Throwable $t) {523 $message = "Exception in {$this->name}::$afterClassMethod" . \PHP_EOL . $t->getMessage();524 $error = new SyntheticError($message, 0, $t->getFile(), $t->getLine(), $t->getTrace());525 $placeholderTest = clone $test;526 $placeholderTest->setName($afterClassMethod);527 $result->startTest($placeholderTest);528 $result->addFailure($placeholderTest, $error, 0);529 $result->endTest($placeholderTest, 0);530 }531 $result->endTestSuite($this);532 return $result;533 }534 public function setRunTestInSeparateProcess(bool $runTestInSeparateProcess): void535 {536 $this->runTestInSeparateProcess = $runTestInSeparateProcess;537 }538 public function setName(string $name): void539 {540 $this->name = $name;541 }542 /**543 * Returns the test at the given index.544 *545 * @return false|Test546 */547 public function testAt(int $index)548 {549 return $this->tests[$index] ?? false;550 }551 /**552 * Returns the tests as an enumeration....
ConverterCheckStyleTest.php
Source:ConverterCheckStyleTest.php
...79 ' </testcase>',80 ' </testsuite>',81 ' <testsuite name="src/JUnit/TestCaseElement.php" file="src/JUnit/TestCaseElement.php" tests="3" failures="3">',82 ' <testcase name="src/JUnit/TestCaseElement.php line 34" class="PhanPluginCanUseParamType" classname="PhanPluginCanUseParamType" file="src/JUnit/TestCaseElement.php" line="34">',83 ' <failure type="PhanPluginCanUseParamType" message="Can use string as the type of parameter $name of setName">',84 'Can use string as the type of parameter $name of setName',85 'Rule : PhanPluginCanUseParamType',86 'File Path: src/JUnit/TestCaseElement.php:34',87 'Severity : warning',88 '</failure>',89 ' </testcase>',90 ' <testcase name="src/JUnit/TestCaseElement.php line 36" class="PhanPluginSuspiciousParamPositionInternal" classname="PhanPluginSuspiciousParamPositionInternal" file="src/JUnit/TestCaseElement.php" line="36">',91 ' <failure type="PhanPluginSuspiciousParamPositionInternal" message="Suspicious order for argument name - This is getting passed to parameter #1 (string $name) of \JBZoo\ToolboxCI\JUnit\TestCaseElement::setAttribute(string $name, string $value)">',92 'Suspicious order for argument name - This is getting passed to parameter #1 (string $name) of \JBZoo\ToolboxCI\JUnit\TestCaseElement::setAttribute(string $name, string $value)',93 'Rule : PhanPluginSuspiciousParamPositionInternal',94 'File Path: src/JUnit/TestCaseElement.php:36',95 'Severity : warning',96 '</failure>',97 ' </testcase>',98 ' <testcase name="src/JUnit/TestCaseElement.php line 42" class="PhanPluginCanUseParamType" classname="PhanPluginCanUseParamType" file="src/JUnit/TestCaseElement.php" line="42">',99 ' <failure type="PhanPluginCanUseParamType" message="Can use string as the type of parameter $classname of setClassname">',100 'Can use string as the type of parameter $classname of setClassname',101 'Rule : PhanPluginCanUseParamType',102 'File Path: src/JUnit/TestCaseElement.php:42',103 'Severity : warning',104 '</failure>',105 ' </testcase>',106 ' </testsuite>',107 ' <testsuite name="src/JUnit/TestSuiteElement.php" file="src/JUnit/TestSuiteElement.php" tests="2" failures="2">',108 ' <testcase name="src/JUnit/TestSuiteElement.php line 35" class="PhanPluginCanUseParamType" classname="PhanPluginCanUseParamType" file="src/JUnit/TestSuiteElement.php" line="35">',109 ' <failure type="PhanPluginCanUseParamType" message="Can use string as the type of parameter $name of setName">',110 'Can use string as the type of parameter $name of setName',111 'Rule : PhanPluginCanUseParamType',112 'File Path: src/JUnit/TestSuiteElement.php:35',113 'Severity : warning',114 '</failure>',115 ' </testcase>',116 ' <testcase name="src/JUnit/TestSuiteElement.php line 37" class="PhanPluginSuspiciousParamPositionInternal" classname="PhanPluginSuspiciousParamPositionInternal" file="src/JUnit/TestSuiteElement.php" line="37">',117 ' <failure type="PhanPluginSuspiciousParamPositionInternal" message="Suspicious order for argument name - This is getting passed to parameter #1 (string $name) of \JBZoo\ToolboxCI\JUnit\TestSuiteElement::setAttribute(string $name, string $value)">',118 'Suspicious order for argument name - This is getting passed to parameter #1 (string $name) of \JBZoo\ToolboxCI\JUnit\TestSuiteElement::setAttribute(string $name, string $value)',119 'Rule : PhanPluginSuspiciousParamPositionInternal',120 'File Path: src/JUnit/TestSuiteElement.php:37',121 'Severity : warning',122 '</failure>',123 ' </testcase>',124 ' </testsuite>',125 ' </testsuite>',126 '</testsuites>',127 ''128 ]), $actual);129 }130 public function testToInternalPHPcs()131 {132 $pathPrefix = '/Users/smetdenis/Work/projects/jbzoo-toolbox-ci';133 $source = (new CheckStyleConverter())134 ->setRootPath($pathPrefix)135 ->toInternal(file_get_contents(Fixtures::PHPCS_CODESTYLE));136 $actual = (new JUnitConverter())->fromInternal($source);137 Aliases::isValidXml($actual);138 isSame(implode("\n", [139 '<?xml version="1.0" encoding="UTF-8"?>',140 '<testsuites>',141 ' <testsuite name="CheckStyle" tests="3" failures="3">',142 ' <testsuite name="src/JUnit/JUnitXml.php" file="src/JUnit/JUnitXml.php" tests="3" failures="3">',143 ' <testcase name="src/JUnit/JUnitXml.php line 24, column 5" class="PSR12.Properties.ConstantVisibility.NotFound" classname="PSR12.Properties.ConstantVisibility.NotFound" file="src/JUnit/JUnitXml.php" line="24">',144 ' <failure type="PSR12.Properties.ConstantVisibility.NotFound" message="Visibility must be declared on all constants if your project supports PHP 7.1 or later">',145 'Visibility must be declared on all constants if your project supports PHP 7.1 or later',146 'Rule : PSR12.Properties.ConstantVisibility.NotFound',147 'File Path: src/JUnit/JUnitXml.php:24:5',148 'Severity : warning',149 '</failure>',150 ' </testcase>',151 ' <testcase name="src/JUnit/JUnitXml.php line 44, column 35" class="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" classname="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" file="src/JUnit/JUnitXml.php" line="44">',152 ' <failure type="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" message="Opening brace should be on a new line">',153 'Opening brace should be on a new line',154 'Rule : Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine',155 'File Path: src/JUnit/JUnitXml.php:44:35',156 'Severity : error',157 '</failure>',158 ' </testcase>',159 ' <testcase name="src/JUnit/JUnitXml.php line 50, column 1" class="PSR2.Files.EndFileNewline.NoneFound" classname="PSR2.Files.EndFileNewline.NoneFound" file="src/JUnit/JUnitXml.php" line="50">',160 ' <failure type="PSR2.Files.EndFileNewline.NoneFound" message="Expected 1 newline at end of file; 0 found">',161 'Expected 1 newline at end of file; 0 found',162 'Rule : PSR2.Files.EndFileNewline.NoneFound',163 'File Path: src/JUnit/JUnitXml.php:50',164 'Severity : error',165 '</failure>',166 ' </testcase>',167 ' </testsuite>',168 ' </testsuite>',169 '</testsuites>',170 '',171 ]), $actual);172 }173 public function testToInternalPhpStan()174 {175 $pathPrefix = '/Users/smetdenis/Work/projects/jbzoo-toolbox-ci';176 $source = (new CheckStyleConverter())177 ->setRootPath($pathPrefix)178 ->toInternal(file_get_contents(Fixtures::PHPSTAN_CHECKSTYLE));179 $actual = (new JUnitConverter())->fromInternal($source);180 Aliases::isValidXml($actual);181 isSame(implode("\n", [182 '<?xml version="1.0" encoding="UTF-8"?>',183 '<testsuites>',184 ' <testsuite name="CheckStyle" tests="5" failures="5">',185 ' <testsuite name="src/JUnit/TestCaseElement.php" file="src/JUnit/TestCaseElement.php" tests="4" failures="4">',186 ' <testcase name="src/JUnit/TestCaseElement.php line 34, column 1" class="ERROR" classname="ERROR" file="src/JUnit/TestCaseElement.php" line="34">',187 ' <failure type="ERROR" message="Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setName() has no return typehint specified.">',188 'Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setName() has no return typehint specified.',189 'File Path: src/JUnit/TestCaseElement.php:34',190 'Severity : error',191 '</failure>',192 ' </testcase>',193 ' <testcase name="src/JUnit/TestCaseElement.php line 42, column 1" class="ERROR" classname="ERROR" file="src/JUnit/TestCaseElement.php" line="42">',194 ' <failure type="ERROR" message="Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setClassname() has no return typehint specified.">',195 'Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setClassname() has no return typehint specified.',196 'File Path: src/JUnit/TestCaseElement.php:42',197 'Severity : error',198 '</failure>',199 ' </testcase>',200 ' <testcase name="src/JUnit/TestCaseElement.php line 52, column 1" class="ERROR" classname="ERROR" file="src/JUnit/TestCaseElement.php" line="52">',201 ' <failure type="ERROR" message="Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setTime() has no return typehint specified.">',202 'Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setTime() has no return typehint specified.',203 'File Path: src/JUnit/TestCaseElement.php:52',204 'Severity : error',205 '</failure>',206 ' </testcase>',207 ' <testcase name="src/JUnit/TestCaseElement.php line 54, column 1" class="ERROR" classname="ERROR" file="src/JUnit/TestCaseElement.php" line="54">',208 ' <failure type="ERROR" message="Parameter #2 $value of method DOMElement::setAttribute() expects string, float given.">',209 'Parameter #2 $value of method DOMElement::setAttribute() expects string, float given.',210 'File Path: src/JUnit/TestCaseElement.php:54',211 'Severity : error',212 '</failure>',213 ' </testcase>',214 ' </testsuite>',215 ' <testsuite name="undefined" file="undefined" tests="1" failures="1">',216 ' <testcase name="undefined" class="ERROR" classname="ERROR" file="undefined">',217 ' <failure type="ERROR" message="Ignored error pattern #Variable \$undefined might not be defined.# was not matched in reported errors.">',218 'Ignored error pattern #Variable \$undefined might not be defined.# was not matched in reported errors.',219 'File Path: undefined',220 'Severity : error',221 '</failure>',222 ' </testcase>',223 ' </testsuite>',224 ' </testsuite>',225 '</testsuites>',226 '',227 ]), $actual);228 }229 public function testToInternalPsalm()230 {231 $pathPrefix = '/Users/smetdenis/Work/projects/jbzoo-toolbox-ci';232 $source = (new CheckStyleConverter())233 ->setRootPath($pathPrefix)234 ->toInternal(file_get_contents(Fixtures::PSALM_CHECKSTYLE));235 $actual = (new JUnitConverter())->fromInternal($source);236 Aliases::isValidXml($actual);237 isSame(implode("\n", [238 '<?xml version="1.0" encoding="UTF-8"?>',239 '<testsuites>',240 ' <testsuite name="CheckStyle" tests="5" failures="5">',241 ' <testsuite name="src/JUnit/TestCaseElement.php" file="src/JUnit/TestCaseElement.php" tests="5" failures="5">',242 ' <testcase name="src/JUnit/TestCaseElement.php line 34, column 21" class="ERROR" classname="ERROR" file="src/JUnit/TestCaseElement.php" line="34">',243 ' <failure type="ERROR" message="MissingReturnType: Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setName does not have a return type, expecting void">',244 'MissingReturnType: Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setName does not have a return type, expecting void',245 'File Path: src/JUnit/TestCaseElement.php:34:21',246 'Severity : error',247 '</failure>',248 ' </testcase>',249 ' <testcase name="src/JUnit/TestCaseElement.php line 42, column 21" class="ERROR" classname="ERROR" file="src/JUnit/TestCaseElement.php" line="42">',250 ' <failure type="ERROR" message="MissingReturnType: Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setClassname does not have a return type, expecting void">',251 'MissingReturnType: Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setClassname does not have a return type, expecting void',252 'File Path: src/JUnit/TestCaseElement.php:42:21',253 'Severity : error',254 '</failure>',255 ' </testcase>',256 ' <testcase name="src/JUnit/TestCaseElement.php line 52, column 21" class="ERROR" classname="ERROR" file="src/JUnit/TestCaseElement.php" line="52">',257 ' <failure type="ERROR" message="MissingReturnType: Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setTime does not have a return type, expecting void">',258 'MissingReturnType: Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setTime does not have a return type, expecting void',...
ConverterPsalmJsonTest.php
Source:ConverterPsalmJsonTest.php
...41 'file' => '/Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElement.php',42 'line' => 34,43 'failure' => [44 'type' => 'MissingReturnType',45 'message' => 'Method JBZoo\\ToolboxCI\\JUnit\\TestCaseElement::setName does not have a return type, expecting void',46 'details' => '47Method JBZoo\\ToolboxCI\\JUnit\\TestCaseElement::setName does not have a return type, expecting void48Rule : MissingReturnType49File Path : /Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElement.php:3450Snippet : `public function setName()`51Docs : https://psalm.dev/05052Severity : error53Error Level: 254',55 ],56 ], $actual->toArray()['suites'][0]['cases'][0]);57 }58 public function testConvertToJUnit()59 {60 $actual = (new PsalmJsonConverter())61 ->toInternal(file_get_contents(Fixtures::PSALM_JSON));62 $junit = (new JUnitConverter())->fromInternal($actual);63 isSame(implode("\n", [64 '<?xml version="1.0" encoding="UTF-8"?>',65 '<testsuites>',66 ' <testsuite name="Psalm" tests="3" warnings="2" failures="1">',67 ' <testsuite name="src/JUnit/TestCaseElement.php" file="/Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElement.php" tests="2" warnings="1" failures="1">',68 ' <testcase name="src/JUnit/TestCaseElement.php line 34" class="MissingReturnType" classname="MissingReturnType" file="/Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElement.php" line="34">',69 ' <failure type="MissingReturnType" message="Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setName does not have a return type, expecting void">',70 'Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setName does not have a return type, expecting void',71 'Rule : MissingReturnType',72 'File Path : /Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElement.php:34',73 'Snippet : `public function setName()`',74 'Docs : https://psalm.dev/050',75 'Severity : error',76 'Error Level: 2',77 '</failure>',78 ' </testcase>',79 ' <testcase name="src/JUnit/TestCaseElement.php line 42" class="MissingReturnType" classname="MissingReturnType" file="/Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElement.php" line="42">',80 ' <warning type="MissingReturnType" message="Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setClassname does not have a return type, expecting void">',81 'Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setClassname does not have a return type, expecting void',82 'Rule : MissingReturnType',83 'File Path : /Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElement.php:42',84 'Snippet : `public function setClassname()`',85 'Docs : https://psalm.dev/050',86 'Severity : info',87 'Error Level: -1',88 '</warning>',89 ' </testcase>',90 ' </testsuite>',91 ' <testsuite name="src/JUnit/TestCaseElementSuppress.php" file="/Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElementSuppress.php" tests="1" warnings="1">',92 ' <testcase name="src/JUnit/TestCaseElementSuppress.php line 42" class="MissingReturnType" classname="MissingReturnType" file="/Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElementSuppress.php" line="42">',93 ' <warning type="MissingReturnType" message="Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setClassname does not have a return type, expecting void">',94 'Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setClassname does not have a return type, expecting void',95 'Rule : MissingReturnType',96 'File Path : /Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElementSuppress.php:42',97 'Snippet : `public function setClassname()`',98 'Docs : https://psalm.dev/050',99 'Severity : suppress',100 'Error Level: -2',101 '</warning>',102 ' </testcase>',103 ' </testsuite>',104 ' </testsuite>',105 '</testsuites>',106 '',107 ]), $junit);108 }109 public function testConvertToTeamCity()110 {111 $actual = (new PsalmJsonConverter())112 ->toInternal(file_get_contents(Fixtures::PSALM_JSON));113 $junit = (new TeamCityTestsConverter(['show-datetime' => false], 76978))->fromInternal($actual);114 isSame(implode("", [115 "\n##teamcity[testCount count='3' flowId='76978']\n",116 "\n##teamcity[testSuiteStarted name='Psalm' flowId='76978']\n",117 "\n##teamcity[testSuiteStarted name='src/JUnit/TestCaseElement.php' locationHint='php_qn:///Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElement.php::\src/JUnit/TestCaseElement.php' flowId='76978']\n",118 "\n##teamcity[testStarted name='src/JUnit/TestCaseElement.php line 34' locationHint='php_qn:///Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElement.php::\MissingReturnType::src/JUnit/TestCaseElement.php line 34' flowId='76978']\n",119 "\n##teamcity[testFailed name='src/JUnit/TestCaseElement.php line 34' message='Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setName does not have a return type, expecting void' details=' Rule : MissingReturnType|n File Path : /Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElement.php:34|n Snippet : `public function setName()`|n Docs : https://psalm.dev/050|n Severity : error|n Error Level: 2|n ' flowId='76978']\n",120 "\n##teamcity[testFinished name='src/JUnit/TestCaseElement.php line 34' flowId='76978']\n",121 "\n##teamcity[testStarted name='src/JUnit/TestCaseElement.php line 42' locationHint='php_qn:///Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElement.php::\MissingReturnType::src/JUnit/TestCaseElement.php line 42' flowId='76978']\n",122 "\n##teamcity[testFailed name='src/JUnit/TestCaseElement.php line 42' message='Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setClassname does not have a return type, expecting void' details=' Rule : MissingReturnType|n File Path : /Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElement.php:42|n Snippet : `public function setClassname()`|n Docs : https://psalm.dev/050|n Severity : info|n Error Level: -1|n ' flowId='76978']\n",123 "\n##teamcity[testFinished name='src/JUnit/TestCaseElement.php line 42' flowId='76978']\n",124 "\n##teamcity[testSuiteFinished name='src/JUnit/TestCaseElement.php' flowId='76978']\n",125 "\n##teamcity[testSuiteStarted name='src/JUnit/TestCaseElementSuppress.php' locationHint='php_qn:///Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElementSuppress.php::\src/JUnit/TestCaseElementSuppress.php' flowId='76978']\n",126 "\n##teamcity[testStarted name='src/JUnit/TestCaseElementSuppress.php line 42' locationHint='php_qn:///Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElementSuppress.php::\MissingReturnType::src/JUnit/TestCaseElementSuppress.php line 42' flowId='76978']\n",127 "\n##teamcity[testFailed name='src/JUnit/TestCaseElementSuppress.php line 42' message='Method JBZoo\ToolboxCI\JUnit\TestCaseElement::setClassname does not have a return type, expecting void' details=' Rule : MissingReturnType|n File Path : /Users/smetdenis/Work/projects/jbzoo-toolbox-ci/src/JUnit/TestCaseElementSuppress.php:42|n Snippet : `public function setClassname()`|n Docs : https://psalm.dev/050|n Severity : suppress|n Error Level: -2|n ' flowId='76978']\n",128 "\n##teamcity[testFinished name='src/JUnit/TestCaseElementSuppress.php line 42' flowId='76978']\n",129 "\n##teamcity[testSuiteFinished name='src/JUnit/TestCaseElementSuppress.php' flowId='76978']\n",130 "\n##teamcity[testSuiteFinished name='Psalm' flowId='76978']\n",131 '',132 ]), $junit);133 }...
EmailTemplateTest.php
Source:EmailTemplateTest.php
...30 ->add()31 ->assertTitle('Create Email Template - Templates - Emails - System')32 ->setEntityName('User')33 ->setType('Html')34 ->setName($templatename)35 ->setSubject('Subject')36 ->setContent('Template content')37 ->save()38 ->assertMessage('Template saved')39 ->assertTitle('Templates - Emails - System')40 ->close();41 return $templatename;42 }43 /**44 * @depends testCreateEmailTemplate45 * @param $templatename46 * @return string47 */48 public function testCloneEmailTemplate($templatename)49 {50 $newtemplatename = 'Clone_' . $templatename;51 $fields = array();52 $login = new Login($this);53 $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN)54 ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS)55 ->submit()56 ->openEmailTemplates()57 ->cloneEntity('Template name', $templatename)58 ->setName($newtemplatename)59 ->save()60 ->assertMessage('Template saved')61 ->assertTitle('Templates - Emails - System')62 ->close()63 ->open(array($newtemplatename))64 ->getFields($fields);65 $this->assertEquals('User', $fields['entityname']);66 $this->assertEquals('Html', $fields['type']);67 $this->assertEquals('Subject', $fields['subject']);68 $this->assertEquals('Template content', $fields['content']);69 return $newtemplatename;70 }71 /**72 * @depends testCreateEmailTemplate73 * @param $templatename74 * @return string75 */76 public function testUpdateEmailTemplate($templatename)77 {78 $newtemplatename = 'Update_' . $templatename;79 $login = new Login($this);80 $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN)81 ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS)82 ->submit()83 ->openEmailTemplates()84 ->open(array($templatename))85 ->setName($newtemplatename)86 ->save()87 ->assertMessage('Template saved')88 ->assertTitle('Templates - Emails - System')89 ->close();90 return $newtemplatename;91 }92 /**93 * @depends testUpdateEmailTemplate94 * @param $templatename95 */96 public function testDeleteEmailTemplate($templatename)97 {98 $login = new Login($this);99 $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN)...
DatabaseMigrateTestListenerTest.php
Source:DatabaseMigrateTestListenerTest.php
...17 PHPMockery::mock('Softonic\DatabaseMigrateTestListener', 'shell_exec')18 ->with('php artisan migrate:refresh --database sqlite ')19 ->once();20 $testSuite = new TestSuite();21 $testSuite->setName('Feature');22 $listener->startTestSuite($testSuite);23 }24 public function testMigrateCommandHasBeenExecutedSeedingData()25 {26 $listener = new DatabaseMigrateTestListener(['Feature'], true);27 PHPMockery::mock('Softonic\DatabaseMigrateTestListener', 'shell_exec')28 ->with('php artisan migrate:refresh --database sqlite --seed ')29 ->once();30 $testSuite = new TestSuite();31 $testSuite->setName('Feature');32 $listener->startTestSuite($testSuite);33 }34 public function testMigrateCommandHasBeenExecutedOnSpecifiedConnection()35 {36 $listener = new DatabaseMigrateTestListener(['Feature'], false, 'testing');37 PHPMockery::mock('Softonic\DatabaseMigrateTestListener', 'shell_exec')38 ->with('php artisan migrate:refresh --database testing ')39 ->once();40 $testSuite = new TestSuite();41 $testSuite->setName('Feature');42 $listener->startTestSuite($testSuite);43 }44 public function testMigrateCommandHasNotBeenExecutedWhenTestSuiteDontMatches()45 {46 $listener = new DatabaseMigrateTestListener(['Feature'], false);47 PHPMockery::mock('Softonic\DatabaseMigrateTestListener', 'chdir')->never();48 PHPMockery::mock('Softonic\DatabaseMigrateTestListener', 'shell_exec')->never();49 $testSuite = new TestSuite();50 $testSuite->setName('Unit');51 $listener->startTestSuite($testSuite);52 }53 public function testMigrateCommandHasSpecificSeederShouldStartTheTestSuite()54 {55 $listener = new DatabaseMigrateTestListener(56 ['Feature'],57 true,58 'sqlite',59 '\\App\\Database\\Seeders\\MyNamespace\\DatabaseSeeder'60 );61 PHPMockery::mock('Softonic\DatabaseMigrateTestListener', 'shell_exec')62 ->with('php artisan migrate:refresh --database sqlite --seed --seeder=\\App\\Database\\Seeders\\MyNamespace\\DatabaseSeeder')63 ->once();64 $testSuite = new TestSuite();65 $testSuite->setName('Feature');66 $listener->startTestSuite($testSuite);67 }68 public function tearDown(): void69 {70 parent::tearDown();71 Mockery::close();72 }73}...
setName
Using AI Code Generation
1$ts = new TestSuite();2$ts->setName("My Test Suite");3$ts = new TestSuite();4echo $ts->getName();5$ts = new TestSuite();6echo $ts->getTestCase();7$ts = new TestSuite();8echo $ts->getTestCaseCount();9$ts = new TestSuite();10$ts->addTestCase(new TestCase());11$ts = new TestSuite();12$ts->addTestSuite(new TestSuite());13$ts = new TestSuite();14$ts->run();15$ts = new TestSuite();16$ts->runTest();17$ts = new TestSuite();18$ts->runTest();19$ts = new TestSuite();20$ts->runTest();21$ts = new TestSuite();22$ts->runTest();23$ts = new TestSuite();24$ts->runTest();25$ts = new TestSuite();26$ts->runTest();27$ts = new TestSuite();28$ts->runTest();29$ts = new TestSuite();30$ts->runTest();31$ts = new TestSuite();
setName
Using AI Code Generation
1$obj = new TestSuite();2$obj->setName('TestSuite');3$obj->addTestFile('2.php');4$obj->addTestFile('3.php');5$obj->addTestFile('4.php');6$obj->addTestFile('5.php');7$obj->addTestFile('6.php');8$obj->addTestFile('7.php');9$obj->run($result);10{11 public function test2()12 {13 $this->assertTrue(true);14 }15}16{17 public function test3()18 {19 $this->assertTrue(true);20 }21}22{23 public function test4()24 {25 $this->assertTrue(true);26 }27}28{29 public function test5()30 {31 $this->assertTrue(true);32 }33}34{35 public function test6()36 {37 $this->assertTrue(true);38 }39}40{41 public function test7()42 {43 $this->assertTrue(true);44 }45}46{47 public function test8()48 {49 $this->assertTrue(true);50 }51}52{53 public function test9()54 {55 $this->assertTrue(true);56 }57}58{59 public function test10()60 {61 $this->assertTrue(true);62 }63}64{65 public function test11()66 {67 $this->assertTrue(true);68 }69}
setName
Using AI Code Generation
1require_once 'simpletest/unit_tester.php';2require_once 'simpletest/reporter.php';3require_once 'simpletest/mock_objects.php';4class TestOfTestSuite extends UnitTestCase {5function testSetTestSuiteName() {6$test = new TestSuite('TestOfTestSuite');7$test->setName('NewName');8$this->assertEqual($test->getLabel(), 'NewName');9}10}11require_once 'simpletest/unit_tester.php';12require_once 'simpletest/reporter.php';13require_once 'simpletest/mock_objects.php';14class TestOfTestSuite extends UnitTestCase {15function testRunTestSuite() {16$test = new TestSuite('TestOfTestSuite');17$test->addTestFile('1.php');18$test->run(new SimpleReporter());19}20}21require_once 'simpletest/unit_tester.php';22require_once 'simpletest/reporter.php';23require_once 'simpletest/mock_objects.php';24class TestOfTestSuite extends UnitTestCase {25function testAttachObserver() {26$test = new TestSuite('TestOfTestSuite');27$test->attachObserver(new SimpleReporter());28}29}30require_once 'simpletest/unit_tester.php';31require_once 'simpletest/reporter.php';32require_once 'simpletest/mock_objects.php';33class TestOfTestSuite extends UnitTestCase {34function testDetachObserver() {35$test = new TestSuite('TestOfTestSuite');36$test->attachObserver(new SimpleReporter());37$test->detachObserver(new SimpleReporter());38}39}40require_once 'simpletest/unit_tester.php';41require_once 'simpletest/reporter.php';42require_once 'simpletest/mock_objects.php';43class TestOfTestSuite extends UnitTestCase {44function testGetTestCase() {45$test = new TestSuite('TestOfTestSuite');46$test->addTestFile('1.php');47$test->getTestCase('testSetTestSuiteName');48}49}50require_once 'simpletest/unit_tester.php';51require_once 'simpletest/reporter.php';
setName
Using AI Code Generation
1$test = new TestSuite();2$test->setName('Sample Test');3echo $test->getName();4Recommended Posts: PHP | PHPUnit | setUpBeforeClass() Method5PHP | PHPUnit | tearDown() Method6PHP | PHPUnit | tearDownAfterClass() Method7PHP | PHPUnit | getNumAssertions() Method8PHP | PHPUnit | getGroups() Method9PHP | PHPUnit | getAnnotations() Method10PHP | PHPUnit | getLinesToBeCovered() Method11PHP | PHPUnit | getLinesToBeUsed() Method12PHP | PHPUnit | getTestResultObject() Method13PHP | PHPUnit | getActualOutput() Method14PHP | PHPUnit | getBackupGlobals() Method15PHP | PHPUnit | getBackupStaticAttributes() Method16PHP | PHPUnit | getBeStrictAboutChangesToGlobalState() Method17PHP | PHPUnit | getRunClassInSeparateProcess() Method18PHP | PHPUnit | getRunTestInSeparateProcess() Method19PHP | PHPUnit | getPreserveGlobalState() Method20PHP | PHPUnit | getUseErrorHandler() Method21PHP | PHPUnit | getUseOutputBuffering() Method22PHP | PHPUnit | getRegisterMockObjectsFromTestArgumentsRecursively() Method23PHP | PHPUnit | getReorderTestsInDataProvider() Method24PHP | PHPUnit | getMockObjects() Method25PHP | PHPUnit | getProphet() Method26PHP | PHPUnit | getDependencies() Method27PHP | PHPUnit | getDepends() Method28PHP | PHPUnit | getExpectedException() Method29PHP | PHPUnit | getExpectedExceptionCode() Method30PHP | PHPUnit | getExpectedExceptionMessage() Method31PHP | PHPUnit | getExpectedExceptionMessageRegExp() Method32PHP | PHPUnit | getExpectedExceptionObject() Method33PHP | PHPUnit | getTestResultObject() Method34PHP | PHPUnit | getActualOutput() Method35PHP | PHPUnit | getBackupGlobals() Method36PHP | PHPUnit | getBackupStaticAttributes() Method37PHP | PHPUnit | getBeStrictAboutChangesToGlobalState() Method38PHP | PHPUnit | getRunClassInSeparateProcess() Method39PHP | PHPUnit | getRunTestInSeparateProcess() Method40PHP | PHPUnit | getPreserveGlobalState() Method41PHP | PHPUnit | getUseErrorHandler() Method42PHP | PHPUnit | getUseOutputBuffering() Method43PHP | PHPUnit | getRegisterMockObjectsFromTestArgumentsRecursively() Method
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with setName on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!