Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Oct 13, 2023
1 parent 788a762 commit 2204f74
Show file tree
Hide file tree
Showing 12 changed files with 6 additions and 99 deletions.
8 changes: 0 additions & 8 deletions .psalm/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@
</PropertyTypeCoercion>
</file>
<file src="src/Event/Value/Test/TestData/TestDataCollection.php">
<ArgumentTypeCoercion>
<code>$data</code>
</ArgumentTypeCoercion>
<PropertyTypeCoercion>
<code>$data</code>
</PropertyTypeCoercion>
Expand Down Expand Up @@ -382,11 +379,6 @@
</DeprecatedMethod>
<MissingThrowsDocblock>
<code>getMethod</code>
<code>valueObjectForEvents</code>
<code>valueObjectForEvents</code>
<code>valueObjectForEvents</code>
<code>valueObjectForEvents</code>
<code>valueObjectForEvents</code>
</MissingThrowsDocblock>
<PropertyNotSetInConstructor>
<code>$outputBufferingLevel</code>
Expand Down

This file was deleted.

29 changes: 5 additions & 24 deletions src/Event/Value/Test/TestData/TestDataCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,19 @@ final class TestDataCollection implements Countable, IteratorAggregate

/**
* @psalm-param list<TestData> $data
*
* @throws MoreThanOneDataSetFromDataProviderException
*/
public static function fromArray(array $data): self
{
return new self(...$data);
}

/**
* @throws MoreThanOneDataSetFromDataProviderException
*/
private function __construct(TestData ...$data)
{
$this->ensureNoMoreThanOneDataFromDataProvider($data);
foreach ($data as $_data) {
if ($_data->isFromDataProvider()) {
$this->fromDataProvider = $_data;
}
}

$this->data = $data;
}
Expand Down Expand Up @@ -83,22 +82,4 @@ public function getIterator(): TestDataCollectionIterator
{
return new TestDataCollectionIterator($this);
}

/**
* @psalm-param list<TestData> $data
*
* @throws MoreThanOneDataSetFromDataProviderException
*/
private function ensureNoMoreThanOneDataFromDataProvider(array $data): void
{
foreach ($data as $_data) {
if ($_data->isFromDataProvider()) {
if ($this->fromDataProvider !== null) {
throw new MoreThanOneDataSetFromDataProviderException;
}

$this->fromDataProvider = $_data;
}
}
}
}
4 changes: 0 additions & 4 deletions src/Event/Value/Test/TestDoxBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
namespace PHPUnit\Event\Code;

use PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException;
use PHPUnit\Framework\TestCase;
use PHPUnit\Logging\TestDox\NamePrettifier;

