Skip to content

Commit

Permalink
Fix truncate table feature and reenable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sirdiego committed Jan 15, 2020
1 parent 7244ac3 commit e43b88a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
16 changes: 16 additions & 0 deletions Classes/Migration/DatabaseConnection.php
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace HDNET\Importr\Migration;

use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class DatabaseConnection implements DatabaseConnectionMigrationInterface
{
public function exec_TRUNCATEquery($table)
{
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$connection = $connectionPool->getConnectionForTable($table);
$connection->truncate($table);
}
}
8 changes: 8 additions & 0 deletions Classes/Migration/DatabaseConnectionMigrationInterface.php
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace HDNET\Importr\Migration;

interface DatabaseConnectionMigrationInterface
{
public function exec_TRUNCATEquery($table);
}
10 changes: 9 additions & 1 deletion Classes/Service/DatabaseService.php
Expand Up @@ -5,16 +5,24 @@

namespace HDNET\Importr\Service;

use HDNET\Importr\Migration\DatabaseConnection;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;

/**
* DatabaseService
*/
class DatabaseService
{
/**
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
* @return \TYPO3\CMS\Core\Database\DatabaseConnection|\HDNET\Importr\Migration\DatabaseConnectionMigrationInterface
*/
public function getDatabaseConnection()
{
if (VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getNumericTypo3Version()) > 9005000) {
return GeneralUtility::makeInstance(DatabaseConnection::class);
}

return $GLOBALS['TYPO3_DB'];
}
}
12 changes: 3 additions & 9 deletions Tests/Unit/Feature/TruncateTableTest.php
Expand Up @@ -6,9 +6,9 @@
namespace HDNET\Importr\Tests\Unit\Feature;

use HDNET\Importr\Feature\TruncateTable;
use HDNET\Importr\Migration\DatabaseConnectionMigrationInterface;
use HDNET\Importr\Processor\Configuration;
use HDNET\Importr\Service\DatabaseService;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Tests\UnitTestCase;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
Expand All @@ -24,13 +24,13 @@ class TruncateTableTest extends UnitTestCase
protected $fixture;

/**
* @var DatabaseConnection|\PHPUnit_Framework_MockObject_MockObject
* @var DatabaseConnectionMigrationInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $connection;

public function setUp()
{
$connection = $this->getMockBuilder(DatabaseConnection::class)->getMock();
$connection = $this->getMockBuilder(DatabaseConnectionMigrationInterface::class)->getMock();
$this->connection = $connection;
$databaseService = $this->getMockBuilder(DatabaseService::class)->getMock();
$databaseService->expects($this->any())->method('getDatabaseConnection')->will($this->returnValue($connection));
Expand All @@ -42,8 +42,6 @@ public function setUp()
*/
public function do_not_truncate_when_not_configured()
{
$this->markTestSkipped('Migrate truncate to doctrine');

$processor = $this->getMockBuilder(Configuration::class)->disableOriginalConstructor()->getMock();
$this->connection->expects($this->never())->method('exec_TRUNCATEquery');

Expand All @@ -55,8 +53,6 @@ public function do_not_truncate_when_not_configured()
*/
public function truncate_when_configured()
{
$this->markTestSkipped('Migrate truncate to doctrine');

$processor = $this->getMockBuilder(Configuration::class)->disableOriginalConstructor()->getMock();

$this->connection->expects($this->once())->method('exec_TRUNCATEquery');
Expand All @@ -69,8 +65,6 @@ public function truncate_when_configured()
*/
public function truncate_multiple_tables_when_configured()
{
$this->markTestSkipped('Migrate truncate to doctrine');

$configuration = [
'truncate' => [
'test',
Expand Down

0 comments on commit e43b88a

Please sign in to comment.