How to use requires method of TestSuite class

Best Phpunit code snippet using TestSuite.requires

TestCase.php

Source:TestCase.php Github

copy

Full Screen

...55 * Each condition is a boolean expression of features. All of them56 * must be True for the test to run.57 * FIXME should target triple parts count here too?58 *59 * @var array $requires60 */61 private $requires = array();62 /**63 * A list of conditions that prevent execution of the test.64 * Each condition is a boolean expression of features and target65 * triple parts. All of them must be False for the test to run.66 *67 * @var array $unsupported68 */69 private $unsupported = array();70 /**71 * @var TestResult $result72 */73 private $result = null;74 public function __construct(TestSuite $suite, array $pathInSuite, TestingConfig $config, string $filePath = null)75 {76 $this->testSuite = $suite;77 $this->pathInSuite = $pathInSuite;78 $this->config = $config;79 $this->filePath = $filePath;80 }81 public function setResult(TestResult $result)82 {83 if ($this->result != null) {84 throw new ValueException('test result already set');85 }86 $this->result = $result;87 // Apply the XFAIL handling to resolve the result exit code.88 try {89 if ($this->isExpectedToFail()) {90 if ($this->result->getCode() === TestResultCode::PASS()) {91 $this->result->setCode(TestResultCode::XPASS());92 } else if ($this->result->getCode() === TestResultCode::FAIL()) {93 $this->result->setCode(TestResultCode::XFAIL());94 }95 }96 } catch (ValueException $e) {97 // Syntax error in an XFAIL line.98 $this->result->setCode(TestResultCode::UNRESOLVED());99 $this->result->setOutput($e->getMessage());100 }101 }102 public function getFullName() : string103 {104 return $this->testSuite->getConfig()->getName() . ' :: ' . implode('/', $this->pathInSuite);105 }106 public function getFilePath() : string107 {108 if ($this->filePath) {109 return $this->filePath;110 }111 return $this->getSourcePath();112 }113 public function getSourcePath() : string114 {115 return $this->testSuite->getSourcePath($this->pathInSuite);116 }117 public function getExecPath() : string118 {119 return $this->testSuite->getExecPath($this->pathInSuite);120 }121 /**122 * Check whether this test is expected to fail in the current123 * configuration. This check relies on the test xfails property which by124 * some test formats may not be computed until the test has first been125 * executed.126 * Throws ValueError if an XFAIL line has a syntax error.127 *128 * @return bool129 */130 public function isExpectedToFail() : bool131 {132 $features = $this->config->getAvailableFeatures();133 $triple = $this->testSuite->getConfig()->getExtraConfig('target_triple', '');134 // Check if any of the xfails match an available feature or the target.135 foreach ($this->xfails as $item) {136 if ($item == '*') {137 return true;138 }139 // If this is a True expression of features and target triple parts,140 // it fails.141 try {142 if (BooleanExpr::evaluate($item, $features, $triple)) {143 return true;144 }145 } catch (ValueException $e) {146 throw new ValueException(sprintf("'Error in XFAIL list:\n%s'", $e->getMessage()));147 }148 }149 return false;150 }151 /**152 * A test is within the feature limits set by run_only_tests if153 * 1. the test's requirements ARE satisfied by the available features154 * 2. the test's requirements ARE NOT satisfied after the limiting155 * features are removed from the available features156 * Throws ValueError if a REQUIRES line has a syntax error.157 *158 * @return bool159 */160 public function isWithinFeatureLimits() : bool161 {162 if (empty($this->config->getLimitToFeatures())) {163 return true;164 }165 // Check the requirements as-is (#1)166 if ($this->getMissingRequiredFeatures()) {167 return false;168 }169 // Check the requirements after removing the limiting features (#2)170 $featuresMinusLimits = array();171 $availableFeatures = $this->config->getAvailableFeatures();172 $limitFeatures = $this->config->getLimitToFeatures();173 foreach ($availableFeatures as $feature) {174 if (!in_array($feature, $limitFeatures)) {175 $featuresMinusLimits[] = $feature;176 }177 }178 if (empty($this->getMissingRequiredFeaturesFromList($featuresMinusLimits))) {179 return false;180 }181 return true;182 }183 public function getMissingRequiredFeaturesFromList(array $features) : array184 {185 $evalResult = array();186 try {187 foreach ($this->requires as $item) {188 if (!BooleanExpr::evaluate($item, $features)) {189 $evalResult[] = $item;190 }191 }192 return $evalResult;193 } catch (ValueException $e) {194 throw new ValueException(sprintf("Error in REQUIRES list:\n%s", $e->getMessage()));195 }196 }197 /**198 * Returns a list of features from REQUIRES that are not satisfied."199 * Throws ValueError if a REQUIRES line has a syntax error.200 *201 * @return array202 */203 public function getMissingRequiredFeatures() : array204 {205 $features = $this->config->getAvailableFeatures();206 return $this->getMissingRequiredFeaturesFromList($features);207 }208 /**209 * Returns a list of features from UNSUPPORTED that are present210 * in the test configuration's features or target triple.211 * Throws ValueError if an UNSUPPORTED line has a syntax error.212 *213 * @return array214 */215 public function getUnsupportedFeatures(): array216 {217 $features = $this->config->getAvailableFeatures();218 $triple = $this->testSuite->getConfig()->getExtraConfig('target_triple', '');219 $evalResult = array();220 try {221 foreach ($this->unsupported as $item) {222 if (BooleanExpr::evaluate($item, $features, $triple)) {223 $evalResult[] = $item;224 }225 }226 return $evalResult;227 } catch (ValueException $e) {228 throw new ValueException(sprintf("Error in UNSUPPORTED list:\n%s", $e->getMessage()));229 }230 }231 /**232 * Check whether this test should be executed early in a particular run.233 * This can be used for test suites with long running tests to maximize234 * parallelism or where it is desirable to surface their failures early.235 *236 * @return bool237 */238 public function isEarlyTest() : bool239 {240 return $this->testSuite->getConfig()->isEarly();241 }242 /**243 * Write the test's report xml representation to a file handle.244 *245 * @param $file246 */247 public function writeJUnitXML($file)248 {249 $testName = htmlspecialchars($this->pathInSuite[count($this->pathInSuite) - 1], ENT_XML1 | ENT_COMPAT, 'UTF-8');250 $testPath = array_slice($this->pathInSuite, 0, -1);251 $safeTestPath = array();252 foreach ($testPath as $path) {253 $safeTestPath[] = str_replace('.', '_', $path);254 }255 $safeName = str_replace('.', '_', $this->testSuite->getName());256 if ($safeTestPath) {257 $className = $safeName .'.' .implode('/', $safeTestPath);258 } else {259 $className = $safeName . '.' . $safeName;260 }261 $className = escape_xml_attr($className);262 $elapsedTime = $this->result->getElapsed();263 $testcaseTemplate = '<testcase classname=%s name=%s time=%s';264 $testcaseXml = sprintf($testcaseTemplate, quote_xml_attr($className),265 quote_xml_attr($testName), quote_xml_attr(sprintf("%.2f", $elapsedTime)));266 fwrite($file, $testcaseXml);267 if ($this->result->getCode()->isFailure()) {268 fwrite($file,">\n\t<failure ><![CDATA[");269 $output = $this->result->getOutput();270 // In the unlikely case that the output contains the CDATA terminator271 // we wrap it by creating a new CDATA block272 fwrite($file, str_replace("]]>","]]]]><![CDATA[>", $output));273 fwrite($file, "]]></failure>\n</testcase>");274 } else if ($this->result->getCode() === TestResultCode::UNSUPPORTED()) {275 $unsupportedFeatures = $this->getMissingRequiredFeatures();276 if (!empty($unsupportedFeatures)) {277 $skipMessage = "Skipping because of: " . join(',', $unsupportedFeatures);278 } else {279 $skipMessage = 'Skipping because of configuration.';280 }281 fwrite($file, sprintf(">\n\t<skipped message=%s />\n</testcase>\n", quote_xml_attr($skipMessage)));282 } else {283 fwrite($file, "/>");284 }285 }286 /**287 * @return TestSuite288 */289 public function getTestSuite(): TestSuite290 {291 return $this->testSuite;292 }293 /**294 * @param TestSuite $testSuite295 * @return TestCase296 */297 public function setTestSuite(TestSuite $testSuite): TestCase298 {299 $this->testSuite = $testSuite;300 return $this;301 }302 /**303 * @return string304 */305 public function getPathInSuite(): string306 {307 return $this->pathInSuite;308 }309 /**310 * @param string $pathInSuite311 * @return TestCase312 */313 public function setPathInSuite(string $pathInSuite): TestCase314 {315 $this->pathInSuite = $pathInSuite;316 return $this;317 }318 /**319 * @return TestingConfig320 */321 public function getConfig(): TestingConfig322 {323 return $this->config;324 }325 /**326 * @param TestingConfig $config327 * @return TestCase328 */329 public function setConfig(TestingConfig $config): TestCase330 {331 $this->config = $config;332 return $this;333 }334 /**335 * @param string $filePath336 * @return TestCase337 */338 public function setFilePath(string $filePath): TestCase339 {340 $this->filePath = $filePath;341 return $this;342 }343 /**344 * @return array345 */346 public function getXfails(): array347 {348 return $this->xfails;349 }350 /**351 * @param array $xfails352 * @return TestCase353 */354 public function setXfails(array $xfails): TestCase355 {356 $this->xfails = $xfails;357 return $this;358 }359 /**360 * @return array361 */362 public function getRequires(): array363 {364 return $this->requires;365 }366 /**367 * @param array $requires368 * @return TestCase369 */370 public function setRequires(array $requires): TestCase371 {372 $this->requires = $requires;373 return $this;374 }375 /**376 * @return array377 */378 public function getUnsupported(): array379 {380 return $this->unsupported;381 }382 /**383 * @param array $unsupported384 * @return TestCase385 */386 public function setUnsupported(array $unsupported): TestCase...

Full Screen

Full Screen

TestSuiteTest.php

Source:TestSuiteTest.php Github

copy

Full Screen

...226 }227 public function testNormalizeRequiredDependencies(): void228 {229 $suite = new TestSuite(MultiDependencyTest::class);230 $this->assertSame([], $suite->requires());231 }232 public function testDetectMissingDependenciesBetweenTestSuites(): void233 {234 $suite = new TestSuite(DependencyOnClassTest::class);235 $this->assertEquals([236 DependencyOnClassTest::class . '::class',237 DependencyOnClassTest::class . '::testThatDependsOnASuccessfulClass',238 DependencyOnClassTest::class . '::testThatDependsOnAFailingClass',239 ], $suite->provides(), 'Provided test names incorrect');240 $this->assertEquals([241 DependencySuccessTest::class . '::class',242 DependencyFailureTest::class . '::class',243 ], $suite->requires(), 'Required test names incorrect');244 }245 public function testResolveDependenciesBetweenTestSuites(): void246 {247 $suite = new TestSuite(DependencyOnClassTest::class);248 $suite->addTestSuite(DependencyFailureTest::class);249 $suite->addTestSuite(DependencySuccessTest::class);250 $this->assertEquals([251 DependencyOnClassTest::class . '::class',252 DependencyOnClassTest::class . '::testThatDependsOnASuccessfulClass',253 DependencyOnClassTest::class . '::testThatDependsOnAFailingClass',254 DependencyFailureTest::class . '::class',255 DependencyFailureTest::class . '::testOne',256 DependencyFailureTest::class . '::testTwo',257 DependencyFailureTest::class . '::testThree',258 DependencyFailureTest::class . '::testFour',259 DependencyFailureTest::class . '::testHandlesDependsAnnotationForNonexistentTests',260 DependencyFailureTest::class . '::testHandlesDependsAnnotationWithNoMethodSpecified',261 DependencySuccessTest::class . '::class',262 DependencySuccessTest::class . '::testOne',263 DependencySuccessTest::class . '::testTwo',264 DependencySuccessTest::class . '::testThree',265 ], $suite->provides(), 'Provided test names incorrect');266 $this->assertEquals([267 DependencyFailureTest::class . '::doesNotExist',268 ], $suite->requires(), 'Required test names incorrect');269 }270 public function testResolverOnlyUsesSuitesAndCases(): void271 {272 $suite = new TestSuite('SomeName');273 $suite->addTest(new DoubleTestCase(new Success));274 $suite->addTestSuite(new TestSuite(DependencyOnClassTest::class));275 $this->assertEquals([276 'SomeName::class',277 DependencyOnClassTest::class . '::class',278 DependencyOnClassTest::class . '::testThatDependsOnASuccessfulClass',279 DependencyOnClassTest::class . '::testThatDependsOnAFailingClass',280 ], $suite->provides(), 'Provided test names incorrect');281 $this->assertEquals([282 DependencySuccessTest::class . '::class',283 DependencyFailureTest::class . '::class',284 ], $suite->requires(), 'Required test names incorrect');285 }286}...

