Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request pestphp#747 from gehrisandro/add-teamcity-testsuit…
Browse files Browse the repository at this point in the history
…e-count

teamcity: add missing test count output
  • Loading branch information
nunomaduro authored Mar 29, 2023
2 parents ba87e1f + cd8d947 commit 56ec3b9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Logging/TeamCity/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ public function getTestSuiteLocation(TestSuite $testSuite): string|null
return $this->toRelativePath($path);
}

/**
* Gets the test suite size.
*/
public function getTestSuiteSize(TestSuite $testSuite): int
{
return $testSuite->count();
}

/**
* Transforms the given path in relative path.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/Logging/TeamCity/ServiceMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public static function testSuiteStarted(string $name, string|null $location): se
]);
}

public static function testSuiteCount(int $count): self
{
return new self('testCount', [
'count' => $count,
]);
}

public static function testSuiteFinished(string $name): self
{
return new self('testSuiteFinished', [
Expand Down
11 changes: 11 additions & 0 deletions src/Logging/TeamCity/TeamCityLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ final class TeamCityLogger
{
private ?HRTime $time = null;

private bool $isSummaryTestCountPrinted = false;

/**
* @throws EventFacadeIsSealedException
* @throws UnknownSubscriberTypeException
Expand All @@ -66,6 +68,15 @@ public function testSuiteStarted(TestSuiteStarted $event): void
);

$this->output($message);

if (! $this->isSummaryTestCountPrinted) {
$this->isSummaryTestCountPrinted = true;
$message = ServiceMessage::testSuiteCount(
$this->converter->getTestSuiteSize($event->testSuite())
);

$this->output($message);
}
}

public function testSuiteFinished(TestSuiteFinished $event): void
Expand Down
1 change: 1 addition & 0 deletions tests/.snapshots/Failure.php.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
##teamcity[testSuiteStarted name='Tests/tests/Failure' locationHint='file://tests/.tests/Failure.php' flowId='1234']
##teamcity[testCount count='6' flowId='1234']
##teamcity[testStarted name='it can fail with comparison' locationHint='pest_qn://tests/.tests/Failure.php::it can fail with comparison' flowId='1234']
##teamcity[testFailed name='it can fail with comparison' message='Failed asserting that true matches expected false.' details='at src/Mixins/Expectation.php:343|nat src/Support/ExpectationPipeline.php:75|nat src/Support/ExpectationPipeline.php:79|nat src/Expectation.php:300|nat tests/.tests/Failure.php:6|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:302|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:302|nat src/Concerns/Testable.php:221|nat src/Kernel.php:86' type='comparisonFailure' actual='true' expected='false' flowId='1234']
##teamcity[testFinished name='it can fail with comparison' duration='100000' flowId='1234']
Expand Down
1 change: 1 addition & 0 deletions tests/.snapshots/SuccessOnly.php.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
##teamcity[testSuiteStarted name='Tests/tests/SuccessOnly' locationHint='file://tests/.tests/SuccessOnly.php' flowId='1234']
##teamcity[testCount count='2' flowId='1234']
##teamcity[testStarted name='it can pass with comparison' locationHint='pest_qn://tests/.tests/SuccessOnly.php::it can pass with comparison' flowId='1234']
##teamcity[testFinished name='it can pass with comparison' duration='100000' flowId='1234']
##teamcity[testStarted name='can also pass' locationHint='pest_qn://tests/.tests/SuccessOnly.php::can also pass' flowId='1234']
Expand Down

0 comments on commit 56ec3b9

Please sign in to comment.