Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 9, 2024
1 parent b22cb52 commit e0ea704
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 55 deletions.
15 changes: 3 additions & 12 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
41 changes: 15 additions & 26 deletions tests/tests/Report/Html/EndToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,73 +20,62 @@

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
{
$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
Expand Down
11 changes: 5 additions & 6 deletions tests/tests/Report/PhpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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));
}
Expand Down
14 changes: 7 additions & 7 deletions tests/tests/Report/XmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -42,29 +42,29 @@ 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
{
$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
{
$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
Expand Down
11 changes: 10 additions & 1 deletion tests/tests/StaticAnalysis/Value/ClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/StaticAnalysis/Value/InterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
13 changes: 11 additions & 2 deletions tests/tests/StaticAnalysis/Value/TraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit e0ea704

Please sign in to comment.