Skip to content

Commit d14fd9f

Browse files
committed
[TASK] Enable late static binding in FunctionalTestCase for worker-specific test isolation
Replace self:: with static:: for getInstanceIdentifier() and getInstancePath() to allow subclasses to override these methods for proper test isolation in parallel execution (Paratest). Closes: #708
1 parent dfc296e commit d14fd9f

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

Classes/Core/Functional/FunctionalTestCase.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@ protected function setUp(): void
284284
self::markTestSkipped('Functional tests must be called through phpunit on CLI');
285285
}
286286

287-
$this->identifier = self::getInstanceIdentifier();
288-
$this->instancePath = self::getInstancePath();
287+
// keep the static:: binding to allow method overrides in subclasses.
288+
$this->identifier = static::getInstanceIdentifier();
289+
$this->instancePath = static::getInstancePath();
289290
putenv('TYPO3_PATH_ROOT=' . $this->instancePath);
290291
putenv('TYPO3_PATH_APP=' . $this->instancePath);
291292

@@ -1112,7 +1113,8 @@ protected static function getInstanceIdentifier(): string
11121113
*/
11131114
protected static function getInstancePath(): string
11141115
{
1115-
$identifier = self::getInstanceIdentifier();
1116+
// keep the static:: binding to allow method overrides in subclasses.
1117+
$identifier = static::getInstanceIdentifier();
11161118
return ORIGINAL_ROOT . 'typo3temp/var/tests/functional-' . $identifier;
11171119
}
11181120
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TYPO3\TestingFramework\Tests\Unit\Core\Functional;
6+
7+
/*
8+
* This file is part of the TYPO3 CMS project.
9+
*
10+
* It is free software; you can redistribute it and/or modify it under
11+
* the terms of the GNU General Public License, either version 2
12+
* of the License, or any later version.
13+
*
14+
* For the full copyright and license information, please read the
15+
* LICENSE.txt file that was distributed with this source code.
16+
*
17+
* The TYPO3 project - inspiring people to share!
18+
*/
19+
20+
use PHPUnit\Framework\Attributes\Test;
21+
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
22+
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23+
24+
class FunctionalTestCaseTest extends UnitTestCase
25+
{
26+
#[Test]
27+
public function GetInstanceIdentifierAndGetInstancePathCanBeOverridden(): void
28+
{
29+
// Define ORIGINAL_ROOT constant if not already defined (needed by setUp)
30+
if (!defined('ORIGINAL_ROOT')) {
31+
define('ORIGINAL_ROOT', dirname(__DIR__, 5));
32+
}
33+
34+
// Anonymous subclass to test static binding in setUp() method calling:
35+
// $this->identifier = static::getInstanceIdentifier();
36+
$testInstance = new class ('overriddenGetInstanceIdentifierAndGetInstancePathMethods') extends FunctionalTestCase {
37+
protected static function getInstanceIdentifier(): string
38+
{
39+
return 'test_identifier_from_subclass_xyz';
40+
}
41+
42+
protected static function getInstancePath(): string
43+
{
44+
return parent::getInstancePath() . '/suffix_from_subclass_xyz';
45+
}
46+
47+
public function getIdentifier(): string
48+
{
49+
return $this->identifier;
50+
}
51+
52+
public function getInstancePathProperty(): string
53+
{
54+
return $this->instancePath;
55+
}
56+
57+
public function setUp(): void
58+
{
59+
try {
60+
parent::setUp();
61+
} catch (\Throwable) {
62+
63+
}
64+
}
65+
};
66+
$testInstance->setUp();
67+
68+
// The key assertions: values must contain the subclass overrides,
69+
// proving that static:: binding was used (not self::)
70+
self::assertSame('test_identifier_from_subclass_xyz', $testInstance->getIdentifier());
71+
self::assertStringEndsWith('/suffix_from_subclass_xyz', $testInstance->getInstancePathProperty());
72+
}
73+
}

0 commit comments

Comments
 (0)