From f5fee0fe631b64db1ebee9e18045c34010565c87 Mon Sep 17 00:00:00 2001 From: RobinLawinsky <49674116+RobinLawinsky@users.noreply.github.com> Date: Fri, 9 Oct 2020 15:19:25 +0200 Subject: [PATCH] TASK: Fix TestCase and Fixture Importer (#74) * TASK: Fix TestCase and Fixture Importer * TASK: some review changes --- .../FixtureFramework/DatabaseTestCase.php | 23 +++++++++++----- Classes/Testing/FixtureFramework/Fixture.php | 26 +++++++++---------- .../FixtureFramework/FixtureImporter.php | 11 ++++++-- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/Classes/Testing/FixtureFramework/DatabaseTestCase.php b/Classes/Testing/FixtureFramework/DatabaseTestCase.php index a02a653d..624020c6 100755 --- a/Classes/Testing/FixtureFramework/DatabaseTestCase.php +++ b/Classes/Testing/FixtureFramework/DatabaseTestCase.php @@ -24,7 +24,12 @@ * * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ + +use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Object\Container\Container as ExtbaseContainer; +use TYPO3\CMS\Extbase\Object\ObjectManager; +use TYPO3\TestingFramework\Core\Testbase; /** * Database Test Case @@ -71,9 +76,9 @@ abstract class Tx_PtExtbase_Testing_FixtureFramework_DatabaseTestCase extends \P * * @return void */ - protected function setUp() + protected function setUp(): void { - if (!(in_array(GeneralUtility::getApplicationContext(), $this->allowedApplicationContexts) + if (!(in_array(Environment::getContext(), $this->allowedApplicationContexts) || in_array($_SERVER['HOSTNAME'], $this->allowedDomains) || in_array($_SERVER['HTTP_HOST'], $this->allowedDomains))) { $this->fail(sprintf('This test is only allowed in contexts "%s" used %s or on domains "%s" used %s', implode(', ', $this->allowedApplicationContexts), GeneralUtility::getApplicationContext(), implode(', ', $this->allowedDomains), $_SERVER['HOSTNAME'] . ' ' . $_SERVER['HTTP_HOST'])); @@ -85,13 +90,17 @@ protected function setUp() /** * Injects an untainted clone of the object manager and all its referencing * objects for every test. - * - * @return void + * @throws Throwable */ - public function runBare() + public function runBare(): void { - $objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager'); - $this->objectManager = clone $objectManager; + $instancePath = Environment::getCurrentScript(); + $testbase = new Testbase(); + $container = $testbase->setUpBasicTypo3Bootstrap($instancePath); + $extbaseContainer = GeneralUtility::getContainer()->get(ExtbaseContainer::class); + + $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class, $container, $extbaseContainer); + parent::runBare(); } diff --git a/Classes/Testing/FixtureFramework/Fixture.php b/Classes/Testing/FixtureFramework/Fixture.php index 3fe3b39b..ceddec06 100755 --- a/Classes/Testing/FixtureFramework/Fixture.php +++ b/Classes/Testing/FixtureFramework/Fixture.php @@ -39,17 +39,17 @@ class Tx_PtExtbase_Testing_FixtureFramework_Fixture protected $credentials; /** - * @var \PHPUnit\DbUnit\Database\Connection + * @var \PunktDe\Testing\Forked\DbUnit\Database\Connection */ protected $connection; /** - * @var \PHPUnit\DbUnit\DataSet\IDataSet + * @var \PunktDe\Testing\Forked\DbUnit\DataSet\IDataSet */ protected $dataSet; /** - * @var \PHPUnit\DbUnit\Operation\Operation + * @var \PunktDe\Testing\Forked\DbUnit\Operation\Operation */ protected $setUpOperation; @@ -61,13 +61,13 @@ class Tx_PtExtbase_Testing_FixtureFramework_Fixture public function __construct() { - $this->setUpOperation = \PHPUnit\DbUnit\Operation\Factory::CLEAN_INSERT(); + $this->setUpOperation = \PunktDe\Testing\Forked\DbUnit\Operation\Factory::CLEAN_INSERT(); } /** * Returns the test database connection. * - * @return \PHPUnit\DbUnit\Database\Connection + * @return \PunktDe\Testing\Forked\DbUnit\Database\Connection */ public function getConnection() { @@ -75,10 +75,10 @@ public function getConnection() } /** - * @param \PHPUnit\DbUnit\Database\Connection $connection + * @param \PunktDe\Testing\Forked\DbUnit\Database\Connection $connection * @return Tx_PtExtbase_Testing_FixtureFramework_Fixture */ - public function setConnection(\PHPUnit\DbUnit\Database\Connection $connection) + public function setConnection(\PunktDe\Testing\Forked\DbUnit\Database\Connection $connection) { $this->connection = $connection; return $this; @@ -87,7 +87,7 @@ public function setConnection(\PHPUnit\DbUnit\Database\Connection $connection) /** * Returns the test dataset. * - * @return \PHPUnit\DbUnit\DataSet\IDataSet + * @return \PunktDe\Testing\Forked\DbUnit\DataSet\IDataSet */ public function getDataSet() { @@ -95,10 +95,10 @@ public function getDataSet() } /** - * @param \PHPUnit\DbUnit\DataSet\IDataSet $dataSet + * @param \PunktDe\Testing\Forked\DbUnit\DataSet\IDataSet $dataSet * @return Tx_PtExtbase_Testing_FixtureFramework_Fixture */ - public function setDataSet(\PHPUnit\DbUnit\DataSet\IDataSet $dataSet) + public function setDataSet(\PunktDe\Testing\Forked\DbUnit\DataSet\IDataSet $dataSet) { $this->dataSet = $dataSet; return $this; @@ -107,7 +107,7 @@ public function setDataSet(\PHPUnit\DbUnit\DataSet\IDataSet $dataSet) /** * Returns the database operation executed in test setup. * - * @return \PHPUnit\DbUnit\Operation\Operation + * @return \PunktDe\Testing\Forked\DbUnit\Operation\Operation */ public function getSetUpOperation() { @@ -115,10 +115,10 @@ public function getSetUpOperation() } /** - * @param \PHPUnit\DbUnit\Operation\Operation $setUpOperation + * @param \PunktDe\Testing\Forked\DbUnit\Operation\Operation $setUpOperation * @return Tx_PtExtbase_Testing_FixtureFramework_Fixture */ - public function setSetUpOperation(\PHPUnit\DbUnit\Operation\Operation $setUpOperation) + public function setSetUpOperation(\PunktDe\Testing\Forked\DbUnit\Operation\Operation $setUpOperation) { $this->setUpOperation = $setUpOperation; return $this; diff --git a/Classes/Testing/FixtureFramework/FixtureImporter.php b/Classes/Testing/FixtureFramework/FixtureImporter.php index c5bb320f..b788ba3a 100755 --- a/Classes/Testing/FixtureFramework/FixtureImporter.php +++ b/Classes/Testing/FixtureFramework/FixtureImporter.php @@ -25,6 +25,9 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use PunktDe\PtExtbase\Utility\Files; +use TYPO3\CMS\Core\Core\Environment; + /** * FixtureImporter * @@ -66,7 +69,7 @@ public function import($fixtures) protected function setConnection() { $this->fixture->setConnection( - new \PHPUnit\DbUnit\Database\DefaultConnection( + new \PunktDe\Testing\Forked\DbUnit\Database\DefaultConnection( new PDO( $this->fixture->getCredentials()->getDsn(), $this->fixture->getCredentials()->getUsername(), @@ -85,7 +88,11 @@ protected function setConnection() protected function importSchema() { if ($this->fixture->getSchemaFilePath() != '') { - $schemaFilePath = PATH_site . $this->fixture->getSchemaFilePath(); + + $schemaFilePath = Files::concatenatePaths([ + Environment::getPublicPath(), + $this->fixture->getSchemaFilePath() + ]); if (file_exists($schemaFilePath)) { $command[] = 'mysql'; $command[] = '-h ' . $this->fixture->getCredentials()->getHostname();