From e0ea704a2385b0b91ca30bde3ddefb9e6e0096d0 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 9 Dec 2024 14:54:45 +0100 Subject: [PATCH] Cleanup --- tests/TestCase.php | 15 ++----- tests/tests/Report/Html/EndToEndTest.php | 41 +++++++------------ tests/tests/Report/PhpTest.php | 11 +++-- tests/tests/Report/XmlTest.php | 14 +++---- .../tests/StaticAnalysis/Value/ClassTest.php | 11 ++++- .../StaticAnalysis/Value/InterfaceTest.php | 2 +- .../tests/StaticAnalysis/Value/TraitTest.php | 13 +++++- 7 files changed, 52 insertions(+), 55 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 46883f490..4f2157718 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,27 +9,18 @@ */ namespace SebastianBergmann\CodeCoverage; -use SebastianBergmann\CodeCoverage\Data\RawCodeCoverageData; -use SebastianBergmann\CodeCoverage\Test\Target\Target; -use SebastianBergmann\CodeCoverage\Test\Target\TargetCollection; -use function array_merge; -use function range; use function rmdir; use function unlink; use BankAccount; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; +use SebastianBergmann\CodeCoverage\Data\RawCodeCoverageData; use SebastianBergmann\CodeCoverage\Driver\Driver; +use SebastianBergmann\CodeCoverage\Test\Target\Target; +use SebastianBergmann\CodeCoverage\Test\Target\TargetCollection; abstract class TestCase extends \PHPUnit\Framework\TestCase { - protected static $TEST_TMP_PATH; - - public static function setUpBeforeClass(): void - { - self::$TEST_TMP_PATH = TEST_FILES_PATH . 'tmp'; - } - protected function getLineCoverageXdebugDataForBankAccount() { return [ diff --git a/tests/tests/Report/Html/EndToEndTest.php b/tests/tests/Report/Html/EndToEndTest.php index 1865112e1..6262bf6a1 100644 --- a/tests/tests/Report/Html/EndToEndTest.php +++ b/tests/tests/Report/Html/EndToEndTest.php @@ -20,30 +20,19 @@ final class EndToEndTest extends TestCase { - private static $TEST_REPORT_PATH_SOURCE; - - public static function setUpBeforeClass(): void - { - parent::setUpBeforeClass(); - - self::$TEST_REPORT_PATH_SOURCE = TEST_FILES_PATH . 'Report' . DIRECTORY_SEPARATOR . 'HTML'; - } - protected function tearDown(): void { - parent::tearDown(); - $this->removeTemporaryFiles(); } public function testLineCoverageForBankAccountTest(): void { - $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForBankAccount'; + $expectedFilesPath = TEST_FILES_PATH . 'Report' . DIRECTORY_SEPARATOR . 'HTML' . DIRECTORY_SEPARATOR . 'CoverageForBankAccount'; $report = new Facade; - $report->process($this->getLineCoverageForBankAccount(), self::$TEST_TMP_PATH); + $report->process($this->getLineCoverageForBankAccount(), TEST_FILES_PATH . 'tmp'); - $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + $this->assertFilesEquals($expectedFilesPath, TEST_FILES_PATH . 'tmp'); } public function testPathCoverageForBankAccountTest(): void @@ -51,42 +40,42 @@ public function testPathCoverageForBankAccountTest(): void $this->markTestIncomplete('This test fails after https://github.com/sebastianbergmann/php-code-coverage/pull/1037 and I have not figured out how to update it.'); /** @phpstan-ignore deadCode.unreachable */ - $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'PathCoverageForBankAccount'; + $expectedFilesPath = TEST_FILES_PATH . 'Report' . DIRECTORY_SEPARATOR . 'HTML' . DIRECTORY_SEPARATOR . 'PathCoverageForBankAccount'; $report = new Facade; - $report->process($this->getPathCoverageForBankAccount(), self::$TEST_TMP_PATH); + $report->process($this->getPathCoverageForBankAccount(), TEST_FILES_PATH . 'tmp'); - $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + $this->assertFilesEquals($expectedFilesPath, TEST_FILES_PATH . 'tmp'); } public function testPathCoverageForSourceWithoutNamespace(): void { - $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'PathCoverageForSourceWithoutNamespace'; + $expectedFilesPath = TEST_FILES_PATH . 'Report' . DIRECTORY_SEPARATOR . 'HTML' . DIRECTORY_SEPARATOR . 'PathCoverageForSourceWithoutNamespace'; $report = new Facade; - $report->process($this->getPathCoverageForSourceWithoutNamespace(), self::$TEST_TMP_PATH); + $report->process($this->getPathCoverageForSourceWithoutNamespace(), TEST_FILES_PATH . 'tmp'); - $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + $this->assertFilesEquals($expectedFilesPath, TEST_FILES_PATH . 'tmp'); } public function testForFileWithIgnoredLines(): void { - $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForFileWithIgnoredLines'; + $expectedFilesPath = TEST_FILES_PATH . 'Report' . DIRECTORY_SEPARATOR . 'HTML' . DIRECTORY_SEPARATOR . 'CoverageForFileWithIgnoredLines'; $report = new Facade; - $report->process($this->getCoverageForFileWithIgnoredLines(), self::$TEST_TMP_PATH); + $report->process($this->getCoverageForFileWithIgnoredLines(), TEST_FILES_PATH . 'tmp'); - $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + $this->assertFilesEquals($expectedFilesPath, TEST_FILES_PATH . 'tmp'); } public function testForClassWithAnonymousFunction(): void { - $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForClassWithAnonymousFunction'; + $expectedFilesPath = TEST_FILES_PATH . 'Report' . DIRECTORY_SEPARATOR . 'HTML' . DIRECTORY_SEPARATOR . 'CoverageForClassWithAnonymousFunction'; $report = new Facade; - $report->process($this->getCoverageForClassWithAnonymousFunction(), self::$TEST_TMP_PATH); + $report->process($this->getCoverageForClassWithAnonymousFunction(), TEST_FILES_PATH . 'tmp'); - $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + $this->assertFilesEquals($expectedFilesPath, TEST_FILES_PATH . 'tmp'); } private function assertFilesEquals(string $expectedFilesPath, string $actualFilesPath): void diff --git a/tests/tests/Report/PhpTest.php b/tests/tests/Report/PhpTest.php index 75c11b4ba..358e588a7 100644 --- a/tests/tests/Report/PhpTest.php +++ b/tests/tests/Report/PhpTest.php @@ -26,9 +26,9 @@ public function testPHPSerialisationProducesValidCode(): void $coverage = $this->getLineCoverageForBankAccount(); /* @noinspection UnusedFunctionResultInspection */ - (new PHP)->process($coverage, self::$TEST_TMP_PATH . '/serialized.php'); + (new PHP)->process($coverage, TEST_FILES_PATH . 'tmp/serialized.php'); - $unserialized = require self::$TEST_TMP_PATH . '/serialized.php'; + $unserialized = require TEST_FILES_PATH . 'tmp/serialized.php'; $this->assertEquals($coverage, $unserialized); } @@ -38,9 +38,9 @@ public function testPHPSerialisationProducesValidCodeWhenOutputIncludesSingleQuo $coverage = $this->getLineCoverageForFileWithEval(); /* @noinspection UnusedFunctionResultInspection */ - (new PHP)->process($coverage, self::$TEST_TMP_PATH . '/serialized.php'); + (new PHP)->process($coverage, TEST_FILES_PATH . 'tmp/serialized.php'); - $unserialized = require self::$TEST_TMP_PATH . '/serialized.php'; + $unserialized = require TEST_FILES_PATH . 'tmp/serialized.php'; $this->assertEquals($coverage, $unserialized); } @@ -53,12 +53,11 @@ public function testCacheDataNeverGetSaved(): void $coverage->getReport(); $refProperty = new ReflectionProperty($coverage, 'cachedReport'); - $refProperty->setAccessible(true); $this->assertNotNull($refProperty->getValue($coverage)); /* @noinspection UnusedFunctionResultInspection */ - (new PHP)->process($coverage, self::$TEST_TMP_PATH . '/serialized.php'); + (new PHP)->process($coverage, TEST_FILES_PATH . 'tmp/serialized.php'); $this->assertNull($refProperty->getValue($coverage)); } diff --git a/tests/tests/Report/XmlTest.php b/tests/tests/Report/XmlTest.php index 0ec8f2e40..53deb784e 100644 --- a/tests/tests/Report/XmlTest.php +++ b/tests/tests/Report/XmlTest.php @@ -31,7 +31,7 @@ protected function tearDown(): void { parent::tearDown(); - foreach (new FilesystemIterator(self::$TEST_TMP_PATH) as $path => $fileInfo) { + foreach (new FilesystemIterator(TEST_FILES_PATH . 'tmp') as $path => $fileInfo) { /* @var \SplFileInfo $fileInfo */ unlink($fileInfo->getPathname()); } @@ -42,9 +42,9 @@ public function testForBankAccountTest(): void $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForBankAccount'; $xml = new Facade('1.0.0'); - $xml->process($this->getLineCoverageForBankAccount(), self::$TEST_TMP_PATH); + $xml->process($this->getLineCoverageForBankAccount(), TEST_FILES_PATH . 'tmp'); - $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + $this->assertFilesEquals($expectedFilesPath, TEST_FILES_PATH . 'tmp'); } public function testForFileWithIgnoredLines(): void @@ -52,9 +52,9 @@ public function testForFileWithIgnoredLines(): void $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForFileWithIgnoredLines'; $xml = new Facade('1.0.0'); - $xml->process($this->getCoverageForFileWithIgnoredLines(), self::$TEST_TMP_PATH); + $xml->process($this->getCoverageForFileWithIgnoredLines(), TEST_FILES_PATH . 'tmp'); - $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + $this->assertFilesEquals($expectedFilesPath, TEST_FILES_PATH . 'tmp'); } public function testForClassWithAnonymousFunction(): void @@ -62,9 +62,9 @@ public function testForClassWithAnonymousFunction(): void $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForClassWithAnonymousFunction'; $xml = new Facade('1.0.0'); - $xml->process($this->getCoverageForClassWithAnonymousFunction(), self::$TEST_TMP_PATH); + $xml->process($this->getCoverageForClassWithAnonymousFunction(), TEST_FILES_PATH . 'tmp'); - $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + $this->assertFilesEquals($expectedFilesPath, TEST_FILES_PATH . 'tmp'); } private function assertFilesEquals(string $expectedFilesPath, string $actualFilesPath): void diff --git a/tests/tests/StaticAnalysis/Value/ClassTest.php b/tests/tests/StaticAnalysis/Value/ClassTest.php index 430c38156..cd83f153a 100644 --- a/tests/tests/StaticAnalysis/Value/ClassTest.php +++ b/tests/tests/StaticAnalysis/Value/ClassTest.php @@ -79,7 +79,16 @@ public function testMayUseTraits(): void public function testMayHaveMethods(): void { - $methods = [new Method('method', 0, 0, 'method(): void', Visibility::Public, 1)]; + $methods = [ + 'method' => new Method( + 'method', + 0, + 0, + 'method(): void', + Visibility::Public, + 1, + ), + ]; $this->assertSame($methods, $this->class(methods: $methods)->methods()); } diff --git a/tests/tests/StaticAnalysis/Value/InterfaceTest.php b/tests/tests/StaticAnalysis/Value/InterfaceTest.php index fda17b840..431d8f40b 100644 --- a/tests/tests/StaticAnalysis/Value/InterfaceTest.php +++ b/tests/tests/StaticAnalysis/Value/InterfaceTest.php @@ -46,7 +46,7 @@ public function testMayHaveParentInterfaces(): void { $interfaces = ['example\AnInterface']; - $this->assertSame($interfaces, $this->interface(parentInterfaces: $interfaces)->parentInterfaces()); + $this->assertSame($interfaces, $this->interface($interfaces)->parentInterfaces()); } /** diff --git a/tests/tests/StaticAnalysis/Value/TraitTest.php b/tests/tests/StaticAnalysis/Value/TraitTest.php index e33cecf2e..76773832f 100644 --- a/tests/tests/StaticAnalysis/Value/TraitTest.php +++ b/tests/tests/StaticAnalysis/Value/TraitTest.php @@ -44,9 +44,18 @@ public function testHasEndLine(): void public function testMayHaveMethods(): void { - $methods = [new Method('method', 0, 0, 'method(): void', Visibility::Public, 1)]; + $methods = [ + 'method' => new Method( + 'method', + 0, + 0, + 'method(): void', + Visibility::Public, + 1, + ), + ]; - $this->assertSame($methods, $this->trait(methods: $methods)->methods()); + $this->assertSame($methods, $this->trait($methods)->methods()); } /**