-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgraded package to be compatible with eZ Platform v3.0 (#119)
* EZP-31512: Fixed extracting text from RichText for no child nodes * [CS] Disabled native_function_invocation php-cs-fixer rule * [Tests] Upgraded test setup to rely on Doctrine instead of eZc Database * Delegated importing test fixtures to eZ Platform Kernel FixtureImporter. * Replaced usages of eZc Database Handler with Doctrine Connection. * Aligned CS to follow eZ Platform Code Style. * Replaced usages of PDO::FETCH_* with Doctrine FetchMode * [SF5] Replaced ContextErrorException with ErrorException ContextErrorException was dropped in Symfony 4.0 in favor of the native \ErrorException * Update README.md Co-authored-by: André R <[email protected]>
- Loading branch information
Showing
11 changed files
with
146 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,31 @@ | ||
<?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. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformXmlTextFieldType\Tests\FieldType\Persistence\Legacy; | ||
|
||
use Doctrine\DBAL\DBALException; | ||
use ErrorException; | ||
use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; | ||
use eZ\Publish\SPI\Tests\Persistence\FileFixtureFactory; | ||
use eZ\Publish\SPI\Tests\Persistence\FixtureImporter; | ||
|
||
abstract class BaseTest extends APIBaseTest | ||
{ | ||
/** | ||
* Taken from ezplatform-kernel/eZ/Publish/Core/Persistence/Legacy/Tests/TestCase.php. | ||
* | ||
* @param string $file | ||
* @throws \Exception | ||
*/ | ||
protected function insertDatabaseFixture($file) | ||
protected function insertDatabaseFixture(string $file): void | ||
{ | ||
$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 = []; | ||
|
||
// 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); | ||
} | ||
try { | ||
$fixtureImporter = new FixtureImporter($this->getRawDatabaseConnection()); | ||
$fixtureImporter->import((new FileFixtureFactory())->buildFixture($file)); | ||
} catch (ErrorException | DBALException $e) { | ||
self::fail('Database fixture import failed: ' . $e->getMessage()); | ||
} | ||
} | ||
} |
Oops, something went wrong.