Skip to content

Commit

Permalink
[CS] Added FileHandling (Teardown) to TestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Jan 26, 2025
1 parent ca0ac18 commit c0716e0
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,37 @@

class TestCase extends PhpUnitTestCase
{
/**
* Registered files
*
* @var array<string>
*/
private $registeredFiles = [];

/**
* @inheritDoc
*/
protected function setUp(): void
{
parent::setUp();

$this->registeredFiles = [];
}

/**
* @inheritDoc
*/
protected function tearDown(): void
{
foreach ($this->registeredFiles as $registeredFile) {
if (file_exists($registeredFile)) {
@unlink($registeredFile);
}
}

parent::tearDown();
}

/**
* Expect notice on php version smaller than 8
* Expect warning on php version greater or equal than 8
Expand Down Expand Up @@ -119,4 +150,15 @@ public function invokePrivateMethodFromObject($object, string $methodName, ...$a
$method = $this->getPrivateMethodFromObject($object, $methodName);
return $method->invoke($object, ...$args);
}

/**
* Register a file for teardown
*
* @param string $filename
* @return void
*/
protected function registerFileForTeardown(string $filename): void
{
$this->registeredFiles[] = $filename;
}
}

0 comments on commit c0716e0

Please sign in to comment.