From 92a7684f32ab5ebb34056505f6738eda1efc7819 Mon Sep 17 00:00:00 2001 From: Edward Surov Date: Tue, 23 May 2023 14:45:24 +0300 Subject: [PATCH] fix nested steps (fixes #116, via #115) --- composer.json | 6 +-- src/Internal/TestLifecycle.php | 7 +++- .../functional/NestedStepsCest.php | 41 +++++++++++++++++++ test/report/ReportTest.php | 31 ++++++++++++++ 4 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 test/codeception/functional/NestedStepsCest.php diff --git a/composer.json b/composer.json index 5faea3d..5d11539 100644 --- a/composer.json +++ b/composer.json @@ -27,12 +27,12 @@ "allure-framework/allure-php-commons": "^2" }, "require-dev": { - "phpunit/phpunit": "^9", + "phpunit/phpunit": "^9.5", "psalm/plugin-phpunit": "^0.18.4", "remorhaz/php-json-data": "^0.5.3", "remorhaz/php-json-path": "^0.7.7", - "squizlabs/php_codesniffer": "^3.7.1", - "vimeo/psalm": "^5.2" + "squizlabs/php_codesniffer": "^3.7.2", + "vimeo/psalm": "^5.12" }, "autoload": { "psr-4": { diff --git a/src/Internal/TestLifecycle.php b/src/Internal/TestLifecycle.php index 5281234..763b28b 100644 --- a/src/Internal/TestLifecycle.php +++ b/src/Internal/TestLifecycle.php @@ -297,9 +297,8 @@ private function buildHistoryId(string $testCaseId, TestInfo $testInfo, Paramete public function startStep(Step $step): self { - $parent = $this->currentStepStart?->getUuid() ?? $this->currentTestStart?->getTestUuid(); $stepResult = $this->resultFactory->createStep(); - $this->lifecycle->startStep($stepResult, $parent); + $this->lifecycle->startStep($stepResult); $stepStart = new StepStartInfo( $step, @@ -323,6 +322,10 @@ public function stopStep(): self { $stepStart = $this->getCurrentStepStart(); $this->lifecycle->stopStep($stepStart->getUuid()); + /** + * @psalm-var Step $step + * @psalm-var StepStartInfo $storedStart + */ foreach ($this->stepStarts as $step => $storedStart) { if ($storedStart === $stepStart) { unset($this->stepStarts[$step]); diff --git a/test/codeception/functional/NestedStepsCest.php b/test/codeception/functional/NestedStepsCest.php new file mode 100644 index 0000000..618158f --- /dev/null +++ b/test/codeception/functional/NestedStepsCest.php @@ -0,0 +1,41 @@ +expect("condition 1"); + Allure::runStep( + function () use ($I): void { + $I->expect("condition 1.1"); + Allure::runStep( + function () use ($I): void { + $I->expect("condition 1.1.1"); + }, + 'Step 1.1.1', + ); + }, + 'Step 1.1', + ); + Allure::runStep( + function () use ($I): void { + $I->expect("condition 1.2"); + }, + 'Step 1.2', + ); + }, + 'Step 1', + ); + } +} diff --git a/test/report/ReportTest.php b/test/report/ReportTest.php index 3c16800..8be2570 100644 --- a/test/report/ReportTest.php +++ b/test/report/ReportTest.php @@ -5,6 +5,7 @@ namespace Qameta\Allure\Codeception\Test; use PHPUnit\Framework\TestCase; +use Qameta\Allure\Codeception\Test\Functional\NestedStepsCest; use Qameta\Allure\Codeception\Test\Unit\AnnotationTest; use Qameta\Allure\Codeception\Test\Unit\StepsTest; use Remorhaz\JSON\Data\Value\EncodedJson\NodeValueFactory; @@ -323,6 +324,36 @@ public function providerExistingNodeValue(): iterable '$.steps[*].name', ['step 1 name', 'step 2 name'], ], + 'Nested steps: root names' => [ + NestedStepsCest::class, + 'makeNestedSteps', + '$.steps[*].name', + ['Step 1'], + ], + 'Nested steps: level 1 names' => [ + NestedStepsCest::class, + 'makeNestedSteps', + '$.steps[?(@.name=="Step 1")].steps[*].name', + ['i expect condition 1', 'Step 1.1', 'Step 1.2'], + ], + 'Nested steps: level 1.1 names' => [ + NestedStepsCest::class, + 'makeNestedSteps', + '$.steps..steps[?(@.name=="Step 1.1")].steps[*].name', + ['i expect condition 1.1', 'Step 1.1.1'], + ], + 'Nested steps: level 1.1.1 names' => [ + NestedStepsCest::class, + 'makeNestedSteps', + '$.steps..steps[?(@.name=="Step 1.1.1")].steps[*].name', + ['i expect condition 1.1.1'], + ], + 'Nested steps: level 1.2 names' => [ + NestedStepsCest::class, + 'makeNestedSteps', + '$.steps..steps[?(@.name=="Step 1.2")].steps[*].name', + ['i expect condition 1.2'], + ], ]; }