Expand All @@ -18,9 +17,6 @@
*/
final class TestDoxBuilder
{
/**
* @throws MoreThanOneDataSetFromDataProviderException
*/
public static function fromTestCase(TestCase $testCase): TestDox
{
$prettifier = new NamePrettifier;
Expand Down
7 changes: 0 additions & 7 deletions src/Event/Value/Test/TestMethodBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use PHPUnit\Event\Facade as EventFacade;
use PHPUnit\Event\TestData\DataFromDataProvider;
use PHPUnit\Event\TestData\DataFromTestDependency;
use PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException;
use PHPUnit\Event\TestData\TestDataCollection;
use PHPUnit\Framework\TestCase;
use PHPUnit\Metadata\Parser\Registry as MetadataRegistry;
Expand All @@ -27,9 +26,6 @@
*/
final class TestMethodBuilder
{
/**
* @throws MoreThanOneDataSetFromDataProviderException
*/
public static function fromTestCase(TestCase $testCase): TestMethod
{
$methodName = $testCase->name();
Expand Down Expand Up @@ -63,9 +59,6 @@ public static function fromCallStack(): TestMethod
throw new NoTestCaseObjectOnCallStackException;
}

/**
* @throws MoreThanOneDataSetFromDataProviderException
*/
private static function dataFor(TestCase $testCase): TestDataCollection
{
$testData = [];
Expand Down
21 changes: 0 additions & 21 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
use DeepCopy\DeepCopy;
use PHPUnit\Event;
use PHPUnit\Event\NoPreviousThrowableException;
use PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException;
use PHPUnit\Event\TestData\NoDataSetFromDataProviderException;
use PHPUnit\Framework\Constraint\Exception as ExceptionConstraint;
use PHPUnit\Framework\Constraint\ExceptionCode;
Expand Down Expand Up @@ -291,7 +290,6 @@ final public function status(): TestStatus
* @throws \SebastianBergmann\Template\InvalidArgumentException
* @throws CodeCoverageException
* @throws Exception
* @throws MoreThanOneDataSetFromDataProviderException
* @throws NoDataSetFromDataProviderException
* @throws NoPreviousThrowableException
* @throws ProcessIsolationException
Expand Down Expand Up @@ -864,8 +862,6 @@ final public function setData(int|string $dataName, array $data): void

/**
* @internal This method is not covered by the backward compatibility promise for PHPUnit
*
* @throws MoreThanOneDataSetFromDataProviderException
*/
final public function valueObjectForEvents(): Event\Code\TestMethod
{
Expand Down Expand Up @@ -1618,7 +1614,6 @@ private function handleDependencies(): bool

/**
* @throws Exception
* @throws MoreThanOneDataSetFromDataProviderException
* @throws NoPreviousThrowableException
*/
private function markErrorForInvalidDependency(?ExecutionOrderDependency $dependency = null): void
Expand All @@ -1642,9 +1637,6 @@ private function markErrorForInvalidDependency(?ExecutionOrderDependency $depend
$this->status = TestStatus::error($message);
}

/**
* @throws MoreThanOneDataSetFromDataProviderException
*/
private function markSkippedForMissingDependency(ExecutionOrderDependency $dependency): void
{
$message = sprintf(
Expand All @@ -1668,9 +1660,6 @@ private function startOutputBuffering(): void
$this->outputBufferingLevel = ob_get_level();
}

/**
* @throws MoreThanOneDataSetFromDataProviderException
*/
private function stopOutputBuffering(): bool
{
$bufferingLevel = ob_get_level();
Expand Down Expand Up @@ -1716,9 +1705,6 @@ private function snapshotGlobalState(): void
$this->snapshot = $snapshot;
}

/**
* @throws MoreThanOneDataSetFromDataProviderException
*/
private function restoreGlobalState(): void
{
if (!$this->snapshot instanceof Snapshot) {
Expand Down Expand Up @@ -1783,9 +1769,6 @@ private function createGlobalStateSnapshot(bool $backupGlobals): Snapshot
);
}

/**
* @throws MoreThanOneDataSetFromDataProviderException
*/
private function compareGlobalStateSnapshots(Snapshot $before, Snapshot $after): void
{
$backupGlobals = $this->backupGlobals === null || $this->backupGlobals;
Expand Down Expand Up @@ -1813,9 +1796,6 @@ private function compareGlobalStateSnapshots(Snapshot $before, Snapshot $after):
}
}

/**
* @throws MoreThanOneDataSetFromDataProviderException
*/
private function compareGlobalStateSnapshotPart(array $before, array $after, string $header): void
{
if ($before != $after) {
Expand Down Expand Up @@ -1986,7 +1966,6 @@ private function isCallableTestMethod(string $dependency): bool
/**
* @throws Exception
* @throws ExpectationFailedException
* @throws MoreThanOneDataSetFromDataProviderException
* @throws NoPreviousThrowableException
*/
private function performAssertionsOnOutput(): void
Expand Down
3 changes: 0 additions & 3 deletions src/Framework/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use AssertionError;
use PHPUnit\Event;
use PHPUnit\Event\NoPreviousThrowableException;
use PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException;
use PHPUnit\Event\TestData\NoDataSetFromDataProviderException;
use PHPUnit\Metadata\Api\CodeCoverage as CodeCoverageMetadataApi;
use PHPUnit\Metadata\Parser\Registry as MetadataRegistry;
Expand Down Expand Up @@ -61,7 +60,6 @@ public function __construct()
* @throws \PHPUnit\Runner\Exception
* @throws \SebastianBergmann\CodeCoverage\InvalidArgumentException
* @throws CodeCoverageException
* @throws MoreThanOneDataSetFromDataProviderException
* @throws NoDataSetFromDataProviderException
* @throws UnintentionallyCoveredCodeException
*/
Expand Down Expand Up @@ -247,7 +245,6 @@ public function run(TestCase $test): void
* @throws \PHPUnit\Util\Exception
* @throws \SebastianBergmann\Template\InvalidArgumentException
* @throws Exception
* @throws MoreThanOneDataSetFromDataProviderException
* @throws NoPreviousThrowableException
* @throws ProcessIsolationException
* @throws StaticAnalysisCacheNotConfiguredException
Expand Down
1 change: 0 additions & 1 deletion src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ public function isForTestClass(): bool
}

/**
* @throws \PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException
* @throws Exception
*/
protected function addTestMethod(ReflectionClass $class, ReflectionMethod $method): void
Expand Down
4 changes: 0 additions & 4 deletions src/Metadata/Api/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@
use function substr;
use function trim;
use PHPUnit\Event;
use PHPUnit\Event\Code\TestMethod;
use PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException;
use PHPUnit\Event\TestData\TestDataCollection;
use PHPUnit\Framework\InvalidDataProviderException;
use PHPUnit\Metadata\DataProvider as DataProviderMetadata;
use PHPUnit\Metadata\MetadataCollection;
use PHPUnit\Metadata\Parser\Registry as MetadataRegistry;
use PHPUnit\Metadata\TestWith;
use PHPUnit\Util\Reflection;
use ReflectionClass;
use ReflectionMethod;
use Throwable;
Expand Down
2 changes: 0 additions & 2 deletions src/Runner/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use function file_put_contents;
use function sprintf;
use PHPUnit\Event\Facade as EventFacade;
use PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException;
use PHPUnit\Event\TestData\NoDataSetFromDataProviderException;
use PHPUnit\Framework\TestCase;
use PHPUnit\TextUI\Configuration\CodeCoverageFilterRegistry;
Expand Down Expand Up @@ -140,7 +139,6 @@ public function driver(): Driver
}

/**
* @throws MoreThanOneDataSetFromDataProviderException
* @throws NoDataSetFromDataProviderException
*/
public function start(TestCase $test): void
Expand Down
3 changes: 1 addition & 2 deletions src/Runner/Filter/TestIdFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace PHPUnit\Runner\Filter;

use function in_array;
use PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException;
use PHPUnit\Event\TestData\NoDataSetFromDataProviderException;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -54,7 +53,7 @@ public function accept(): bool

try {
return in_array($test->valueObjectForEvents()->id(), $this->testIds, true);
} catch (MoreThanOneDataSetFromDataProviderException|NoDataSetFromDataProviderException) {
} catch (NoDataSetFromDataProviderException) {
return false;
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/Util/PHP/AbstractPhpProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use PHPUnit\Event\Code\ThrowableBuilder;
use PHPUnit\Event\Facade;
use PHPUnit\Event\NoPreviousThrowableException;
use PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\Test;
Expand Down Expand Up @@ -132,7 +131,6 @@ public function getEnv(): array
*
* @throws \PHPUnit\Runner\Exception
* @throws Exception
* @throws MoreThanOneDataSetFromDataProviderException
* @throws NoPreviousThrowableException
*/
public function runTestJob(string $job, Test $test, string $processResultFile): void
Expand Down Expand Up @@ -226,7 +224,6 @@ protected function settingsToParameters(array $settings): string
/**
* @throws \PHPUnit\Runner\Exception
* @throws Exception
* @throws MoreThanOneDataSetFromDataProviderException
* @throws NoPreviousThrowableException
*/
private function processChildResult(Test $test, string $stdout, string $stderr): void
Expand Down

0 comments on commit 2204f74

Please sign in to comment.