Full Screen

Full Screen

TestSuite.php

Source:TestSuite.php Github

copy

Full Screen

...37 private array $provides;38 /**39 * @psalm-var list<ExecutionOrderDependency>40 */41 private array $requires;42 private string $sortId;43 private TestCollection $tests;44 /**45 * @psalm-var list<string>46 */47 private array $warnings;48 public static function fromTestSuite(FrameworkTestSuite $testSuite): self49 {50 $groups = [];51 foreach ($testSuite->getGroupDetails() as $groupName => $tests) {52 if (!isset($groups[$groupName])) {53 $groups[$groupName] = [];54 }55 foreach ($tests as $test) {56 $groups[$groupName][] = get_class($test);57 }58 }59 $tests = [];60 foreach ($testSuite->tests() as $test) {61 if ($test instanceof TestCase || $test instanceof PhptTestCase) {62 $tests[] = $test->valueObjectForEvents();63 }64 }65 if ($testSuite instanceof DataProviderTestSuite) {66 [$className, $methodName] = explode('::', $testSuite->getName());67 try {68 $reflector = new ReflectionMethod($className, $methodName);69 return new TestSuiteForTestMethodWithDataProvider(70 $testSuite->getName(),71 $testSuite->count(),72 $groups,73 $testSuite->provides(),74 $testSuite->requires(),75 $testSuite->sortId(),76 TestCollection::fromArray($tests),77 $testSuite->warnings(),78 $className,79 $methodName,80 $reflector->getFileName(),81 $reflector->getStartLine(),82 );83 // @codeCoverageIgnoreStart84 } catch (ReflectionException $e) {85 throw new Exception(86 $e->getMessage(),87 (int) $e->getCode(),88 $e89 );90 }91 // @codeCoverageIgnoreEnd92 }93 if (class_exists($testSuite->getName())) {94 try {95 $reflector = new ReflectionClass($testSuite->getName());96 return new TestSuiteForTestClass(97 $testSuite->getName(),98 $testSuite->count(),99 $groups,100 $testSuite->provides(),101 $testSuite->requires(),102 $testSuite->sortId(),103 TestCollection::fromArray($tests),104 $testSuite->warnings(),105 $reflector->getFileName(),106 $reflector->getStartLine(),107 );108 // @codeCoverageIgnoreStart109 } catch (ReflectionException $e) {110 throw new Exception(111 $e->getMessage(),112 (int) $e->getCode(),113 $e114 );115 }116 // @codeCoverageIgnoreEnd117 }118 return new TestSuiteWithName(119 $testSuite->getName(),120 $testSuite->count(),121 $groups,122 $testSuite->provides(),123 $testSuite->requires(),124 $testSuite->sortId(),125 TestCollection::fromArray($tests),126 $testSuite->warnings(),127 );128 }129 public function __construct(string $name, int $size, array $groups, array $provides, array $requires, string $sortId, TestCollection $tests, array $warnings)130 {131 $this->name = $name;132 $this->count = $size;133 $this->groups = $groups;134 $this->provides = $provides;135 $this->requires = $requires;136 $this->sortId = $sortId;137 $this->tests = $tests;138 $this->warnings = $warnings;139 }140 public function name(): string141 {142 return $this->name;143 }144 public function count(): int145 {146 return $this->count;147 }148 /**149 * @psalm-return array<string, list<class-string>>150 */151 public function groups(): array152 {153 return $this->groups;154 }155 /**156 * @psalm-return list<ExecutionOrderDependency>157 */158 public function provides(): array159 {160 return $this->provides;161 }162 /**163 * @psalm-return list<ExecutionOrderDependency>164 */165 public function requires(): array166 {167 return $this->requires;168 }169 public function sortId(): string170 {171 return $this->sortId;172 }173 public function tests(): TestCollection174 {175 return $this->tests;176 }177 public function warnings(): array178 {179 return $this->warnings;180 }181 /**...

Full Screen

Full Screen

SubtopicTest.php

Source:SubtopicTest.php Github

copy

Full Screen

...34 ->assertStatus(200)35 ->assertJson(fn(AssertableJson $json) => $json36 ->has('data', fn($json) => $this->assertJsonIsSubtopic($json)));37 }38 public function test_creating_resource_requires_authentication()39 {40 $resource = Subtopic::factory()->makeOne()->toArray();41 $response = self::postJson(route('api.topics.subtopics.store', ['topic' => $this->topic]), $resource);42 $response->assertUnauthorized();43 self::assertCount(0, Subtopic::all(), 'Failed asserting that resource was not created');44 }45 /** @depends test_creating_resource_requires_authentication */46 public function test_creating_resource()47 {48 $token = $this->user->createToken('testsuite')->plainTextToken;49 $resource = Subtopic::factory()->makeOne();50 self::assertEmpty(Subtopic::all(), 'Failed asserting that test environment has no topics generated.');51 $response = self::withToken($token)52 ->postJson(route('api.topics.subtopics.store', ['topic' => $this->topic]), $resource->toArray());53 $response->assertCreated();54 self::assertCount(1, Subtopic::all(), 'Failed asserting that resource was created');55 }56 public function test_updating_resource_requires_authentication()57 {58 $resource = Subtopic::factory()->create([], $this->topic);59 $response = self::putJson(route('api.subtopics.update', ['subtopic' => $resource]), [60 'name' => 'Updated name',61 ]);62 $response->assertUnauthorized();63 self::assertSame($resource, $resource->refresh(), 'Failed asserting that resource was not updated');64 }65 /** @depends test_updating_resource_requires_authentication */66 public function test_updating_resource()67 {68 $resource = Subtopic::factory()->create([], $this->topic);69 $token = $this->user->createToken('testsuite')->plainTextToken;70 $response = self::withToken($token)->putJson(route('api.subtopics.update', ['subtopic' => $resource]), [71 'name' => 'Updated name',72 ]);73 $response->assertStatus(200)->assertJson(['data' => ['name' => 'Updated name']]);74 self::assertEquals('Updated name', $resource->refresh()->name, 'Failed asserting that resource was updated');75 }76 /** @depends test_updating_resource_requires_authentication */77 public function test_updating_resource_fails_if_not_owner()78 {79 $resource = Subtopic::factory()->create([], $this->topic);80 $token = User::factory()->create()->createToken('testsuite')->plainTextToken;81 $response = self::withToken($token)->putJson(route('api.subtopics.update', ['subtopic' => $resource]), [82 'name' => 'Updated name',83 ]);84 $response->assertForbidden();85 self::assertSame($resource, $resource->refresh(), 'Failed asserting that resource was not updated');86 }87 public function test_deleting_resource_requires_authentication()88 {89 $resource = Subtopic::factory()->create([], $this->topic);90 $response = self::deleteJson(route('api.subtopics.destroy', ['subtopic' => $resource]));91 $response->assertUnauthorized();92 self::assertCount(1, Subtopic::all(), 'Failed asserting that resource was not deleted');93 }94 /** @depends test_deleting_resource_requires_authentication */95 public function test_deleting_resource()96 {97 $resource = Subtopic::factory()->create([], $this->topic);98 $token = $this->user->createToken('testsuite')->plainTextToken;99 $response = self::withToken($token)->deleteJson(route('api.subtopics.destroy', ['subtopic' => $resource]));100 $response->assertStatus(200);101 self::assertCount(0, Subtopic::all(), 'Failed asserting that resource was deleted');102 }103 /** @depends test_deleting_resource_requires_authentication */104 public function test_deleting_resource_fails_if_not_owner()105 {106 $resource = Subtopic::factory()->create([], $this->topic);107 $token = User::factory()->create()->createToken('testsuite')->plainTextToken;108 $response = self::withToken($token)->deleteJson(route('api.subtopics.destroy', ['subtopic' => $resource]));109 $response->assertForbidden();110 self::assertCount(1, Subtopic::all(), 'Failed asserting that resource was not deleted');111 }112 protected function setUp(): void113 {114 parent::setUp();115 $this->user = User::factory()->create();116 $this->episode = Episode::factory()->create([], $this->user);117 $this->topic = Topic::factory()->create([], $this->episode);...

Full Screen

Full Screen

TopicTest.php

Source:TopicTest.php Github

copy

Full Screen

...33 ->assertStatus(200)34 ->assertJson(fn(AssertableJson $json) => $json35 ->has('data', fn($json) => $this->assertJsonIsTopic($json)));36 }37 public function test_creating_resource_requires_authentication()38 {39 $topic = Topic::factory()->newModel()->toArray();40 $response = self::postJson(route('api.episodes.topics.store', ['episode' => $this->episode]), $topic);41 $response->assertUnauthorized();42 self::assertCount(0, Topic::all(), 'Failed asserting that resource was not created');43 }44 /** @depends test_creating_resource_requires_authentication */45 public function test_creating_resource()46 {47 $token = $this->user->createToken('testsuite')->plainTextToken;48 $topic = Topic::factory()->makeOne();49 self::assertEmpty(Topic::all(), 'Failed asserting that test environment has no topics generated.');50 $response = self::withToken($token)51 ->postJson(route('api.episodes.topics.store', ['episode' => $this->episode]), $topic->toArray());52 $response->assertCreated();53 self::assertCount(1, Topic::all(), 'Failed asserting that resource was created');54 }55 public function test_updating_resource_requires_authentication()56 {57 $topic = Topic::factory()->create([], $this->episode);58 $response = self::putJson(route('api.topics.update', ['topic' => $topic]), [59 'name' => 'Updated topic name',60 ]);61 $response->assertUnauthorized();62 self::assertSame($topic, $topic->refresh(), 'Failed asserting that resource was not updated');63 }64 /** @depends test_updating_resource_requires_authentication */65 public function test_updating_resource()66 {67 $topic = Topic::factory()->create([], $this->episode);68 $token = $this->user->createToken('testsuite')->plainTextToken;69 $response = self::withToken($token)->putJson(route('api.topics.update', ['topic' => $topic]), [70 'name' => 'Updated topic name',71 ]);72 $response->assertStatus(200)->assertJson(['data' => ['name' => 'Updated topic name']]);73 self::assertEquals('Updated topic name', $topic->refresh()->name, 'Failed asserting that resource was updated');74 }75 /** @depends test_updating_resource_requires_authentication */76 public function test_updating_resource_fails_if_not_owner()77 {78 $topic = Topic::factory()->create([], $this->episode);79 $token = User::factory()->create()->createToken('testsuite')->plainTextToken;80 $response = self::withToken($token)->putJson(route('api.topics.update', ['topic' => $topic]), [81 'name' => 'Updated topic name',82 ]);83 $response->assertForbidden();84 self::assertSame($topic, $topic->refresh(), 'Failed asserting that resource was not updated');85 }86 public function test_deleting_resource_requires_authentication()87 {88 $topic = Topic::factory()->create([], $this->episode);89 $response = self::deleteJson(route('api.topics.destroy', ['topic' => $topic]));90 $response->assertUnauthorized();91 self::assertCount(1, Topic::all(), 'Failed asserting that resource was not deleted');92 }93 /** @depends test_deleting_resource_requires_authentication */94 public function test_deleting_resource()95 {96 $topic = Topic::factory()->create([], $this->episode);97 $token = $this->user->createToken('testsuite')->plainTextToken;98 $response = self::withToken($token)->deleteJson(route('api.topics.destroy', ['topic' => $topic]));99 $response->assertStatus(200);100 self::assertCount(0, Topic::all(), 'Failed asserting that resource was deleted');101 }102 /** @depends test_deleting_resource_requires_authentication */103 public function test_deleting_resource_fails_if_not_owner()104 {105 $topic = Topic::factory()->create([], $this->episode);106 $token = User::factory()->create()->createToken('testsuite')->plainTextToken;107 $response = self::withToken($token)->deleteJson(route('api.topics.destroy', ['topic' => $topic]));108 $response->assertStatus(403);109 self::assertCount(1, Topic::all(), 'Failed asserting that resource was not deleted');110 }111 protected function setUp(): void112 {113 parent::setUp();114 $this->faker = new Generator();115 $this->user = User::factory()->create();116 $this->episode = Episode::factory()->create([], $this->user);...

Full Screen

Full Screen

JUnitOutputPrinter.php

Source:JUnitOutputPrinter.php Github

copy

Full Screen

...50 * @param array $testsuitesAttributes Attributes for the root element51 */52 public function createNewFile($name, array $testsuitesAttributes = array())53 {54 // This requires the DOM extension to be enabled.55 if (!extension_loaded('dom')) {56 throw new MissingExtensionException('The PHP DOM extension is required to generate JUnit reports.');57 }58 $this->setFileName(strtolower(trim(preg_replace('/[^[:alnum:]_]+/', '_', $name), '_')));59 $this->domDocument = new \DOMDocument(self::XML_VERSION, self::XML_ENCODING);60 $this->domDocument->formatOutput = true;61 $this->testSuites = $this->domDocument->createElement('testsuites');62 $this->domDocument->appendChild($this->testSuites);63 $this->addAttributesToNode($this->testSuites, array_merge(array('name' => $name), $testsuitesAttributes));64 $this->flush();65 }66 /**67 * Adds a new <testsuite> node.68 *...

Full Screen

Full Screen

HostTest.php

Source:HostTest.php Github

copy

Full Screen

...33 ->assertStatus(200)34 ->assertJson(fn(AssertableJson $json) => $json35 ->has('data', fn($json) => $this->assertJsonIsHost($json)));36 }37 public function test_creating_resource_requires_authentication()38 {39 $resource = Host::factory()->makeOne()->toArray();40 $response = self::postJson(route('api.hosts.store', ['episode' => $this->episode]), $resource);41 $response->assertUnauthorized();42 self::assertCount(0, Host::all(), 'Failed asserting that resource was not created');43 }44 /** @depends test_creating_resource_requires_authentication */45 public function test_creating_resource()46 {47 $token = $this->user->createToken('testsuite')->plainTextToken;48 $resource = Host::factory()->makeOne();49 self::assertEmpty(Host::all(), 'Failed asserting that test environment has no topics generated.');50 $response = self::withToken($token)51 ->postJson(route('api.hosts.store', ['episode' => $this->episode]), $resource->toArray());52 $response->assertCreated();53 self::assertCount(1, Host::all(), 'Failed asserting that resource was created');54 }55 public function test_updating_resource_requires_authentication()56 {57 $resource = Host::factory()->create([], $this->user);58 $response = self::putJson(route('api.hosts.update', ['host' => $resource]), [59 'name' => 'Updated name',60 ]);61 $response->assertUnauthorized();62 self::assertSame($resource, $resource->refresh(), 'Failed asserting that resource was not updated');63 }64 /** @depends test_updating_resource_requires_authentication */65 public function test_updating_resource_fails_for_standard_users()66 {67 $resource = Host::factory()->create([], $this->user);68 $token = $this->user->createToken('testsuite')->plainTextToken;69 $response = self::withToken($token)->putJson(route('api.hosts.update', ['host' => $resource]), [70 'name' => 'Updated name',71 ]);72 $response->assertForbidden();73 self::assertSame($resource, $resource->refresh(), 'Failed asserting that resource was not updated');74 }75 public function test_deleting_resource_requires_authentication()76 {77 $resource = Host::factory()->create([], $this->user);78 $response = self::deleteJson(route('api.hosts.destroy', ['host' => $resource]));79 $response->assertUnauthorized();80 self::assertCount(1, Host::all(), 'Failed asserting that resource was not deleted');81 }82 /** @depends test_deleting_resource_requires_authentication */83 public function test_deleting_resource()84 {85 $resource = Host::factory()->create([], $this->user);86 $token = $this->user->createToken('testsuite')->plainTextToken;87 $response = self::withToken($token)->deleteJson(route('api.hosts.destroy', ['host' => $resource]));88 $response->assertForbidden();89 self::assertCount(1, Host::all(), 'Failed asserting that resource was not deleted');90 }91 protected function setUp(): void92 {93 parent::setUp();94 $this->episode = Episode::factory()->create();95 $this->user = User::factory()->create();96 }...

Full Screen

Full Screen

TestCaseBeforeAllPrototype.php

Source:TestCaseBeforeAllPrototype.php Github

copy

Full Screen

1<?php declare(strict_types=1);2namespace Cspray\Labrador\AsyncUnit\Prototype;3use Amp\Coroutine;4use Amp\Promise;5use Cspray\Labrador\AsyncUnit\Attribute\BeforeAll;6use Cspray\Labrador\AsyncUnit\Attribute\Prototype;7use Cspray\Labrador\AsyncUnit\Attribute\PrototypeRequiresAttribute;8use Cspray\Labrador\AsyncUnit\TestCase;9use Cspray\Labrador\AsyncUnit\TestSuite;10#[Prototype([TestCase::class])]11#[PrototypeRequiresAttribute(BeforeAll::class)]12interface TestCaseBeforeAllPrototype {13 public static function beforeAll(TestSuite $testSuite) : Promise|\Generator|Coroutine|null;14}...

Full Screen

Full Screen

requires

Using AI Code Generation

copy

Full Screen

1require_once 'simpletest/autorun.php';2require_once 'simpletest/unit_tester.php';3require_once 'simpletest/web_tester.php';4class TestOfMyFirstUnitTestCase extends UnitTestCase {5 function testTrueIsTrue() {6 $this->assertTrue(true);7 }8}9class TestOfMyFirstWebTestCase extends WebTestCase {10 function testGoogle() {11 $this->assertResponse(200);12 $this->assertText('Google');13 }14}15class TestOfMyFirstTestSuite extends TestSuite {16 function __construct() {17 parent::__construct();18 $this->addFile('1.php');19 $this->addFile('2.php');20 $this->addFile('3.php');21 }22}23class TestOfMySecondUnitTestCase extends UnitTestCase {24 function testTrueIsTrue() {25 $this->assertTrue(true);26 }27}28class TestOfMySecondWebTestCase extends WebTestCase {29 function testGoogle() {30 $this->assertResponse(200);31 $this->assertText('Google');32 }33}34class TestOfMySecondTestSuite extends TestSuite {35 function __construct() {36 parent::__construct();37 $this->addFile('1.php');38 $this->addFile('2.php');39 $this->addFile('3.php');40 }41}42class TestOfMyThirdUnitTestCase extends UnitTestCase {43 function testTrueIsTrue() {44 $this->assertTrue(true);45 }46}47class TestOfMyThirdWebTestCase extends WebTestCase {48 function testGoogle() {49 $this->assertResponse(200);50 $this->assertText('Google');51 }52}53class TestOfMyThirdTestSuite extends TestSuite {54 function __construct() {55 parent::__construct();56 $this->addFile('1.php');57 $this->addFile('2.php');58 $this->addFile('3.php');59 }60}61class TestOfMyFourthUnitTestCase extends UnitTestCase {62 function testTrueIsTrue() {63 $this->assertTrue(true);64 }65}

Full Screen

Full Screen

requires

Using AI Code Generation

copy

Full Screen

1require_once('TestSuite.php');2require_once('TestResult.php');3require_once('Test.php');4require_once('TestCase.php');5require_once('TestSuite.php');6require_once('TestResult.php');7require_once('Test.php');8require_once('TestCase.php');9require_once('TestSuite.php');10require_once('TestResult.php');11require_once('Test.php');12require_once('TestCase.php');13require_once('TestSuite.php');14require_once('TestResult.php');15require_once('Test.php');16require_once('TestCase.php');17require_once('TestSuite.php');18require_once('TestResult.php');19require_once('Test.php');20require_once('TestCase.php');21require_once('TestSuite.php');22require_once('TestResult.php');23require_once('Test.php');24require_once('TestCase.php');25require_once('TestSuite.php');26require_once('TestResult.php');27require_once('Test.php');28require_once('TestCase.php');29require_once('TestSuite.php');30require_once('Test

Full Screen

Full Screen

requires

Using AI Code Generation

copy

Full Screen

1require_once('simpletest/unit_tester.php');2require_once('simpletest/reporter.php');3require_once('simpletest/mock_objects.php');4class MockTestCase extends UnitTestCase {5 function testMock() {6 $mock = &new MockMyClass();7 $mock->expectOnce('myMethod');8 $mock->myMethod();9 $mock->tally();10 }11}12class MyTestCase extends UnitTestCase {13 function testMock() {14 $mock = &new MockMyClass();15 $mock->expectOnce('myMethod');16 $mock->myMethod();17 $mock->tally();18 }19}20class MyTestCase extends UnitTestCase {21 function testMock() {22 $mock = &new MockMyClass();23 $mock->expectOnce('myMethod');24 $mock->myMethod();25 $mock->tally();26 }27}28class MyTestCase extends UnitTestCase {29 function testMock() {30 $mock = &new MockMyClass();31 $mock->expectOnce('myMethod');32 $mock->myMethod();33 $mock->tally();34 }35}36class MyTestCase extends UnitTestCase {37 function testMock() {38 $mock = &new MockMyClass();39 $mock->expectOnce('myMethod');40 $mock->myMethod();41 $mock->tally();42 }43}44class MyTestCase extends UnitTestCase {45 function testMock() {46 $mock = &new MockMyClass();47 $mock->expectOnce('myMethod');48 $mock->myMethod();49 $mock->tally();50 }51}52class MyTestCase extends UnitTestCase {53 function testMock() {54 $mock = &new MockMyClass();55 $mock->expectOnce('myMethod');56 $mock->myMethod();57 $mock->tally();58 }59}

Full Screen

Full Screen

requires

Using AI Code Generation

copy

Full Screen

1require('TestSuite.php');2$testSuite = new TestSuite();3$testSuite->addTestFile('test1.php');4$testSuite->addTestFile('test2.php');5$testSuite->addTestFile('test3.php');6$testSuite->run(new HtmlReporter());

Full Screen

Full Screen

requires

Using AI Code Generation

copy

Full Screen

1require_once 'simpletest/unit_tester.php';2require_once 'simpletest/reporter.php';3require_once 'simpletest/mock_objects.php';4require_once 'simpletest/collector.php';5require_once 'simpletest/web_tester.php';6require_once 'simpletest/autorun.php';7require_once 'simpletest/mock_objects.php';8require_once 'simpletest/expectation.php';9require_once 'simpletest/compatibility.php';10require_once 'simpletest/extensions/phpunit.php';11require_once 'simpletest/extensions/pear_test_case.php';12require_once 'simpletest/extensions/parameterized_test.php';13require_once 'simpletest/extensions/parameterized_test_case.php';14require_once 'simpletest/extensions/recorder.php';15require_once 'simpletest/extensions/testdox.php';16require_once 'simpletest/extensions/testdox_cli_reporter.php';17require_once 'simpletest/extensions/testdox_html_reporter.php';18require_once 'simpletest/extensions/testdox_text_reporter.php';19require_once 'simpletest/extensions/testdox_xml_reporter.php';20require_once 'simpletest/extensions/testdox_result_printer.php';21require_once 'simpletest/extensions/testdox_result_to_output.php';22require_once 'simpletest/extensions/testdox_result_to_test.php';23require_once 'simpletest/extensions/testdox_test_case.php';24require_once 'simpletest/extensions/testdox_test_suite.php';25require_once 'simpletest/extensions/testdox_test_dox.php';26require_once 'simpletest/extensions/testdox_test_dox_group.php';27require_once 'simpletest/extensions/testdox_test_dox_name.php';28require_once 'simpletest/extensions/testdox_test_dox_name_group.php';29require_once 'simpletest/extensions/testdox_test_dox_comment.php';30require_once 'simpletest/extensions/testdox_test_dox_comment_group.php';31require_once 'simpletest/extensions/testdox_test_dox_comment_test.php';32require_once 'simpletest/extensions/testdox_test_dox_group_test.php';33require_once 'simpletest/extensions/testdox_test_dox_name_group_test.php';34require_once 'simpletest/extensions/testdox_test_dox_name_test.php';35require_once 'simpletest/extensions/testdox_test_dox_test.php';36require_once 'simpletest/extensions/testdox_test_dox_test_result.php';37require_once 'simpletest/extensions/testdox_test_dox_test_result_group.php';

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 requires code on LambdaTest Cloud Grid

Execute automation tests with requires 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