Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 31, 2023
1 parent 23e4eac commit ae2bc1f
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 469 deletions.
35 changes: 14 additions & 21 deletions src/Runner/TestResult/Collector.php
Expand Up @@ -43,14 +43,7 @@
use PHPUnit\Event\TestSuite\TestSuiteForTestClass;
use PHPUnit\Event\TestSuite\TestSuiteForTestMethodWithDataProvider;
use PHPUnit\Event\UnknownSubscriberTypeException;
use PHPUnit\TestRunner\TestResult\Issues\Deprecation;
use PHPUnit\TestRunner\TestResult\Issues\Error;
use PHPUnit\TestRunner\TestResult\Issues\Issue;
use PHPUnit\TestRunner\TestResult\Issues\Notice;
use PHPUnit\TestRunner\TestResult\Issues\PhpDeprecation;
use PHPUnit\TestRunner\TestResult\Issues\PhpNotice;
use PHPUnit\TestRunner\TestResult\Issues\PhpWarning;
use PHPUnit\TestRunner\TestResult\Issues\Warning;
use PHPUnit\TextUI\Configuration\Source;
use PHPUnit\TextUI\Configuration\SourceFilter;

Expand Down Expand Up @@ -122,37 +115,37 @@ final class Collector
private array $testRunnerTriggeredDeprecationEvents = [];

/**
* @psalm-var array<non-empty-string, Error>
* @psalm-var array<non-empty-string, Issue>
*/
private array $errors = [];

/**
* @psalm-var array<non-empty-string, Deprecation>
* @psalm-var array<non-empty-string, Issue>
*/
private array $deprecations = [];

/**
* @psalm-var array<non-empty-string, Notice>
* @psalm-var array<non-empty-string, Issue>
*/
private array $notices = [];

/**
* @psalm-var array<non-empty-string, Warning>
* @psalm-var array<non-empty-string, Issue>
*/
private array $warnings = [];

/**
* @psalm-var array<non-empty-string, PhpDeprecation>
* @psalm-var array<non-empty-string, Issue>
*/
private array $phpDeprecations = [];

/**
* @psalm-var array<non-empty-string, PhpNotice>
* @psalm-var array<non-empty-string, Issue>
*/
private array $phpNotices = [];

/**
* @psalm-var array<non-empty-string, PhpWarning>
* @psalm-var array<non-empty-string, Issue>
*/
private array $phpWarnings = [];

Expand Down Expand Up @@ -360,7 +353,7 @@ public function testTriggeredDeprecation(DeprecationTriggered $event): void
$id = $this->issueId($event);

if (!isset($this->deprecations[$id])) {
$this->deprecations[$id] = Issue::deprecation(
$this->deprecations[$id] = Issue::from(
$event->file(),
$event->line(),
$event->message(),
Expand All @@ -386,7 +379,7 @@ public function testTriggeredPhpDeprecation(PhpDeprecationTriggered $event): voi
$id = $this->issueId($event);

if (!isset($this->phpDeprecations[$id])) {
$this->phpDeprecations[$id] = Issue::phpDeprecation(
$this->phpDeprecations[$id] = Issue::from(
$event->file(),
$event->line(),
$event->message(),
Expand Down Expand Up @@ -417,7 +410,7 @@ public function testTriggeredError(ErrorTriggered $event): void
$id = $this->issueId($event);

if (!isset($this->errors[$id])) {
$this->errors[$id] = Issue::error(
$this->errors[$id] = Issue::from(
$event->file(),
$event->line(),
$event->message(),
Expand All @@ -443,7 +436,7 @@ public function testTriggeredNotice(NoticeTriggered $event): void
$id = $this->issueId($event);

if (!isset($this->notices[$id])) {
$this->notices[$id] = Issue::notice(
$this->notices[$id] = Issue::from(
$event->file(),
$event->line(),
$event->message(),
Expand All @@ -469,7 +462,7 @@ public function testTriggeredPhpNotice(PhpNoticeTriggered $event): void
$id = $this->issueId($event);

if (!isset($this->phpNotices[$id])) {
$this->phpNotices[$id] = Issue::phpNotice(
$this->phpNotices[$id] = Issue::from(
$event->file(),
$event->line(),
$event->message(),
Expand All @@ -495,7 +488,7 @@ public function testTriggeredWarning(WarningTriggered $event): void
$id = $this->issueId($event);

if (!isset($this->warnings[$id])) {
$this->warnings[$id] = Issue::warning(
$this->warnings[$id] = Issue::from(
$event->file(),
$event->line(),
$event->message(),
Expand All @@ -521,7 +514,7 @@ public function testTriggeredPhpWarning(PhpWarningTriggered $event): void
$id = $this->issueId($event);

if (!isset($this->phpWarnings[$id])) {
$this->phpWarnings[$id] = Issue::phpWarning(
$this->phpWarnings[$id] = Issue::from(
$event->file(),
$event->line(),
$event->message(),
Expand Down
113 changes: 113 additions & 0 deletions src/Runner/TestResult/Issue.php
@@ -0,0 +1,113 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestRunner\TestResult\Issues;

use PHPUnit\Event\Code\Test;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Issue
{
/**
* @psalm-var non-empty-string
*/
private readonly string $file;

/**
* @psalm-var positive-int
*/
private readonly int $line;

/**
* @psalm-var non-empty-string
*/
private readonly string $description;

/**
* @psalm-var non-empty-array<non-empty-string, array{test: Test, count: int}>
*/
private array $triggeringTests;

/**
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
* @psalm-param non-empty-string $description
*/
public static function from(string $file, int $line, string $description, Test $triggeringTest): self
{
return new self($file, $line, $description, $triggeringTest);
}

/**
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
* @psalm-param non-empty-string $description
*/
private function __construct(string $file, int $line, string $description, Test $triggeringTest)
{
$this->file = $file;
$this->line = $line;
$this->description = $description;

$this->triggeringTests = [
$triggeringTest->id() => [
'test' => $triggeringTest,
'count' => 1,
],
];
}

public function triggeredBy(Test $test): void
{
if (isset($this->triggeringTests[$test->id()])) {
$this->triggeringTests[$test->id()]['count']++;

return;
}

$this->triggeringTests[$test->id()] = [
'test' => $test,
'count' => 1,
];
}

/**
* @psalm-return non-empty-string
*/
public function file(): string
{
return $this->file;
}

/**
* @psalm-return positive-int
*/
public function line(): int
{
return $this->line;
}

/**
* @psalm-return non-empty-string
*/
public function description(): string
{
return $this->description;
}

/**
* @psalm-return non-empty-array<non-empty-string, array{test: Test, count: int}>
*/
public function triggeringTests(): array
{
return $this->triggeringTests;
}
}
24 changes: 0 additions & 24 deletions src/Runner/TestResult/Issues/Deprecation.php

This file was deleted.

24 changes: 0 additions & 24 deletions src/Runner/TestResult/Issues/Error.php

This file was deleted.

0 comments on commit ae2bc1f

Please sign in to comment.