Skip to content

Commit

Permalink
DX: do not allow overriding constructor of `PHPUnit\Framework\TestCas…
Browse files Browse the repository at this point in the history
…e` (#7563)
  • Loading branch information
kubawerlos committed Dec 15, 2023
1 parent 4c57217 commit fd3b0a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
19 changes: 11 additions & 8 deletions tests/Smoke/InstallViaComposerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
final class InstallViaComposerTest extends AbstractSmokeTestCase
{
private Filesystem $fs;
private ?Filesystem $fs;

/** @var array<string, mixed> */
private array $currentCodeAsComposerDependency = [
Expand Down Expand Up @@ -64,13 +64,6 @@ final class InstallViaComposerTest extends AbstractSmokeTestCase
'vendor/bin/php-cs-fixer fix --help',
];

public function __construct()
{
$this->fs = new Filesystem();

parent::__construct();
}

public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
Expand Down Expand Up @@ -98,6 +91,16 @@ public static function setUpBeforeClass(): void
}
}

protected function setUp(): void
{
$this->fs = new Filesystem();
}

protected function tearDown(): void
{
$this->fs = null;
}

public function testInstallationViaPathIsPossible(): void
{
$tmpPath = $this->createFakeComposerProject($this->currentCodeAsComposerDependency);
Expand Down
10 changes: 10 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@
abstract class TestCase extends BaseTestCase
{
use ExpectDeprecationTrait;

final public function testNotDefiningConstructor(): void
{
$reflection = new \ReflectionObject($this);

self::assertNotSame(
$reflection->getConstructor()->getDeclaringClass()->getName(),
$reflection->getName(),
);
}
}

0 comments on commit fd3b0a2

Please sign in to comment.