Skip to content

Commit

Permalink
fix status detection (via #64)
Browse files Browse the repository at this point in the history
  • Loading branch information
remorhaz authored Oct 19, 2021
1 parent ffad875 commit 88bccf5
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 40 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"require": {
"php": "^8",
"allure-framework/allure-php-commons": "^2.0.0-rc1",
"allure-framework/allure-php-commons": "2.0.0-rc3",
"phpunit/phpunit": "^9"
},
"require-dev": {
Expand Down
4 changes: 2 additions & 2 deletions src/AllureExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ public function executeAfterTestFailure(string $test, string $message, float $ti
$this
->testLifecycle
->switchTo($test)
->updateDetectedStatus($message, Status::failed());
->updateDetectedStatus($message, Status::failed(), Status::failed());
}

public function executeAfterTestError(string $test, string $message, float $time): void
{
$this
->testLifecycle
->switchTo($test)
->updateDetectedStatus($message, Status::failed());
->updateDetectedStatus($message, Status::broken());
}

public function executeAfterIncompleteTest(string $test, string $message, float $time): void
Expand Down
8 changes: 6 additions & 2 deletions src/Internal/TestLifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@ public function updateStatus(?string $message = null, ?Status $status = null): s
return $this;
}

public function updateDetectedStatus(?string $message = null, ?Status $status = null): self
{
public function updateDetectedStatus(
?string $message = null,
?Status $status = null,
?Status $overrideStatus = null,
): self {
$exception = $this->adapter->getLastException();
if (!isset($exception)) {
return $this->updateStatus($message, $status);
Expand All @@ -127,6 +130,7 @@ public function updateDetectedStatus(?string $message = null, ?Status $status =
$testResult,
$this->statusDetector,
$exception,
$overrideStatus,
),
$this->adapter->getTestId($this->getCurrentTest()),
);
Expand Down
6 changes: 5 additions & 1 deletion src/Internal/TestLifecycleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public function write(): TestLifecycleInterface;

public function updateStatus(?string $message = null, ?Status $status = null): TestLifecycleInterface;

public function updateDetectedStatus(?string $message = null, ?Status $status = null): TestLifecycleInterface;
public function updateDetectedStatus(
?string $message = null,
?Status $status = null,
?Status $overrideStatus = null,
): TestLifecycleInterface;

public function switchTo(string $test): TestLifecycleInterface;

Expand Down
12 changes: 8 additions & 4 deletions src/Internal/TestUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function setInfo(TestResult $testResult, TestInfo $info): void
$parser = $this->parseAnnotations($info);

$testResult
->setName($parser->getTitle() ?? $info->getName())
->setName($parser->getDisplayName() ?? $info->getName())
->setFullName($info->getFullName())
->setDescriptionHtml($parser->getDescriptionHtml())
->setDescription($parser->getDescription())
Expand Down Expand Up @@ -122,10 +122,14 @@ public function setRunInfo(TestResult $testResult, TestRunInfo $runInfo): void
->setRerunOf($runInfo->getRerunOf());
}

public function setDetectedStatus(TestResult $test, StatusDetectorInterface $statusDetector, Throwable $e): void
{
public function setDetectedStatus(
TestResult $test,
StatusDetectorInterface $statusDetector,
Throwable $e,
?Status $overrideStatus = null,
): void {
$test
->setStatus($statusDetector->getStatus($e))
->setStatus($overrideStatus ?? $statusDetector->getStatus($e))
->setStatusDetails($statusDetector->getStatusDetails($e));
}

Expand Down
7 changes: 6 additions & 1 deletion src/Internal/TestUpdaterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ public function setInfo(TestResult $testResult, TestInfo $info): void;

public function setRunInfo(TestResult $testResult, TestRunInfo $runInfo): void;

public function setDetectedStatus(TestResult $test, StatusDetectorInterface $statusDetector, Throwable $e): void;
public function setDetectedStatus(
TestResult $test,
StatusDetectorInterface $statusDetector,
Throwable $e,
?Status $overrideStatus = null,
): void;

public function setStatus(TestResult $test, ?string $message = null, ?Status $status = null): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @Title ("This test has wrong title")
*/
#[
Attribute\Title('Native class-level annotation overrides legacy one if both are used'),
Attribute\DisplayName('Native class-level annotation overrides legacy one if both are used'),
Attribute\Epic('Annotations'),
Attribute\Feature('Title'),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Qameta\Allure\Attribute;

#[
Attribute\Title('Test without title annotation uses class-level native title annotation'),
Attribute\DisplayName('Test without title annotation uses class-level native title annotation'),
Attribute\Epic('Annotations'),
Attribute\Feature('Title'),
]
Expand Down
4 changes: 2 additions & 2 deletions test/report/Generate/Annotation/TitleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testLegacyTitleAnnotation(): void
$this->expectNotToPerformAssertions();
}

#[Attribute\Title('Native title annotation is reported as test title')]
#[Attribute\DisplayName('Native display name annotation is reported as test title')]
public function testNativeTitleAnnotation(): void
{
$this->expectNotToPerformAssertions();
Expand All @@ -40,7 +40,7 @@ public function testNativeTitleAnnotation(): void
/**
* @Title ("This is wrong title for this test")
*/
#[Attribute\Title('Native title annotation overrides legacy one')]
#[Attribute\DisplayName('Native display name annotation overrides legacy one')]
public function testMixedTitleAnnotation(): void
{
$this->expectNotToPerformAssertions();
Expand Down
12 changes: 6 additions & 6 deletions test/report/Generate/AnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class AnnotationTest extends TestCase
/**
* @Description ("Legacy description with `markdown`", type = DescriptionType::MARKDOWN)
*/
#[Attribute\Title('Legacy description annotation is reported as test description')]
#[Attribute\DisplayName('Legacy description annotation is reported as test description')]
public function testLegacyDescriptionAnnotation(): void
{
$this->expectNotToPerformAssertions();
}

#[
Attribute\Title('Native description annotation is reported as test description'),
Attribute\DisplayName('Native description annotation is reported as test description'),
Attribute\Description('Test native description with `markdown`'),
]
public function testNativeDescriptionAnnotation(): void
Expand All @@ -49,14 +49,14 @@ public function testMixedDescriptionAnnotation(): void
/**
* @Severity (level = SeverityLevel::MINOR)
*/
#[Attribute\Title('Legacy severity annotation is reported as test severity')]
#[Attribute\DisplayName('Legacy severity annotation is reported as test severity')]
public function testLegacySeverityAnnotation(): void
{
$this->expectNotToPerformAssertions();
}

#[
Attribute\Title('Native severity annotation is reported as test severity'),
Attribute\DisplayName('Native severity annotation is reported as test severity'),
Attribute\Severity(Attribute\Severity::CRITICAL),
]
public function testNativeSeverityAnnotation(): void
Expand All @@ -68,7 +68,7 @@ public function testNativeSeverityAnnotation(): void
* @Severity (level = SeverityLevel::MINOR)
*/
#[
Attribute\Title('Legacy severity annotation overrides native one'),
Attribute\DisplayName('Legacy severity annotation overrides native one'),
Attribute\Severity(Attribute\Severity::CRITICAL),
]
public function testMixedSeverityAnnotation(): void
Expand All @@ -79,7 +79,7 @@ public function testMixedSeverityAnnotation(): void
/**
* @Parameter (name = "foo", value = "legacy foo")
*/
#[Attribute\Title('Legacy parameter')]
#[Attribute\DisplayName('Legacy parameter')]
public function testLegacyParameterAnnotation(): void
{
$this->expectNotToPerformAssertions();
Expand Down
22 changes: 11 additions & 11 deletions test/report/Generate/NegativeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,70 @@

use PHPUnit\Framework\TestCase;
use Qameta\Allure\Allure;
use Qameta\Allure\Attribute\Title;
use Qameta\Allure\Attribute\DisplayName;
use Qameta\Allure\PHPUnit\ExceptionDetailsTrait;
use RuntimeException;

class NegativeTest extends TestCase
{
use ExceptionDetailsTrait;

#[Title('Test with failed assertion is reported as failed')]
#[DisplayName('Test with failed assertion is reported as failed')]
public function testFailedWithoutSteps(): void
{
self::fail("Failure message");
}

#[Title('Test with failed assertion in step is reported as failed')]
#[DisplayName('Test with failed assertion in step is reported as failed')]
public function testFailedWithSteps(): void
{
Allure::addStep('Successful step');
Allure::runStep(
#[Title('Failed step')]
#[DisplayName('Failed step')]
function () {
self::fail('Failure message');
}
);
}

#[Title('Test that throws exception is reported as failed')]
#[DisplayName('Test that throws exception is reported as failed')]
public function testException(): void
{
throw new RuntimeException('Exception message');
}

#[Title('Test that throws exception in step is reported as failed')]
#[DisplayName('Test that throws exception in step is reported as failed')]
public function testExceptionWithSteps(): void
{
Allure::addStep('Successful step');
Allure::runStep(
#[Title('Failed step')]
#[DisplayName('Failed step')]
function () {
throw new RuntimeException('Exception message');
}
);
}

#[Title('Test that emits warning is reported as broken')]
#[DisplayName('Test that emits warning is reported as broken')]
public function testWarning(): void
{
/** @psalm-suppress InternalMethod */
$this->addWarning('Warning message');
}

#[Title('Skipped test is reported as skipped')]
#[DisplayName('Skipped test is reported as skipped')]
public function testSkipped(): void
{
self::markTestSkipped('Skipped message');
}

#[Title('Incomplete test is reported as broken')]
#[DisplayName('Incomplete test is reported as broken')]
public function testIncomplete(): void
{
self::markTestIncomplete('Incomplete message');
}

#[Title('Risky test is reported as failed')]
#[DisplayName('Risky test is reported as failed')]
public function testRisky(): void
{
self::markAsRisky();
Expand Down
8 changes: 4 additions & 4 deletions test/report/Generate/RetriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use Qameta\Allure\Allure;
use Qameta\Allure\Attribute\Description;
use Qameta\Allure\Attribute\Title;
use Qameta\Allure\Attribute\DisplayName;
use Qameta\Allure\PHPUnit\ExceptionDetailsTrait;

class RetriesTest extends TestCase
Expand All @@ -19,13 +19,13 @@ class RetriesTest extends TestCase
*/
private static array $runCounters = [];

#[Title('Reruns of successful test are reported correctly')]
#[DisplayName('Reruns of successful test are reported correctly')]
public function testRerunsOfSuccessfulTest(): void
{
$this->expectNotToPerformAssertions();
}

#[Title('Reruns of failed test are reported correctly')]
#[DisplayName('Reruns of failed test are reported correctly')]
public function testRerunsOfFailedTest(): void
{
self::assertNotSame(1, $this->getRunIndex(__METHOD__));
Expand All @@ -35,7 +35,7 @@ public function testRerunsOfFailedTest(): void
* @dataProvider providerData
*/
#[
Title('Reruns of test with data provider are reported correctly'),
DisplayName('Reruns of test with data provider are reported correctly'),
Description("Parameter `retry` has different value on each run but is excluded and doesn't have effect"),
]
public function testRerunsOfTestWithDataProvider(string $firstValue, string $secondValue): void
Expand Down
12 changes: 10 additions & 2 deletions test/unit/AllureExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ public function testExecuteAfterTestFailure_Constructed_SetsDetectedOrFailedStat
->expects(self::once())
->after('switch')
->method('updateDetectedStatus')
->with(self::identicalTo('c'), self::identicalTo(Status::failed()));
->with(
self::identicalTo('c'),
self::identicalTo(Status::failed()),
self::identicalTo(Status::failed()),
);
$extension->executeAfterTestFailure('b', 'c', 1.2);
}

Expand All @@ -274,7 +278,11 @@ public function testExecuteAfterTestError_Constructed_SetsDetectedOrFailedStatus
->expects(self::once())
->after('switch')
->method('updateDetectedStatus')
->with(self::identicalTo('c'), self::identicalTo(Status::failed()));
->with(
self::identicalTo('c'),
self::identicalTo(Status::broken()),
self::identicalTo(null),
);
$extension->executeAfterTestError('b', 'c', 1.2);
}

Expand Down
7 changes: 5 additions & 2 deletions test/unit/TestTestLifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ public function switchTo(string $test): TestLifecycleInterface
return $this;
}

public function updateDetectedStatus(?string $message = null, ?Status $status = null): TestLifecycleInterface
{
public function updateDetectedStatus(
?string $message = null,
?Status $status = null,
?Status $overrideStatus = null,
): TestLifecycleInterface {
return $this;
}

Expand Down

0 comments on commit 88bccf5

Please sign in to comment.