Skip to content

Commit

Permalink
Added tests for DB gateway service
Browse files Browse the repository at this point in the history
  • Loading branch information
vidarl committed Oct 9, 2018
1 parent 0475d7e commit 86347ff
Show file tree
Hide file tree
Showing 9 changed files with 1,034 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bundle/Command/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public function getContentTypeIds($contentTypeIdentifiers)
return $result;
}

/**
* @param $dryRun
* @param OutputInterface $output
* @return int Number of field definitions which was converted
*/
public function convertFieldDefinitions($dryRun, OutputInterface $output)
{
$query = $this->dbal->createQueryBuilder();
Expand Down Expand Up @@ -85,6 +90,7 @@ public function convertFieldDefinitions($dryRun, OutputInterface $output)
}

$output->writeln("Converted $count ezxmltext field definitions to ezrichtext");
return $count;
}

public function getRowCountOfContentObjectAttributes($datatypeString, $contentId)
Expand Down
27 changes: 27 additions & 0 deletions phpunit-integration-legacy-empty-db.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version = '1.0' encoding = 'utf-8'?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./tests/bootstrap.php"
processIsolation="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
colors="true">
<php>
<env name="setupFactory" value="EzSystems\EzPlatformXmlTextFieldType\Tests\SetupFactory\LegacyEmptyDBSetupFactory" />
<env name="backendVersion" value="5" />
<env name="fixtureDir" value="Legacy" />
</php>
<testsuites>
<testsuite name="Command Gateway">
<directory suffix="Test.php">./tests/bundle/Command/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./bundle</directory>
<directory>./lib</directory>
<directory>./vendor</directory>
</whitelist>
</filter>
</phpunit>
84 changes: 84 additions & 0 deletions tests/bundle/Command/BaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* This file is part of the eZ Platform XmlText Field Type package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*
* @version //autogentag//
*/
namespace EzSystems\EzPlatformXmlTextFieldTypeBundle\Tests\Command;

use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest;

abstract class BaseTest extends APIBaseTest
{
/**
* Taken from ezpublish-kernel/eZ/Publish/Core/Persistence/Legacy/Tests/TestCase.php
*
* @param $file
* @throws \Exception
*/
protected function insertDatabaseFixture($file)
{
$data = require $file;
$db = $this->getSetupFactory()->getDatabaseHandler();

foreach ($data as $table => $rows) {
// Check that at least one row exists
if (!isset($rows[0])) {
continue;
}

$q = $db->createInsertQuery();
$q->insertInto($db->quoteIdentifier($table));

// Contains the bound parameters
$values = array();

// Binding the parameters
foreach ($rows[0] as $col => $val) {
$q->set(
$db->quoteIdentifier($col),
$q->bindParam($values[$col])
);
}

$stmt = $q->prepare();

foreach ($rows as $row) {
try {
// This CANNOT be replaced by:
// $values = $row
// each $values[$col] is a PHP reference which should be
// kept for parameters binding to work
foreach ($row as $col => $val) {
$values[$col] = $val;
}

$stmt->execute();
} catch (Exception $e) {
echo "$table ( ", implode(', ', $row), " )\n";
throw $e;
}
}
}

$this->resetSequences();
}

public function resetSequences()
{
switch ($this->getDB()) {
case 'pgsql':
// Update PostgreSQL sequences
$handler = $this->getSetupFactory()->getDatabaseHandler();

$queries = array_filter(preg_split('(;\\s*$)m',
file_get_contents(__DIR__ . '/_fixtures/setval.pgsql.sql')));
foreach ($queries as $query) {
$handler->exec($query);
}
}
}
}
Loading

0 comments on commit 86347ff

Please sign in to comment.