Skip to content

Commit d28f6ba

Browse files
authored
set labels from environment variables (fixes #91, via #117)
1 parent 92a7684 commit d28f6ba

31 files changed

+179
-86
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ vendor/*
44
composer.phar
55
composer.lock
66
/build/
7-
/test/codeception/_support/_generated/
7+
/test/codeception*/_support/_generated/
88
.phpunit.result.cache
99

codeception-report.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace: Qameta\Allure\Codeception\Test\Report
2+
3+
settings:
4+
lint: true
5+
paths:
6+
tests: test/codeception-report
7+
output: build
8+
support: test/codeception-report/_support
9+
data: test/codeception-report/_data
10+
extensions:
11+
enabled:
12+
- Qameta\Allure\Codeception\AllureCodeception
13+
config:
14+
Qameta\Allure\Codeception\AllureCodeception:
15+
outputDirectory: allure-results
16+
linkTemplates:
17+
issue: https://example.org/issues/%s

codeception.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,3 @@ paths:
77
output: build
88
support: test/codeception/_support
99
data: test/codeception/_data
10-
extensions:
11-
enabled:
12-
- Qameta\Allure\Codeception\AllureCodeception
13-
config:
14-
Qameta\Allure\Codeception\AllureCodeception:
15-
outputDirectory: allure-results
16-
linkTemplates:
17-
issue: https://example.org/issues/%s

composer.json

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
"require": {
2424
"php": "^8",
2525
"ext-json": "*",
26-
"codeception/codeception": "^5",
27-
"allure-framework/allure-php-commons": "^2"
26+
"codeception/codeception": "^5.0.3",
27+
"allure-framework/allure-php-commons": "^2.3.1"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "^9.5",
3130
"psalm/plugin-phpunit": "^0.18.4",
3231
"remorhaz/php-json-data": "^0.5.3",
3332
"remorhaz/php-json-path": "^0.7.7",
@@ -41,29 +40,34 @@
4140
},
4241
"autoload-dev": {
4342
"psr-4": {
44-
"Qameta\\Allure\\Codeception\\Test\\Functional\\": "test/codeception/functional/",
45-
"Qameta\\Allure\\Codeception\\Test\\Acceptance\\": "test/codeception/acceptance/",
46-
"Qameta\\Allure\\Codeception\\Test\\Unit\\": "test/codeception/unit/",
47-
"Qameta\\Allure\\Codeception\\Test\\": [
48-
"test/codeception/_support/",
49-
"test/report/"
50-
]
43+
"Qameta\\Allure\\Codeception\\Test\\": "test/codeception/_support/",
44+
"Qameta\\Allure\\Codeception\\Test\\Unit\\": [
45+
"test/codeception/report-check/",
46+
"test/codeception/unit/"
47+
],
48+
"Qameta\\Allure\\Codeception\\Test\\Report\\": "test/codeception-report/_support/",
49+
"Qameta\\Allure\\Codeception\\Test\\Report\\Functional\\": "test/codeception-report/functional/",
50+
"Qameta\\Allure\\Codeception\\Test\\Report\\Acceptance\\": "test/codeception-report/acceptance/",
51+
"Qameta\\Allure\\Codeception\\Test\\Report\\Unit\\": "test/codeception-report/unit/"
5152
}
5253
},
5354
"scripts": {
5455
"build": [
5556
"vendor/bin/codecept build",
56-
"vendor/bin/codecept gherkin:snippets acceptance"
57+
"vendor/bin/codecept build -c codeception-report.yml",
58+
"vendor/bin/codecept gherkin:snippets acceptance -c codeception-report.yml"
5759
],
5860
"test-cs": "vendor/bin/phpcs -sp",
61+
"test-unit": "vendor/bin/codecept run unit --coverage-text",
5962
"test-report-generate": [
60-
"rm -rf ./build/log/",
61-
"vendor/bin/codecept run --no-exit --report"
63+
"rm -rf ./build/allure-results/",
64+
"vendor/bin/codecept run -c codeception-report.yml --no-exit --report"
6265
],
63-
"test-report-check": "vendor/bin/phpunit --testsuite=report",
66+
"test-report-check": "vendor/bin/codecept run report-check",
6467
"test-psalm": "vendor/bin/psalm --shepherd",
6568
"test": [
6669
"@test-cs",
70+
"@test-unit",
6771
"@test-report-generate",
6872
"@test-report-check",
6973
"@test-psalm"

phpunit.xml.dist

Lines changed: 0 additions & 12 deletions
This file was deleted.

psalm.xml.dist

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
<?xml version="1.0"?>
22
<psalm
33
errorLevel="1"
4+
findUnusedBaselineEntry="true"
5+
findUnusedCode="false"
46
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
57
xmlns="https://getpsalm.org/schema/config"
68
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
79
<projectFiles>
810
<directory name="src"/>
9-
<directory name="test/report/"/>
11+
<directory name="test/codeception/"/>
12+
<directory name="test/codeception-report/unit/"/>
1013
<ignoreFiles>
14+
<file name="src/StatusDetector.php" />
1115
<directory name="vendor"/>
16+
<directory name="test/codeception/_support/"/>
17+
<directory name="test/codeception-report/_support/"/>
1218
</ignoreFiles>
1319
</projectFiles>
1420
<plugins>

src/AllureCodeception.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public function moduleInit(): void
7474
$this->testLifecycle = null;
7575
$this->threadDetector = null;
7676
QametaAllure::getLifecycleConfigurator()
77-
->setStatusDetector(new StatusDetector(new DefaultStatusDetector()))
7877
->setOutputDirectory($this->getOutputDirectory());
7978
foreach ($this->getLinkTemplates() as $linkType => $linkTemplate) {
8079
QametaAllure::getLifecycleConfigurator()->addLinkTemplate($linkType, $linkTemplate);
@@ -191,18 +190,26 @@ public function testError(FailEvent $failEvent): void
191190
$this
192191
->getTestLifecycle()
193192
->switchToTest($failEvent->getTest())
194-
->updateTestFailure($failEvent->getFail());
193+
->updateTestFailure(
194+
$failEvent->getFail(),
195+
Status::broken(),
196+
);
195197
}
196198

197199
/**
198200
* @psalm-suppress MissingDependency
199201
*/
200202
public function testFail(FailEvent $failEvent): void
201203
{
204+
$error = $failEvent->getFail();
202205
$this
203206
->getTestLifecycle()
204207
->switchToTest($failEvent->getTest())
205-
->updateTestFailure($failEvent->getFail(), Status::failed());
208+
->updateTestFailure(
209+
$failEvent->getFail(),
210+
Status::failed(),
211+
new StatusDetails(message: $error->getMessage(), trace: $error->getTraceAsString()),
212+
);
206213
}
207214

208215
/**
@@ -294,6 +301,7 @@ private function getTestLifecycle(): TestLifecycleInterface
294301
Allure::getConfig()->getStatusDetector(),
295302
$this->getThreadDetector(),
296303
Allure::getConfig()->getLinkTemplates(),
304+
$_ENV,
297305
);
298306
}
299307
}

src/Internal/TestLifecycle.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Qameta\Allure\AllureLifecycleInterface;
1414
use Qameta\Allure\Codeception\Setup\ThreadDetectorInterface;
1515
use Qameta\Allure\Io\DataSourceFactory;
16+
use Qameta\Allure\Model\EnvProvider;
1617
use Qameta\Allure\Model\ModelProviderChain;
1718
use Qameta\Allure\Model\Parameter;
1819
use Qameta\Allure\Model\ResultFactoryInterface;
@@ -46,19 +47,13 @@ final class TestLifecycle implements TestLifecycleInterface
4647
*/
4748
private WeakMap $stepStarts;
4849

49-
/**
50-
* @param AllureLifecycleInterface $lifecycle
51-
* @param ResultFactoryInterface $resultFactory
52-
* @param StatusDetectorInterface $statusDetector
53-
* @param ThreadDetectorInterface $threadDetector
54-
* @param LinkTemplateCollectionInterface $linkTemplates
55-
*/
5650
public function __construct(
5751
private AllureLifecycleInterface $lifecycle,
5852
private ResultFactoryInterface $resultFactory,
5953
private StatusDetectorInterface $statusDetector,
6054
private ThreadDetectorInterface $threadDetector,
6155
private LinkTemplateCollectionInterface $linkTemplates,
56+
private array $env,
6257
) {
6358
/** @psalm-var WeakMap<Step, StepStartInfo> $this->stepStarts */
6459
$this->stepStarts = new WeakMap();
@@ -143,6 +138,7 @@ public function create(): self
143138
public function updateTest(): self
144139
{
145140
$provider = new ModelProviderChain(
141+
new EnvProvider($this->env),
146142
...SuiteProvider::createForChain($this->getCurrentSuite(), $this->linkTemplates),
147143
...TestInfoProvider::createForChain($this->getCurrentTest()),
148144
...$this->createModelProvidersForTest($this->getCurrentTest()->getOriginalTest()),

src/Internal/UnitProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,6 @@ public function getDescriptionHtml(): ?string
117117

118118
public function getFullName(): ?string
119119
{
120-
return null;
120+
return $this->test->getTestCase()::class . '::' . $this->test->getMetadata()->getName();
121121
}
122122
}

src/StatusDetector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
use Qameta\Allure\Setup\StatusDetectorInterface;
1313
use Throwable;
1414

15+
/**
16+
* @deprecated This class is not used anymore and will be removed in next major version.
17+
* @psalm-suppress UnusedClass
18+
*/
1519
final class StatusDetector implements StatusDetectorInterface
1620
{
1721
public function __construct(

test/codeception/_support/AcceptanceTester.php renamed to test/codeception-report/_support/AcceptanceTester.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
declare(strict_types=1);
44

5-
namespace Qameta\Allure\Codeception\Test;
5+
namespace Qameta\Allure\Codeception\Test\Report;
66

77
use Behat\Gherkin\Node\TableNode;
88
use Codeception\Actor;
9-
use PHPUnit\Framework\Assert;
9+
use Codeception\Test\Unit;
1010

1111
use function abs;
1212
use function array_map;
@@ -62,7 +62,7 @@ private function calculate(): void
6262
*/
6363
public function iShouldGetOutputAs($num)
6464
{
65-
Assert::assertSame([(int) $num], $this->outputs);
65+
Unit::assertSame([(int) $num], $this->outputs);
6666
}
6767

6868
/**
@@ -92,7 +92,7 @@ public function iHaveInputs(TableNode $table)
9292
public function iShouldGetNonNegativeOutputs()
9393
{
9494
foreach ($this->outputs as $num) {
95-
Assert::assertGreaterThanOrEqual(0, $num);
95+
Unit::assertGreaterThanOrEqual(0, $num);
9696
}
9797
}
9898
}

test/codeception/_support/FunctionalTester.php renamed to test/codeception-report/_support/FunctionalTester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Qameta\Allure\Codeception\Test;
5+
namespace Qameta\Allure\Codeception\Test\Report;
66

77
use Codeception\Actor;
88

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Qameta\Allure\Codeception\Test\Report;
6+
7+
/**
8+
* Inherited Methods
9+
* @method void wantToTest($text)
10+
* @method void wantTo($text)
11+
* @method void execute($callable)
12+
* @method void expectTo($prediction)
13+
* @method void expect($prediction)
14+
* @method void amGoingTo($argumentation)
15+
* @method void am($role)
16+
* @method void lookForwardTo($achieveValue)
17+
* @method void comment($description)
18+
* @method void pause($vars = [])
19+
*
20+
* @SuppressWarnings(PHPMD)
21+
*/
22+
class UnitTester extends \Codeception\Actor
23+
{
24+
use _generated\UnitTesterActions;
25+
26+
/**
27+
* Define custom actions here
28+
*/
29+
}

test/codeception/functional/BasicScenarioCept.php renamed to test/codeception-report/functional/BasicScenarioCept.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Qameta\Allure\Codeception\Test\Functional;
66

77
use Codeception\Scenario;
8-
use Qameta\Allure\Codeception\Test\FunctionalTester;
8+
use Qameta\Allure\Codeception\Test\Report\FunctionalTester;
99

1010
/** @var Scenario $scenario */
1111
$I = new FunctionalTester($scenario);

test/codeception/functional/ClassTitleCest.php renamed to test/codeception-report/functional/ClassTitleCest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
declare(strict_types=1);
44

5-
namespace Qameta\Allure\Codeception\Test\Functional;
5+
namespace Qameta\Allure\Codeception\Test\Report\Functional;
66

77
use Qameta\Allure\Attribute\DisplayName;
8-
use Qameta\Allure\Codeception\Test\FunctionalTester;
8+
use Qameta\Allure\Codeception\Test\Report\FunctionalTester;
99

1010
#[DisplayName('Cest Title')]
1111
class ClassTitleCest

test/codeception/functional/CustomizedScenarioCept.php renamed to test/codeception-report/functional/CustomizedScenarioCept.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
declare(strict_types=1);
44

5-
namespace Qameta\Allure\Codeception\Test\Functional;
5+
namespace Qameta\Allure\Codeception\Test\Report\Functional;
66

77
use Codeception\Scenario;
88
use Qameta\Allure\Allure;
9-
use Qameta\Allure\Codeception\Test\FunctionalTester;
9+
use Qameta\Allure\Codeception\Test\Report\FunctionalTester;
1010

1111
Allure::displayName('Scenario title');
1212
Allure::description('Description with *markdown*');

test/codeception/functional/NestedStepsCest.php renamed to test/codeception-report/functional/NestedStepsCest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
declare(strict_types=1);
44

5-
namespace Qameta\Allure\Codeception\Test\Functional;
5+
namespace Qameta\Allure\Codeception\Test\Report\Functional;
66

77
use Qameta\Allure\Allure;
88
use Qameta\Allure\Attribute\DisplayName;
9-
use Qameta\Allure\Codeception\Test\FunctionalTester;
9+
use Qameta\Allure\Codeception\Test\Report\FunctionalTester;
1010

1111
#[DisplayName('Nested steps')]
1212
class NestedStepsCest

test/codeception/functional/NoClassTitleCest.php renamed to test/codeception-report/functional/NoClassTitleCest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace Qameta\Allure\Codeception\Test\Functional;
5+
namespace Qameta\Allure\Codeception\Test\Report\Functional;
66

77
use Codeception\Example;
88
use Qameta\Allure\Attribute\DisplayName;
99
use Qameta\Allure\Attribute\Issue;
10-
use Qameta\Allure\Codeception\Test\FunctionalTester;
10+
use Qameta\Allure\Codeception\Test\Report\FunctionalTester;
1111

1212
#[Issue('Issue 1')]
1313
class NoClassTitleCest

test/codeception/functional/ScenarioWithLegacyAnnotationsCept.php renamed to test/codeception-report/functional/ScenarioWithLegacyAnnotationsCept.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
declare(strict_types=1);
1212

13-
namespace Qameta\Allure\Codeception\Test\Functional;
13+
namespace Qameta\Allure\Codeception\Test\Report\Functional;
1414

1515
use Codeception\Scenario;
16-
use Qameta\Allure\Codeception\Test\FunctionalTester;
16+
use Qameta\Allure\Codeception\Test\Report\FunctionalTester;
1717

1818
/** @var Scenario $scenario */
1919
$I = new FunctionalTester($scenario);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
actor: UnitTester

test/codeception/unit/AnnotationTest.php renamed to test/codeception-report/unit/AnnotationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Qameta\Allure\Codeception\Test\Unit;
5+
namespace Qameta\Allure\Codeception\Test\Report\Unit;
66

77
use Codeception\Test\Unit;
88
use Qameta\Allure\Attribute;

0 commit comments

Comments
 (0)