Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ composer.phar
composer.lock
/build/
/test/codeception*/_support/_generated/
/test/hooks-fixtures/_support/_generated/
.phpunit.result.cache

17 changes: 17 additions & 0 deletions codeception-hooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace: Qameta\Allure\Codeception\Test\Hooks

settings:
lint: true
paths:
tests: test/hooks-fixtures
output: build/hooks-fixtures
support: test/hooks-fixtures/_support
data: test/hooks-fixtures/_data

extensions:
enabled:
- Qameta\Allure\Codeception\AllureCodeception
config:
Qameta\Allure\Codeception\AllureCodeception:
outputDirectory: allure-results-hooks
setupHook: Qameta\Allure\Codeception\Test\Hooks\Setup\OutputDirectoryHook
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@
"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/"
"Qameta\\Allure\\Codeception\\Test\\Report\\Unit\\": "test/codeception-report/unit/",
"Qameta\\Allure\\Codeception\\Test\\Hooks\\": [
"test/hooks-fixtures/_support/",
"test/hooks-fixtures/unit/"
]
}
},
"scripts": {
"build": [
"vendor/bin/codecept build",
"vendor/bin/codecept build -c codeception-report.yml",
"vendor/bin/codecept build -c codeception-hooks.yml",
"vendor/bin/codecept gherkin:snippets acceptance -c codeception-report.yml"
],
"test-cs": "vendor/bin/phpcs -sp",
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<file>test</file>
<exclude-pattern>test/codeception/_support/_generated/*</exclude-pattern>
<exclude-pattern>test/codeception-report/_support/_generated/*</exclude-pattern>
<exclude-pattern>test/hooks-fixtures/_support/_generated/*</exclude-pattern>

<arg name="colors"/>

Expand Down
122 changes: 122 additions & 0 deletions src/AllureAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

declare(strict_types=1);

namespace Qameta\Allure\Codeception;

final class AllureAdapter implements AllureAdapterInterface
{
private static ?AllureAdapterInterface $instance = null;

/**
* @var array<string, string>
*/
private array $suiteContainers = [];

/**
* @var array<string, true>
*/
private array $emittedHookGlobals = [];

/**
* @var array<string, true>
*/
private array $startedTests = [];

private ?string $activeFixtureUuid = null;

private ?string $activeHookName = null;

private function __construct()
{
}

public static function getInstance(): AllureAdapterInterface
{
return self::$instance ??= new self();
}

public static function setInstance(AllureAdapterInterface $instance): void
{
self::$instance = $instance;
}

public static function reset(): void
{
self::$instance = null;
}

#[\Override]
public function setActiveFixture(string $uuid, string $hookName): void
{
$this->activeFixtureUuid = $uuid;
$this->activeHookName = $hookName;
}

#[\Override]
public function getActiveFixtureUuid(): ?string
{
return $this->activeFixtureUuid;
}

#[\Override]
public function getActiveHookName(): ?string
{
return $this->activeHookName;
}

#[\Override]
public function clearActiveFixture(): void
{
$this->activeFixtureUuid = null;
$this->activeHookName = null;
}

#[\Override]
public function hasEmittedHookGlobalError(string $fixtureUuid): bool
{
return isset($this->emittedHookGlobals[$fixtureUuid]);
}

#[\Override]
public function markHookGlobalErrorEmitted(string $fixtureUuid): void
{
$this->emittedHookGlobals[$fixtureUuid] = true;
}

#[\Override]
public function registerSuiteContainer(string $suiteName, string $containerUuid): void
{
$this->suiteContainers[$suiteName] = $containerUuid;
}

#[\Override]
public function getSuiteContainerId(string $suiteName): ?string
{
return $this->suiteContainers[$suiteName] ?? null;
}

#[\Override]
public function clearSuiteContainer(string $suiteName): void
{
unset($this->suiteContainers[$suiteName]);
}

#[\Override]
public function markTestStarted(string $testUuid): void
{
$this->startedTests[$testUuid] = true;
}

#[\Override]
public function wasTestStarted(string $testUuid): bool
{
return isset($this->startedTests[$testUuid]);
}

#[\Override]
public function clearTestStarted(string $testUuid): void
{
unset($this->startedTests[$testUuid]);
}
}
32 changes: 32 additions & 0 deletions src/AllureAdapterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Qameta\Allure\Codeception;

interface AllureAdapterInterface
{
public function setActiveFixture(string $uuid, string $hookName): void;

public function getActiveFixtureUuid(): ?string;

public function getActiveHookName(): ?string;

public function clearActiveFixture(): void;

public function hasEmittedHookGlobalError(string $fixtureUuid): bool;

public function markHookGlobalErrorEmitted(string $fixtureUuid): void;

public function registerSuiteContainer(string $suiteName, string $containerUuid): void;

public function getSuiteContainerId(string $suiteName): ?string;

public function clearSuiteContainer(string $suiteName): void;

public function markTestStarted(string $testUuid): void;

public function wasTestStarted(string $testUuid): bool;

public function clearTestStarted(string $testUuid): void;
}
Loading
Loading