Skip to content

Commit

Permalink
Merge pull request #179 from bnf/functionals-getContainer
Browse files Browse the repository at this point in the history
[TASK] Provide container instance in functional tests
  • Loading branch information
bmack authored May 12, 2020
2 parents 970fb83 + 8af31d3 commit 7b920e0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
21 changes: 19 additions & 2 deletions Classes/Core/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use PHPUnit\Util\PHP\AbstractPhpProcess;
use Psr\Container\ContainerInterface;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Cache\Backend\NullBackend;
use TYPO3\CMS\Core\Core\Bootstrap;
Expand Down Expand Up @@ -218,6 +219,11 @@ abstract class FunctionalTestCase extends BaseTestCase
*/
protected $backendUserFixture = 'PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/be_users.xml';

/**
* @var ContainerInterface
*/
private $container;

/**
* This internal variable tracks if the given test is the first test of
* that test case. This variable is set to current calling test case class.
Expand Down Expand Up @@ -263,7 +269,7 @@ protected function setUp(): void
// Reusing an existing instance. This typically happens for the second, third, ... test
// in a test case, so environment is set up only once per test case.
GeneralUtility::purgeInstances();
$testbase->setUpBasicTypo3Bootstrap($this->instancePath);
$this->container = $testbase->setUpBasicTypo3Bootstrap($this->instancePath);
$testbase->initializeTestDatabaseAndTruncateTables();
Bootstrap::initializeBackendRouter();
$testbase->loadExtensionTables();
Expand Down Expand Up @@ -327,7 +333,7 @@ protected function setUp(): void
$this->testExtensionsToLoad,
$this->frameworkExtensionsToLoad
);
$testbase->setUpBasicTypo3Bootstrap($this->instancePath);
$this->container = $testbase->setUpBasicTypo3Bootstrap($this->instancePath);
if ($dbDriver !== 'pdo_sqlite') {
$testbase->setUpTestDatabase($dbName, $originalDatabaseName);
} else {
Expand All @@ -347,6 +353,17 @@ protected function getConnectionPool()
return GeneralUtility::makeInstance(ConnectionPool::class);
}

/**
* @return ContainerInterface
*/
protected function getContainer(): ContainerInterface
{
if (!$this->container instanceof ContainerInterface) {
throw new \RuntimeException('Please invoke parent::setUp() before calling getContainer().', 1589221777);
}
return $this->container;
}

/**
* Initialize backend user
*
Expand Down
9 changes: 6 additions & 3 deletions Classes/Core/Testbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Psr\Container\ContainerInterface;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Core\ClassLoadingInformation;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
Expand Down Expand Up @@ -562,9 +563,9 @@ public function setUpTestDatabase(string $databaseName, string $originalDatabase
* For functional and acceptance tests.
*
* @param string $instancePath Absolute path to test instance
* @return void
* @return ContainerInterface
*/
public function setUpBasicTypo3Bootstrap($instancePath)
public function setUpBasicTypo3Bootstrap($instancePath): ContainerInterface
{
$_SERVER['PWD'] = $instancePath;
$_SERVER['argv'][0] = 'index.php';
Expand All @@ -575,12 +576,14 @@ public function setUpBasicTypo3Bootstrap($instancePath)

$classLoader = require __DIR__ . '/../../../../autoload.php';
SystemEnvironmentBuilder::run(0, SystemEnvironmentBuilder::REQUESTTYPE_BE | SystemEnvironmentBuilder::REQUESTTYPE_CLI);
Bootstrap::init($classLoader);
$container = Bootstrap::init($classLoader);
// Make sure output is not buffered, so command-line output can take place and
// phpunit does not whine about changed output bufferings in tests.
ob_end_clean();

$this->dumpClassLoadingInformation();

return $container;
}

/**
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"require": {
"phpunit/phpunit": "^8.4 || ^9.0",
"psr/container": "^1.0",
"mikey179/vfsstream": "~1.6.8",
"typo3fluid/fluid": "^2.5|^3",
"typo3/cms-core": "10.*.*@dev",
Expand Down

0 comments on commit 7b920e0

Please sign in to comment.