private function generateXML($tmpDir) { AnnotationRegistry::registerAutoloadNamespace('JMS\\Serializer\\Annotation', __DIR__ . "/../../../../vendor/jms/serializer/src"); Model\Provider::setOutputDirectory($tmpDir); Allure::setDefaultLifecycle(); $testSuiteStartedEvent = new TestSuiteStartedEvent(TEST_SUITE_NAME); $uuid = $testSuiteStartedEvent->getUuid(); $testSuiteStartedEvent->setTitle(TEST_SUITE_TITLE); $testSuiteStartedEvent->setDescription(new Description(DescriptionType::HTML, DESCRIPTION)); $testSuiteStartedEvent->setLabels([Label::feature(FEATURE_NAME), Label::story(STORY_NAME)]); Allure::lifecycle()->fire($testSuiteStartedEvent); $testCaseStartedEvent = new TestCaseStartedEvent($uuid, TEST_CASE_NAME); $testCaseStartedEvent->setDescription(new Description(DescriptionType::MARKDOWN, DESCRIPTION)); $testCaseStartedEvent->setLabels([Label::feature(FEATURE_NAME), Label::story(STORY_NAME), Label::severity(SeverityLevel::MINOR)]); $testCaseStartedEvent->setTitle(TEST_CASE_TITLE); $testCaseStartedEvent->setParameters([new Parameter(PARAMETER_NAME, PARAMETER_VALUE, ParameterKind::SYSTEM_PROPERTY)]); Allure::lifecycle()->fire($testCaseStartedEvent); $testCaseFailureEvent = new TestCaseFailedEvent(); $testCaseFailureEvent = $testCaseFailureEvent->withMessage(FAILURE_MESSAGE)->withException(new \Exception()); Allure::lifecycle()->fire($testCaseFailureEvent); $stepStartedEvent = new StepStartedEvent(STEP_NAME); $stepStartedEvent = $stepStartedEvent->withTitle(STEP_TITLE); Allure::lifecycle()->fire($stepStartedEvent); Allure::lifecycle()->fire(new AddAttachmentEvent(STEP_ATTACHMENT_SOURCE, STEP_ATTACHMENT_TITLE, 'text/plain')); Allure::lifecycle()->fire(new StepFinishedEvent()); Allure::lifecycle()->fire(new TestCaseFinishedEvent()); Allure::lifecycle()->fire(new TestSuiteFinishedEvent($uuid)); return $uuid; }
public function testPrepareOutputDirectory() { $rootDirectory = vfsStream::setup(ROOT_DIRECTORY); $this->assertFalse($rootDirectory->hasChild(TEST_DIRECTORY)); $newDirectoryPath = vfsStream::url(ROOT_DIRECTORY) . DIRECTORY_SEPARATOR . TEST_DIRECTORY; Model\Provider::setOutputDirectory(null); new AllureAdapter($newDirectoryPath, true); $this->assertTrue($rootDirectory->hasChild(TEST_DIRECTORY)); $this->assertEquals($newDirectoryPath, Model\Provider::getOutputDirectory()); }
public function testAddAttachment() { $attachmentContents = 'test-contents'; $attachmentCaption = 'test-title'; $attachmentType = 'text/html'; Provider::setOutputDirectory(sys_get_temp_dir()); $this->addAttachment($attachmentContents, $attachmentCaption, $attachmentType); $event = Allure::lifecycle()->getLastEvent(); $this->assertTrue($event instanceof AddAttachmentEvent && $event->getFilePathOrContents() === $attachmentContents && $event->getCaption() === $attachmentCaption && $event->getType() === $attachmentType); }
public function _initialize() { parent::_initialize(); Annotation\AnnotationProvider::registerAnnotationNamespaces(); $outputDirectory = $this->getOutputDirectory(); $deletePreviousResults = $this->tryGetOption(DELETE_PREVIOUS_RESULTS_PARAMETER, false); $this->prepareOutputDirectory($outputDirectory, $deletePreviousResults); if (is_null(Model\Provider::getOutputDirectory())) { Model\Provider::setOutputDirectory($outputDirectory); } }
/** * Extra annotations to ignore in addition to standard PHPUnit annotations. * * @param array $ignoredAnnotations */ public function _initialize(array $ignoredAnnotations = []) { parent::_initialize(); Annotation\AnnotationProvider::registerAnnotationNamespaces(); // Add standard PHPUnit annotations Annotation\AnnotationProvider::addIgnoredAnnotations($this->ignoredAnnotations); // Add custom ignored annotations Annotation\AnnotationProvider::addIgnoredAnnotations($ignoredAnnotations); $outputDirectory = $this->getOutputDirectory(); $deletePreviousResults = $this->tryGetOption(DELETE_PREVIOUS_RESULTS_PARAMETER, false); $this->prepareOutputDirectory($outputDirectory, $deletePreviousResults); if (is_null(Model\Provider::getOutputDirectory())) { Model\Provider::setOutputDirectory($outputDirectory); } }
public function testEventWithStringContents() { $attachmentCaption = self::ATTACHMENT_CAPTION; $attachmentType = 'text/plain'; $correctExtension = 'txt'; $tmpDirectory = sys_get_temp_dir(); Provider::setOutputDirectory($tmpDirectory); $contents = $this->getTestContents(); $sha1Sum = sha1($contents); $event = new AddAttachmentEvent($contents, $attachmentCaption); $step = new Step(); $event->process($step); $attachmentFileName = $event->getOutputFileName($sha1Sum, $correctExtension); $attachmentOutputPath = $event->getOutputPath($sha1Sum, $correctExtension); $this->checkAttachmentIsCorrect($step, $attachmentOutputPath, $attachmentFileName, $attachmentCaption, $attachmentType); }
public function prepareOutputDirectory($outputDirectory, $deletePreviousResults) { if (!file_exists($outputDirectory)) { mkdir($outputDirectory, 0755, true); } if ($deletePreviousResults) { $files = glob($outputDirectory . DIRECTORY_SEPARATOR . '{,.}*', GLOB_BRACE); foreach ($files as $file) { if (is_file($file)) { unlink($file); } } } if (is_null(Model\Provider::getOutputDirectory())) { Model\Provider::setOutputDirectory($outputDirectory); } }
public function testTestSuiteFinishedEvent() { Allure::lifecycle()->getTestSuiteStorage()->clear(); $testSuite = Allure::lifecycle()->getTestSuiteStorage()->get(self::TEST_SUITE_UUID); $testSuite->addTestCase(new TestCase()); $this->assertEquals(1, Allure::lifecycle()->getTestSuiteStorage()->size()); $outputDirectory = sys_get_temp_dir(); AnnotationRegistry::registerAutoloadNamespace('JMS\\Serializer\\Annotation', __DIR__ . "/../../../../vendor/jms/serializer/src"); Provider::setOutputDirectory($outputDirectory); $xmlFilePath = $outputDirectory . DIRECTORY_SEPARATOR . self::TEST_SUITE_UUID . '-testsuite.xml'; Allure::lifecycle()->fire(new TestSuiteFinishedEvent(self::TEST_SUITE_UUID)); $this->assertTrue(Allure::lifecycle()->getTestSuiteStorage()->isEmpty()); $this->assertTrue(file_exists($xmlFilePath)); }
public function getOutputPath($sha1, $extension) { return Provider::getOutputDirectory() . DIRECTORY_SEPARATOR . $this->getOutputFileName($sha1, $extension); }
protected function saveToFile($testSuiteUuid, TestSuite $testSuite) { if ($testSuite->size() > 0) { $xml = $testSuite->serialize(); $fileName = $testSuiteUuid . '-testsuite.xml'; $filePath = Provider::getOutputDirectory() . DIRECTORY_SEPARATOR . $fileName; file_put_contents($filePath, $xml); } }