Skip to content
Merged
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
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
php-version:
- "8.0"
- "8.1"
- "8.2"
os:
- ubuntu-latest
- windows-latest
Expand Down Expand Up @@ -48,10 +49,10 @@ jobs:
${{ matrix.composer-options }}

- name: Run tests
if: ${{ matrix.php-version != '8.1' }}
if: ${{ matrix.php-version != '8.2' }}
run: composer test

- name: Run tests (experimental)
if: ${{ matrix.php-version == '8.1' }}
if: ${{ matrix.php-version == '8.2' }}
continue-on-error: true
run: composer test
11 changes: 4 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,16 @@
"require": {
"php": "^8",
"ext-json": "*",
"codeception/codeception": "^4.1",
"codeception/codeception": "^5",
"allure-framework/allure-php-commons": "^2"
},
"require-dev": {
"phpunit/phpunit": "^9",
"psalm/plugin-phpunit": "^0.16.1",
"psalm/plugin-phpunit": "^0.18.4",
"remorhaz/php-json-data": "^0.5.3",
"remorhaz/php-json-path": "^0.7.7",
"squizlabs/php_codesniffer": "^3.6.2",
"vimeo/psalm": "^4.20"
},
"conflict": {
"codeception/phpunit-wrapper": "<9.0.1"
"squizlabs/php_codesniffer": "^3.7.1",
"vimeo/psalm": "^5.2"
},
"autoload": {
"psr-4": {
Expand Down
33 changes: 13 additions & 20 deletions src/AllureCodeception.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Codeception\Event\TestEvent;
use Codeception\Events;
use Codeception\Exception\ConfigurationException;
use Codeception\Step;
use Qameta\Allure\Allure;
use Qameta\Allure\Allure as QametaAllure;
use Qameta\Allure\Codeception\Internal\DefaultThreadDetector;
Expand All @@ -26,7 +25,6 @@
use Qameta\Allure\Setup\DefaultStatusDetector;
use Qameta\Allure\Setup\LinkTemplate;
use Qameta\Allure\Setup\LinkTemplateInterface;
use Throwable;

use function class_exists;
use function is_a;
Expand All @@ -46,6 +44,7 @@ final class AllureCodeception extends Extension
private const DEFAULT_RESULTS_DIRECTORY = 'allure-results';

protected static array $events = [
Events::MODULE_INIT => 'moduleInit',
Events::SUITE_BEFORE => 'suiteBefore',
Events::SUITE_AFTER => 'suiteAfter',
Events::TEST_START => 'testStart',
Expand All @@ -69,11 +68,11 @@ final class AllureCodeception extends Extension
* @throws ConfigurationException
* phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
*/
public function _initialize(): void
public function moduleInit(): void
{
// phpcs:enable PSR2.Methods.MethodDeclaration.Underscore
parent::_initialize();
QametaAllure::reset();
$this->testLifecycle = null;
$this->threadDetector = null;
QametaAllure::getLifecycleConfigurator()
->setStatusDetector(new StatusDetector(new DefaultStatusDetector()))
->setOutputDirectory($this->getOutputDirectory());
Expand Down Expand Up @@ -148,7 +147,11 @@ class_exists($linkConfig) && is_a($linkConfig, LinkTemplateInterface::class, tru
public function suiteBefore(SuiteEvent $suiteEvent): void
{
/** @psalm-suppress InternalMethod */
$suiteName = $suiteEvent->getSuite()->getName();
$suiteName = $suiteEvent->getSuite()?->getName();
if (!isset($suiteName)) {
return;
}

$this
->getTestLifecycle()
->switchToSuite(new SuiteInfo($suiteName));
Expand Down Expand Up @@ -185,33 +188,28 @@ private function getThreadDetector(): ThreadDetectorInterface
*/
public function testError(FailEvent $failEvent): void
{
/** @var Throwable $error */
$error = $failEvent->getFail();
$this
->getTestLifecycle()
->switchToTest($failEvent->getTest())
->updateTestFailure($error);
->updateTestFailure($failEvent->getFail());
}

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

/**
* @psalm-suppress MissingDependency
*/
public function testIncomplete(FailEvent $failEvent): void
{
/** @var Throwable $error */
$error = $failEvent->getFail();
$this
->getTestLifecycle()
Expand All @@ -228,7 +226,6 @@ public function testIncomplete(FailEvent $failEvent): void
*/
public function testSkipped(FailEvent $failEvent): void
{
/** @var Throwable $error */
$error = $failEvent->getFail();
$this
->getTestLifecycle()
Expand Down Expand Up @@ -269,12 +266,10 @@ public function testEnd(TestEvent $testEvent): void
*/
public function stepBefore(StepEvent $stepEvent): void
{
/** @psalm-var Step $step */
$step = $stepEvent->getStep();
$this
->getTestLifecycle()
->switchToTest($stepEvent->getTest())
->startStep($step)
->startStep($stepEvent->getStep())
->updateStep();
}

Expand All @@ -283,12 +278,10 @@ public function stepBefore(StepEvent $stepEvent): void
*/
public function stepAfter(StepEvent $stepEvent): void
{
/** @psalm-var Step $step */
$step = $stepEvent->getStep();
$this
->getTestLifecycle()
->switchToTest($stepEvent->getTest())
->switchToStep($step)
->switchToStep($stepEvent->getStep())
->updateStepResult()
->stopStep();
}
Expand Down
22 changes: 20 additions & 2 deletions src/Internal/ArgumentAsString.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Qameta\Allure\Codeception\Internal;

use Codeception\Util\Locator;
use InvalidArgumentException;
use Stringable;

use function array_map;
Expand All @@ -15,6 +15,7 @@
use function is_resource;
use function is_string;
use function json_encode;
use function method_exists;
use function strtr;
use function trim;

Expand Down Expand Up @@ -77,7 +78,7 @@ private function prepareObject(object $argument): string

$webdriverByClass = '\Facebook\WebDriver\WebDriverBy';
if (class_exists($webdriverByClass) && is_a($argument, $webdriverByClass)) {
return Locator::humanReadableString($argument);
return $this->webDriverByAsString($argument);
}

return trim($argument::class, "\\");
Expand All @@ -90,4 +91,21 @@ public function __toString(): string
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES,
);
}

private function webDriverByAsString(object $selector): string
{
$type = method_exists($selector, 'getMechanism')
? (string) $selector->getMechanism()
: null;

$locator = method_exists($selector, 'getValue')
? (string) $selector->getValue()
: null;

if (!isset($type, $locator)) {
throw new InvalidArgumentException("Unrecognized selector");
}

return "$type '$locator'";
}
}
6 changes: 3 additions & 3 deletions src/Internal/CeptInfoBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public function build(?string $host, ?string $thread): TestInfo
{
return new TestInfo(
originalTest: $this->test,
signature: (string) $this->test->getSignature(),
class: (string) $this->test->getName(),
method: (string) $this->test->getName(),
signature: $this->test->getSignature(),
class: $this->test->getName(),
method: $this->test->getName(),
host: $host,
thread: $thread,
);
Expand Down
6 changes: 3 additions & 3 deletions src/Internal/CeptProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function getDisplayName(): ?string

public function getFullName(): ?string
{
return (string) $this->test->getSignature();
return $this->test->getSignature();
}

public function getDescription(): ?string
Expand All @@ -118,7 +118,7 @@ public function getDescriptionHtml(): ?string
private function getLegacyAnnotation(string $name): ?string
{
/**
* @var mixed $annotations
* @psalm-var mixed $annotations
* @psalm-suppress InvalidArgument
*/
$annotations = $this->test->getMetadata()->getParam($name);
Expand All @@ -140,7 +140,7 @@ private function getLegacyAnnotation(string $name): ?string
private function getLegacyAnnotations(string $name): array
{
/**
* @var mixed $annotations
* @psalm-var mixed $annotations
* @psalm-suppress InvalidArgument
*/
$annotations = $this->test->getMetadata()->getParam($name);
Expand Down
12 changes: 3 additions & 9 deletions src/Internal/CestInfoBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Codeception\Test\Cest;

use function is_int;
use function is_object;
use function is_string;

final class CestInfoBuilder implements TestInfoBuilderInterface
Expand All @@ -19,16 +18,11 @@ public function __construct(

public function build(?string $host, ?string $thread): TestInfo
{
/** @var mixed $testClass */
$testClass = $this->test->getTestClass();
/** @var mixed $testMethod */
$testMethod = $this->test->getTestMethod();

return new TestInfo(
originalTest: $this->test,
signature: (string) $this->test->getSignature(),
class: is_object($testClass) ? $testClass::class : null,
method: is_string($testMethod) ? $testMethod : null,
signature: $this->test->getSignature(),
class: $this->test->getTestInstance()::class,
method: $this->test->getTestMethod(),
dataLabel: $this->getDataLabel(),
host: $host,
thread: $thread,
Expand Down
13 changes: 4 additions & 9 deletions src/Internal/CestProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use function array_values;
use function is_array;
use function is_int;
use function is_object;
use function is_string;

/**
Expand All @@ -37,16 +36,12 @@ public function __construct(
*/
public static function createForChain(Cest $test, LinkTemplateCollectionInterface $linkTemplates): array
{
/** @var mixed $testClass */
$testClass = $test->getTestClass();
/** @var mixed $testMethod */
$testMethod = $test->getTestMethod();
/** @var callable-string|null $callableTestMethod */
$callableTestMethod = is_string($testMethod) ? $testMethod : null;
/** @psalm-var callable-string $callableTestMethod */
$callableTestMethod = $test->getTestMethod();

return [
...AttributeParser::createForChain(
classOrObject: is_object($testClass) ? $testClass : null,
classOrObject: $test->getTestInstance(),
methodOrFunction: $callableTestMethod,
linkTemplates: $linkTemplates,
),
Expand Down Expand Up @@ -111,6 +106,6 @@ public function getDescriptionHtml(): ?string
*/
public function getFullName(): ?string
{
return get_class($this->test->getTestClass()) . "::" . $this->test->getTestMethod();
return $this->test->getTestInstance()::class . "::" . $this->test->getTestMethod();
}
}
11 changes: 3 additions & 8 deletions src/Internal/GherkinInfoBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@ public function __construct(

public function build(?string $host, ?string $thread): TestInfo
{
/** @psalm-var mixed $className */
$className = $this->test->getFeature();
/** @psalm-var mixed $methodName */
$methodName = $this->test->getScenarioTitle();

return new TestInfo(
originalTest: $this->test,
signature: (string) $this->test->getSignature(),
class: is_string($className) ? $className : null,
method: is_string($methodName) ? $methodName : null,
signature: $this->test->getSignature(),
class: $this->test->getFeature(),
method: $this->test->getScenarioTitle(),
host: $host,
thread: $thread,
);
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/GherkinProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getParameters(): array

public function getDisplayName(): ?string
{
return (string) $this->test->toString();
return $this->test->toString();
}

public function getDescription(): ?string
Expand Down
Loading