Skip to content

Commit be87dc5

Browse files
committed
[TASK] Make getInstanceIdentifier() and getInstancePath() non-static for overridability
Convert protected static methods to protected instance methods and mark as @internal. This allows subclasses to override these methods for proper test isolation in parallel execution (Paratest), without making them part of the public API. Instead of using static:: binding, use $this-> for natural method overriding. Solves the need for test isolation in single-test-level parallelization while signaling that these are internal implementation details. Relates to: #708
1 parent dfc296e commit be87dc5

2 files changed

Lines changed: 80 additions & 5 deletions

File tree

Classes/Core/Functional/FunctionalTestCase.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ 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+
$this->identifier = $this->getInstanceIdentifier();
288+
$this->instancePath = $this->getInstancePath();
289289
putenv('TYPO3_PATH_ROOT=' . $this->instancePath);
290290
putenv('TYPO3_PATH_APP=' . $this->instancePath);
291291

@@ -1100,19 +1100,21 @@ protected function withDatabaseSnapshot(?callable $createCallback = null, ?calla
11001100
/**
11011101
* Uses a 7 char long hash of class name as identifier.
11021102
*
1103+
* @internal
11031104
* @return non-empty-string
11041105
*/
1105-
protected static function getInstanceIdentifier(): string
1106+
protected function getInstanceIdentifier(): string
11061107
{
11071108
return substr(sha1(static::class), 0, 7);
11081109
}
11091110

11101111
/**
1112+
* @internal
11111113
* @return non-empty-string
11121114
*/
1113-
protected static function getInstancePath(): string
1115+
protected function getInstancePath(): string
11141116
{
1115-
$identifier = self::getInstanceIdentifier();
1117+
$identifier = $this->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 method overrides in setUp() method calling:
35+
// $this->identifier = $this->getInstanceIdentifier();
36+
$testInstance = new class ('overriddenGetInstanceIdentifierAndGetInstancePathMethods') extends FunctionalTestCase {
37+
protected function getInstanceIdentifier(): string
38+
{
39+
return 'test_identifier_from_subclass_xyz';
40+
}
41+
42+
protected 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 methods can be properly overridden in subclasses
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)