Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested steps #115

Merged
merged 13 commits into from
May 23, 2023
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 5 additions & 2 deletions src/Internal/TestLifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]);
Expand Down
41 changes: 41 additions & 0 deletions test/codeception/functional/NestedStepsCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Qameta\Allure\Codeception\Test\Functional;

use Qameta\Allure\Allure;
use Qameta\Allure\Attribute\DisplayName;
use Qameta\Allure\Codeception\Test\FunctionalTester;

#[DisplayName('Nested steps')]
class NestedStepsCest
{
public function makeNestedSteps(FunctionalTester $I): void
{
Allure::runStep(
function () use ($I): void {
$I->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',
);
}
}
31 changes: 31 additions & 0 deletions test/report/ReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'],
],
];
}

Expand Down