Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
TASK: Fix TestCase and Fixture Importer (#74)
Browse files Browse the repository at this point in the history
* TASK: Fix TestCase and Fixture Importer

* TASK: some review changes
  • Loading branch information
RobinLawinsky authored and kabarakh committed Oct 9, 2020
1 parent 7a965ee commit f5fee0f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
23 changes: 16 additions & 7 deletions Classes/Testing/FixtureFramework/DatabaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']));
Expand All @@ -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();
}

Expand Down
26 changes: 13 additions & 13 deletions Classes/Testing/FixtureFramework/Fixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -61,24 +61,24 @@ 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()
{
return $this->connection;
}

/**
* @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;
Expand All @@ -87,18 +87,18 @@ 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()
{
return $this->dataSet;
}

/**
* @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;
Expand All @@ -107,18 +107,18 @@ 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()
{
return $this->setUpOperation;
}

/**
* @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;
Expand Down
11 changes: 9 additions & 2 deletions Classes/Testing/FixtureFramework/FixtureImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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(),
Expand All @@ -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();
Expand Down

0 comments on commit f5fee0f

Please sign in to comment.