Skip to content

Commit

Permalink
Initial work on event-based result printing
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Aug 7, 2022
1 parent de14574 commit 7b7b5dd
Show file tree
Hide file tree
Showing 26 changed files with 214 additions and 326 deletions.
13 changes: 4 additions & 9 deletions .psalm/baseline.xml
Expand Up @@ -1044,18 +1044,13 @@
</PropertyNotSetInConstructor>
</file>
<file src="src/TextUI/ResultPrinter.php">
<DeprecatedClass occurrences="7">
<code>LegacyTestResult</code>
<code>LegacyTestResult</code>
<code>LegacyTestResult</code>
<code>LegacyTestResult</code>
<code>LegacyTestResult</code>
<code>LegacyTestResult</code>
<code>LegacyTestResult</code>
</DeprecatedClass>
<MissingThrowsDocblock occurrences="1">
<code>resourceUsageSinceStartOfRequest</code>
</MissingThrowsDocblock>
<RedundantCondition occurrences="2">
<code>assert($test instanceof TestMethod)</code>
<code>assert($test instanceof TestMethod)</code>
</RedundantCondition>
</file>
<file src="src/TextUI/TestRunner.php">
<DeprecatedClass occurrences="1">
Expand Down
32 changes: 8 additions & 24 deletions src/Framework/TestSuite.php
Expand Up @@ -103,18 +103,10 @@ public static function fromClassReflector(ReflectionClass $class): static
$constructor = $class->getConstructor();

if ($constructor !== null && !$constructor->isPublic()) {
$message = sprintf(
'Class "%s" has no public constructor.',
$class->getName()
);

Event\Facade::emitter()->testRunnerTriggeredWarning($message);

$testSuite->addTest(
new WarningTestCase(
$class->getName(),
'',
$message
Event\Facade::emitter()->testRunnerTriggeredWarning(
sprintf(
'Class "%s" has no public constructor.',
$class->getName()
)
);

Expand All @@ -138,18 +130,10 @@ public static function fromClassReflector(ReflectionClass $class): static
}

if (count($testSuite) === 0) {
$message = sprintf(
'No tests found in class "%s".',
$class->getName()
);

Event\Facade::emitter()->testRunnerTriggeredWarning($message);

$testSuite->addTest(
new WarningTestCase(
$class->getName(),
'',
$message
Event\Facade::emitter()->testRunnerTriggeredWarning(
sprintf(
'No tests found in class "%s".',
$class->getName()
)
);
}
Expand Down
13 changes: 13 additions & 0 deletions src/Runner/TestResult/Collector.php
Expand Up @@ -235,6 +235,19 @@ public function hasTestMarkedIncompleteEvents(): bool
return !empty($this->testMarkedIncompleteEvents);
}

public function hasTestRunnerTriggeredWarningEvents(): bool
{
return !empty($this->testRunnerTriggeredWarningEvents);
}

/**
* @psalm-return list<TestRunnerWarningTriggered>
*/
public function testRunnerTriggeredWarningEvents(): array
{
return $this->testRunnerTriggeredWarningEvents;
}

/**
* @psalm-return list<class-string>
*/
Expand Down
9 changes: 9 additions & 0 deletions src/TextUI/Application.php
Expand Up @@ -249,6 +249,15 @@ private function handleArguments(array $argv): TestSuite
exit(self::EXCEPTION_EXIT);
}

if ($testSuite->isEmpty() &&
($arguments->hasArgument() || $this->xmlConfiguration->phpunit()->hasDefaultTestSuite())) {
$this->printVersionString();

print 'No tests found.' . PHP_EOL;

exit(self::EXCEPTION_EXIT);
}

if ($configuration->hasCoverageReport() || $arguments->hasWarmCoverageCache()) {
CodeCoverageFilterRegistry::init($arguments, $this->xmlConfiguration);
}
Expand Down

0 comments on commit 7b7b5dd

Please sign in to comment.