-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor unsetting tests during TestSuite::run, for even faster destr…
…uction of instances. - Continuing on the destruction fix: The iterator also holds the array of tests. For tests with dataProviders, this results in not immediately destructing each Test, but only when the deeper TestSuite is done. - Refactored cleanup tricks: Just do a first loop so we no longer need properties nor the iterator, and then array_shift as we go. - Added test coverage.
- Loading branch information
1 parent
8afb89b
commit 541fd37
Showing
2 changed files
with
58 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tests/unit/Framework/TestSuiteRunDestructsTestCaseTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\Framework; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Depends; | ||
use PHPUnit\Framework\Attributes\Small; | ||
use PHPUnit\Framework\Attributes\TestWith; | ||
|
||
#[CoversClass(TestSuite::class)] | ||
#[Small] | ||
final class TestSuiteRunDestructsTestCaseTest extends TestCase | ||
{ | ||
private static int $destructsDone = 0; | ||
|
||
public function __destruct() | ||
{ | ||
self::$destructsDone++; | ||
} | ||
|
||
public function testFirstTest(): void | ||
{ | ||
$this->assertSame(0, self::$destructsDone); | ||
} | ||
|
||
#[Depends('testFirstTest')] | ||
public function testSecondTest(): void | ||
{ | ||
$this->assertSame(1, self::$destructsDone); | ||
} | ||
|
||
#[Depends('testSecondTest')] | ||
#[TestWith([2])] | ||
#[TestWith([3])] | ||
#[TestWith([4])] | ||
public function testThirdTestWhichUsesDataProvider($numberOfTestsBeforeThisOne): void | ||
{ | ||
$this->assertSame($numberOfTestsBeforeThisOne, self::$destructsDone); | ||
} | ||
} |