Skip to content

Commit

Permalink
set labels from environment variables (fixes #91, via #117)
Browse files Browse the repository at this point in the history
  • Loading branch information
remorhaz committed May 31, 2023
1 parent 92a7684 commit d28f6ba
Show file tree
Hide file tree
Showing 31 changed files with 179 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -4,6 +4,6 @@ vendor/*
composer.phar
composer.lock
/build/
/test/codeception/_support/_generated/
/test/codeception*/_support/_generated/
.phpunit.result.cache

17 changes: 17 additions & 0 deletions codeception-report.yml
@@ -0,0 +1,17 @@
namespace: Qameta\Allure\Codeception\Test\Report

settings:
lint: true
paths:
tests: test/codeception-report
output: build
support: test/codeception-report/_support
data: test/codeception-report/_data
extensions:
enabled:
- Qameta\Allure\Codeception\AllureCodeception
config:
Qameta\Allure\Codeception\AllureCodeception:
outputDirectory: allure-results
linkTemplates:
issue: https://example.org/issues/%s
8 changes: 0 additions & 8 deletions codeception.yml
Expand Up @@ -7,11 +7,3 @@ paths:
output: build
support: test/codeception/_support
data: test/codeception/_data
extensions:
enabled:
- Qameta\Allure\Codeception\AllureCodeception
config:
Qameta\Allure\Codeception\AllureCodeception:
outputDirectory: allure-results
linkTemplates:
issue: https://example.org/issues/%s
32 changes: 18 additions & 14 deletions composer.json
Expand Up @@ -23,11 +23,10 @@
"require": {
"php": "^8",
"ext-json": "*",
"codeception/codeception": "^5",
"allure-framework/allure-php-commons": "^2"
"codeception/codeception": "^5.0.3",
"allure-framework/allure-php-commons": "^2.3.1"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.18.4",
"remorhaz/php-json-data": "^0.5.3",
"remorhaz/php-json-path": "^0.7.7",
Expand All @@ -41,29 +40,34 @@
},
"autoload-dev": {
"psr-4": {
"Qameta\\Allure\\Codeception\\Test\\Functional\\": "test/codeception/functional/",
"Qameta\\Allure\\Codeception\\Test\\Acceptance\\": "test/codeception/acceptance/",
"Qameta\\Allure\\Codeception\\Test\\Unit\\": "test/codeception/unit/",
"Qameta\\Allure\\Codeception\\Test\\": [
"test/codeception/_support/",
"test/report/"
]
"Qameta\\Allure\\Codeception\\Test\\": "test/codeception/_support/",
"Qameta\\Allure\\Codeception\\Test\\Unit\\": [
"test/codeception/report-check/",
"test/codeception/unit/"
],
"Qameta\\Allure\\Codeception\\Test\\Report\\": "test/codeception-report/_support/",
"Qameta\\Allure\\Codeception\\Test\\Report\\Functional\\": "test/codeception-report/functional/",
"Qameta\\Allure\\Codeception\\Test\\Report\\Acceptance\\": "test/codeception-report/acceptance/",
"Qameta\\Allure\\Codeception\\Test\\Report\\Unit\\": "test/codeception-report/unit/"
}
},
"scripts": {
"build": [
"vendor/bin/codecept build",
"vendor/bin/codecept gherkin:snippets acceptance"
"vendor/bin/codecept build -c codeception-report.yml",
"vendor/bin/codecept gherkin:snippets acceptance -c codeception-report.yml"
],
"test-cs": "vendor/bin/phpcs -sp",
"test-unit": "vendor/bin/codecept run unit --coverage-text",
"test-report-generate": [
"rm -rf ./build/log/",
"vendor/bin/codecept run --no-exit --report"
"rm -rf ./build/allure-results/",
"vendor/bin/codecept run -c codeception-report.yml --no-exit --report"
],
"test-report-check": "vendor/bin/phpunit --testsuite=report",
"test-report-check": "vendor/bin/codecept run report-check",
"test-psalm": "vendor/bin/psalm --shepherd",
"test": [
"@test-cs",
"@test-unit",
"@test-report-generate",
"@test-report-check",
"@test-psalm"
Expand Down
12 changes: 0 additions & 12 deletions phpunit.xml.dist

This file was deleted.

8 changes: 7 additions & 1 deletion psalm.xml.dist
@@ -1,14 +1,20 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedBaselineEntry="true"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<projectFiles>
<directory name="src"/>
<directory name="test/report/"/>
<directory name="test/codeception/"/>
<directory name="test/codeception-report/unit/"/>
<ignoreFiles>
<file name="src/StatusDetector.php" />
<directory name="vendor"/>
<directory name="test/codeception/_support/"/>
<directory name="test/codeception-report/_support/"/>
</ignoreFiles>
</projectFiles>
<plugins>
Expand Down
14 changes: 11 additions & 3 deletions src/AllureCodeception.php
Expand Up @@ -74,7 +74,6 @@ public function moduleInit(): void
$this->testLifecycle = null;
$this->threadDetector = null;
QametaAllure::getLifecycleConfigurator()
->setStatusDetector(new StatusDetector(new DefaultStatusDetector()))
->setOutputDirectory($this->getOutputDirectory());
foreach ($this->getLinkTemplates() as $linkType => $linkTemplate) {
QametaAllure::getLifecycleConfigurator()->addLinkTemplate($linkType, $linkTemplate);
Expand Down Expand Up @@ -191,18 +190,26 @@ public function testError(FailEvent $failEvent): void
$this
->getTestLifecycle()
->switchToTest($failEvent->getTest())
->updateTestFailure($failEvent->getFail());
->updateTestFailure(
$failEvent->getFail(),
Status::broken(),
);
}

/**
* @psalm-suppress MissingDependency
*/
public function testFail(FailEvent $failEvent): void
{
$error = $failEvent->getFail();
$this
->getTestLifecycle()
->switchToTest($failEvent->getTest())
->updateTestFailure($failEvent->getFail(), Status::failed());
->updateTestFailure(
$failEvent->getFail(),
Status::failed(),
new StatusDetails(message: $error->getMessage(), trace: $error->getTraceAsString()),
);
}

/**
Expand Down Expand Up @@ -294,6 +301,7 @@ private function getTestLifecycle(): TestLifecycleInterface
Allure::getConfig()->getStatusDetector(),
$this->getThreadDetector(),
Allure::getConfig()->getLinkTemplates(),
$_ENV,
);
}
}
10 changes: 3 additions & 7 deletions src/Internal/TestLifecycle.php
Expand Up @@ -13,6 +13,7 @@
use Qameta\Allure\AllureLifecycleInterface;
use Qameta\Allure\Codeception\Setup\ThreadDetectorInterface;
use Qameta\Allure\Io\DataSourceFactory;
use Qameta\Allure\Model\EnvProvider;
use Qameta\Allure\Model\ModelProviderChain;
use Qameta\Allure\Model\Parameter;
use Qameta\Allure\Model\ResultFactoryInterface;
Expand Down Expand Up @@ -46,19 +47,13 @@ final class TestLifecycle implements TestLifecycleInterface
*/
private WeakMap $stepStarts;

/**
* @param AllureLifecycleInterface $lifecycle
* @param ResultFactoryInterface $resultFactory
* @param StatusDetectorInterface $statusDetector
* @param ThreadDetectorInterface $threadDetector
* @param LinkTemplateCollectionInterface $linkTemplates
*/
public function __construct(
private AllureLifecycleInterface $lifecycle,
private ResultFactoryInterface $resultFactory,
private StatusDetectorInterface $statusDetector,
private ThreadDetectorInterface $threadDetector,
private LinkTemplateCollectionInterface $linkTemplates,
private array $env,
) {
/** @psalm-var WeakMap<Step, StepStartInfo> $this->stepStarts */
$this->stepStarts = new WeakMap();
Expand Down Expand Up @@ -143,6 +138,7 @@ public function create(): self
public function updateTest(): self
{
$provider = new ModelProviderChain(
new EnvProvider($this->env),
...SuiteProvider::createForChain($this->getCurrentSuite(), $this->linkTemplates),
...TestInfoProvider::createForChain($this->getCurrentTest()),
...$this->createModelProvidersForTest($this->getCurrentTest()->getOriginalTest()),
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/UnitProvider.php
Expand Up @@ -117,6 +117,6 @@ public function getDescriptionHtml(): ?string

public function getFullName(): ?string
{
return null;
return $this->test->getTestCase()::class . '::' . $this->test->getMetadata()->getName();
}
}
4 changes: 4 additions & 0 deletions src/StatusDetector.php
Expand Up @@ -12,6 +12,10 @@
use Qameta\Allure\Setup\StatusDetectorInterface;
use Throwable;

/**
* @deprecated This class is not used anymore and will be removed in next major version.
* @psalm-suppress UnusedClass
*/
final class StatusDetector implements StatusDetectorInterface
{
public function __construct(
Expand Down
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Qameta\Allure\Codeception\Test;
namespace Qameta\Allure\Codeception\Test\Report;

use Behat\Gherkin\Node\TableNode;
use Codeception\Actor;
use PHPUnit\Framework\Assert;
use Codeception\Test\Unit;

use function abs;
use function array_map;
Expand Down Expand Up @@ -62,7 +62,7 @@ private function calculate(): void
*/
public function iShouldGetOutputAs($num)
{
Assert::assertSame([(int) $num], $this->outputs);
Unit::assertSame([(int) $num], $this->outputs);
}

/**
Expand Down Expand Up @@ -92,7 +92,7 @@ public function iHaveInputs(TableNode $table)
public function iShouldGetNonNegativeOutputs()
{
foreach ($this->outputs as $num) {
Assert::assertGreaterThanOrEqual(0, $num);
Unit::assertGreaterThanOrEqual(0, $num);
}
}
}
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Qameta\Allure\Codeception\Test;
namespace Qameta\Allure\Codeception\Test\Report;

use Codeception\Actor;

Expand Down
29 changes: 29 additions & 0 deletions test/codeception-report/_support/UnitTester.php
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Qameta\Allure\Codeception\Test\Report;

/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause($vars = [])
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;

/**
* Define custom actions here
*/
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -5,7 +5,7 @@
namespace Qameta\Allure\Codeception\Test\Functional;

use Codeception\Scenario;
use Qameta\Allure\Codeception\Test\FunctionalTester;
use Qameta\Allure\Codeception\Test\Report\FunctionalTester;

/** @var Scenario $scenario */
$I = new FunctionalTester($scenario);
Expand Down
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace Qameta\Allure\Codeception\Test\Functional;
namespace Qameta\Allure\Codeception\Test\Report\Functional;

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

#[DisplayName('Cest Title')]
class ClassTitleCest
Expand Down
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Qameta\Allure\Codeception\Test\Functional;
namespace Qameta\Allure\Codeception\Test\Report\Functional;

use Codeception\Scenario;
use Qameta\Allure\Allure;
use Qameta\Allure\Codeception\Test\FunctionalTester;
use Qameta\Allure\Codeception\Test\Report\FunctionalTester;

Allure::displayName('Scenario title');
Allure::description('Description with *markdown*');
Expand Down
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Qameta\Allure\Codeception\Test\Functional;
namespace Qameta\Allure\Codeception\Test\Report\Functional;

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

#[DisplayName('Nested steps')]
class NestedStepsCest
Expand Down
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace Qameta\Allure\Codeception\Test\Functional;
namespace Qameta\Allure\Codeception\Test\Report\Functional;

use Codeception\Example;
use Qameta\Allure\Attribute\DisplayName;
use Qameta\Allure\Attribute\Issue;
use Qameta\Allure\Codeception\Test\FunctionalTester;
use Qameta\Allure\Codeception\Test\Report\FunctionalTester;

#[Issue('Issue 1')]
class NoClassTitleCest
Expand Down
Expand Up @@ -10,10 +10,10 @@

declare(strict_types=1);

namespace Qameta\Allure\Codeception\Test\Functional;
namespace Qameta\Allure\Codeception\Test\Report\Functional;

use Codeception\Scenario;
use Qameta\Allure\Codeception\Test\FunctionalTester;
use Qameta\Allure\Codeception\Test\Report\FunctionalTester;

/** @var Scenario $scenario */
$I = new FunctionalTester($scenario);
Expand Down
2 changes: 2 additions & 0 deletions test/codeception-report/unit.suite.yml
@@ -0,0 +1,2 @@

actor: UnitTester
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Qameta\Allure\Codeception\Test\Unit;
namespace Qameta\Allure\Codeception\Test\Report\Unit;

use Codeception\Test\Unit;
use Qameta\Allure\Attribute;
Expand Down

0 comments on commit d28f6ba

Please sign in to comment.