Skip to content

Commit 92a7684

Browse files
authored
fix nested steps (fixes #116, via #115)
1 parent 8855689 commit 92a7684

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
"allure-framework/allure-php-commons": "^2"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "^9",
30+
"phpunit/phpunit": "^9.5",
3131
"psalm/plugin-phpunit": "^0.18.4",
3232
"remorhaz/php-json-data": "^0.5.3",
3333
"remorhaz/php-json-path": "^0.7.7",
34-
"squizlabs/php_codesniffer": "^3.7.1",
35-
"vimeo/psalm": "^5.2"
34+
"squizlabs/php_codesniffer": "^3.7.2",
35+
"vimeo/psalm": "^5.12"
3636
},
3737
"autoload": {
3838
"psr-4": {

src/Internal/TestLifecycle.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,8 @@ private function buildHistoryId(string $testCaseId, TestInfo $testInfo, Paramete
297297

298298
public function startStep(Step $step): self
299299
{
300-
$parent = $this->currentStepStart?->getUuid() ?? $this->currentTestStart?->getTestUuid();
301300
$stepResult = $this->resultFactory->createStep();
302-
$this->lifecycle->startStep($stepResult, $parent);
301+
$this->lifecycle->startStep($stepResult);
303302

304303
$stepStart = new StepStartInfo(
305304
$step,
@@ -323,6 +322,10 @@ public function stopStep(): self
323322
{
324323
$stepStart = $this->getCurrentStepStart();
325324
$this->lifecycle->stopStep($stepStart->getUuid());
325+
/**
326+
* @psalm-var Step $step
327+
* @psalm-var StepStartInfo $storedStart
328+
*/
326329
foreach ($this->stepStarts as $step => $storedStart) {
327330
if ($storedStart === $stepStart) {
328331
unset($this->stepStarts[$step]);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Qameta\Allure\Codeception\Test\Functional;
6+
7+
use Qameta\Allure\Allure;
8+
use Qameta\Allure\Attribute\DisplayName;
9+
use Qameta\Allure\Codeception\Test\FunctionalTester;
10+
11+
#[DisplayName('Nested steps')]
12+
class NestedStepsCest
13+
{
14+
public function makeNestedSteps(FunctionalTester $I): void
15+
{
16+
Allure::runStep(
17+
function () use ($I): void {
18+
$I->expect("condition 1");
19+
Allure::runStep(
20+
function () use ($I): void {
21+
$I->expect("condition 1.1");
22+
Allure::runStep(
23+
function () use ($I): void {
24+
$I->expect("condition 1.1.1");
25+
},
26+
'Step 1.1.1',
27+
);
28+
},
29+
'Step 1.1',
30+
);
31+
Allure::runStep(
32+
function () use ($I): void {
33+
$I->expect("condition 1.2");
34+
},
35+
'Step 1.2',
36+
);
37+
},
38+
'Step 1',
39+
);
40+
}
41+
}

test/report/ReportTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Qameta\Allure\Codeception\Test;
66

77
use PHPUnit\Framework\TestCase;
8+
use Qameta\Allure\Codeception\Test\Functional\NestedStepsCest;
89
use Qameta\Allure\Codeception\Test\Unit\AnnotationTest;
910
use Qameta\Allure\Codeception\Test\Unit\StepsTest;
1011
use Remorhaz\JSON\Data\Value\EncodedJson\NodeValueFactory;
@@ -323,6 +324,36 @@ public function providerExistingNodeValue(): iterable
323324
'$.steps[*].name',
324325
['step 1 name', 'step 2 name'],
325326
],
327+
'Nested steps: root names' => [
328+
NestedStepsCest::class,
329+
'makeNestedSteps',
330+
'$.steps[*].name',
331+
['Step 1'],
332+
],
333+
'Nested steps: level 1 names' => [
334+
NestedStepsCest::class,
335+
'makeNestedSteps',
336+
'$.steps[?(@.name=="Step 1")].steps[*].name',
337+
['i expect condition 1', 'Step 1.1', 'Step 1.2'],
338+
],
339+
'Nested steps: level 1.1 names' => [
340+
NestedStepsCest::class,
341+
'makeNestedSteps',
342+
'$.steps..steps[?(@.name=="Step 1.1")].steps[*].name',
343+
['i expect condition 1.1', 'Step 1.1.1'],
344+
],
345+
'Nested steps: level 1.1.1 names' => [
346+
NestedStepsCest::class,
347+
'makeNestedSteps',
348+
'$.steps..steps[?(@.name=="Step 1.1.1")].steps[*].name',
349+
['i expect condition 1.1.1'],
350+
],
351+
'Nested steps: level 1.2 names' => [
352+
NestedStepsCest::class,
353+
'makeNestedSteps',
354+
'$.steps..steps[?(@.name=="Step 1.2")].steps[*].name',
355+
['i expect condition 1.2'],
356+
],
326357
];
327358
}
328359

0 commit comments

Comments
 (0)