Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Classes/Core/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ protected function setUp(): void
self::markTestSkipped('Functional tests must be called through phpunit on CLI');
}

$this->identifier = self::getInstanceIdentifier();
$this->instancePath = self::getInstancePath();
$this->identifier = $this->getInstanceIdentifier();
$this->instancePath = $this->getInstancePath();
putenv('TYPO3_PATH_ROOT=' . $this->instancePath);
putenv('TYPO3_PATH_APP=' . $this->instancePath);

Expand Down Expand Up @@ -1100,19 +1100,21 @@ protected function withDatabaseSnapshot(?callable $createCallback = null, ?calla
/**
* Uses a 7 char long hash of class name as identifier.
*
* @internal
* @return non-empty-string
*/
protected static function getInstanceIdentifier(): string
protected function getInstanceIdentifier(): string
{
return substr(sha1(static::class), 0, 7);
}

/**
* @internal
* @return non-empty-string
*/
protected static function getInstancePath(): string
protected function getInstancePath(): string
{
$identifier = self::getInstanceIdentifier();
$identifier = $this->getInstanceIdentifier();
return ORIGINAL_ROOT . 'typo3temp/var/tests/functional-' . $identifier;
}
}
73 changes: 73 additions & 0 deletions Tests/Unit/Core/Functional/FunctionalTestCaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace TYPO3\TestingFramework\Tests\Unit\Core\Functional;

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

use PHPUnit\Framework\Attributes\Test;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

class FunctionalTestCaseTest extends UnitTestCase
{
#[Test]
public function GetInstanceIdentifierAndGetInstancePathCanBeOverridden(): void
{
// Define ORIGINAL_ROOT constant if not already defined (needed by setUp)
if (!defined('ORIGINAL_ROOT')) {
define('ORIGINAL_ROOT', dirname(__DIR__, 5));
}

// Anonymous subclass to test method overrides in setUp() method calling:
// $this->identifier = $this->getInstanceIdentifier();
$testInstance = new class ('overriddenGetInstanceIdentifierAndGetInstancePathMethods') extends FunctionalTestCase {
protected function getInstanceIdentifier(): string
{
return 'test_identifier_from_subclass_xyz';
}

protected function getInstancePath(): string
{
return parent::getInstancePath() . '/suffix_from_subclass_xyz';
}

public function getIdentifier(): string
{
return $this->identifier;
}

public function getInstancePathProperty(): string
{
return $this->instancePath;
}

public function setUp(): void
{
try {
parent::setUp();
} catch (\Throwable) {

}
}
};
$testInstance->setUp();

// The key assertions: values must contain the subclass overrides,
// proving that methods can be properly overridden in subclasses
self::assertSame('test_identifier_from_subclass_xyz', $testInstance->getIdentifier());
self::assertStringEndsWith('/suffix_from_subclass_xyz', $testInstance->getInstancePathProperty());
}
}