From 37cbc4b3f34f74653c5d3365dd0361e47deb2194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 21 Jun 2025 14:28:41 -0300 Subject: [PATCH] Extract dependencies from Transformations class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- app/services.php | 3 +- phpstan-baseline.neon | 9 --- psalm-baseline.xml | 5 -- src/Database/MultiTableQuery.php | 2 +- src/Display/Results.php | 2 +- src/Plugins/Export/Helpers/Pdf.php | 5 +- src/Plugins/ExportPlugin.php | 2 +- src/Plugins/Schema/Pdf/PdfRelationSchema.php | 11 +-- src/Transformations.php | 66 +++++++++-------- src/Twig/TransformationsExtension.php | 12 +--- .../AddNewPrimaryControllerTest.php | 3 +- .../CreateNewColumnControllerTest.php | 3 +- .../FirstStepControllerTest.php | 3 +- .../FourthStepControllerTest.php | 3 +- .../SecondStepControllerTest.php | 3 +- .../ThirdStepControllerTest.php | 3 +- .../GetColumnsControllerTest.php | 3 +- .../Normalization/MoveRepeatingGroupTest.php | 3 +- .../PartialDependenciesControllerTest.php | 3 +- .../CreateNewTablesControllerTest.php | 3 +- .../FirstStepControllerTest.php | 3 +- .../NewTablesControllerTest.php | 3 +- .../CreateNewTablesControllerTest.php | 3 +- .../FirstStepControllerTest.php | 3 +- .../NewTablesControllerTest.php | 3 +- .../Databases/DestroyControllerTest.php | 5 +- .../Table/AddFieldControllerTest.php | 2 +- .../Table/ChangeControllerTest.php | 22 +++++- .../Table/CreateControllerTest.php | 2 +- .../Table/DeleteRowsControllerTest.php | 2 +- .../Table/ReplaceControllerTest.php | 2 +- .../Table/SearchControllerTest.php | 2 +- .../Table/Structure/ChangeControllerTest.php | 3 +- .../Table/Structure/SaveControllerTest.php | 10 +-- .../Table/StructureControllerTest.php | 2 +- .../Transformation/OverviewControllerTest.php | 7 +- tests/unit/Display/ResultsTest.php | 2 +- tests/unit/Export/ExportTest.php | 20 +++--- tests/unit/InsertEditTest.php | 70 +++++++++++-------- tests/unit/NormalizationTest.php | 8 ++- .../unit/Plugins/Export/ExportCodegenTest.php | 7 +- tests/unit/Plugins/Export/ExportCsvTest.php | 7 +- tests/unit/Plugins/Export/ExportExcelTest.php | 7 +- .../Plugins/Export/ExportHtmlwordTest.php | 16 +++-- tests/unit/Plugins/Export/ExportJsonTest.php | 7 +- tests/unit/Plugins/Export/ExportLatexTest.php | 15 ++-- .../Plugins/Export/ExportMediawikiTest.php | 7 +- tests/unit/Plugins/Export/ExportOdsTest.php | 7 +- tests/unit/Plugins/Export/ExportOdtTest.php | 18 ++--- tests/unit/Plugins/Export/ExportPdfTest.php | 7 +- .../Plugins/Export/ExportPhparrayTest.php | 7 +- tests/unit/Plugins/Export/ExportSqlTest.php | 11 ++- .../Plugins/Export/ExportTexytextTest.php | 12 ++-- tests/unit/Plugins/Export/ExportXmlTest.php | 7 +- tests/unit/Plugins/Export/ExportYamlTest.php | 7 +- tests/unit/PluginsTest.php | 27 ++----- tests/unit/SqlTest.php | 2 +- tests/unit/Table/ColumnsDefinitionTest.php | 2 +- tests/unit/TransformationsTest.php | 6 +- 59 files changed, 248 insertions(+), 252 deletions(-) diff --git a/app/services.php b/app/services.php index 91cfbdf481..93613d1d93 100644 --- a/app/services.php +++ b/app/services.php @@ -219,7 +219,8 @@ return [ 'class' => TrackingChecker::class, 'arguments' => ['$dbi' => '@dbi', '$relation' => '@relation'], ], - 'transformations' => ['class' => Transformations::class], + 'transformations' => ['class' => Transformations::class, 'arguments' => ['@dbi', '@relation']], + Transformations::class => 'transformations', 'triggers' => ['class' => Triggers::class, 'arguments' => ['@dbi']], 'user_password' => [ 'class' => UserPassword::class, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0eafd89fc2..8bab657995 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -14967,15 +14967,6 @@ parameters: count: 1 path: src/Tracking/Tracking.php - - - message: ''' - #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Dbal\\DatabaseInterface\: - Use dependency injection instead\.$# - ''' - identifier: staticMethod.deprecated - count: 3 - path: src/Transformations.php - - message: '#^Loose comparison via "\!\=" is not allowed\.$#' identifier: notEqual.notAllowed diff --git a/psalm-baseline.xml b/psalm-baseline.xml index b3882c098a..ee4d3b4c71 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -8990,11 +8990,6 @@ - - - - - diff --git a/src/Database/MultiTableQuery.php b/src/Database/MultiTableQuery.php index 88a2e53024..fecbe087f7 100644 --- a/src/Database/MultiTableQuery.php +++ b/src/Database/MultiTableQuery.php @@ -80,7 +80,7 @@ class MultiTableQuery $dbi, $relation, new RelationCleanup($dbi, $relation), - new Transformations(), + new Transformations($dbi, $relation), new Template(), $bookmarkRepository, Config::getInstance(), diff --git a/src/Display/Results.php b/src/Display/Results.php index 4ea2774544..0303216bb9 100644 --- a/src/Display/Results.php +++ b/src/Display/Results.php @@ -217,7 +217,7 @@ class Results private readonly string $sqlQuery, ) { $this->relation = new Relation($this->dbi); - $this->transformations = new Transformations(); + $this->transformations = new Transformations($this->dbi, $this->relation); $this->template = new Template(); $this->setDefaultTransformations(); diff --git a/src/Plugins/Export/Helpers/Pdf.php b/src/Plugins/Export/Helpers/Pdf.php index f25de96c27..dc48476684 100644 --- a/src/Plugins/Export/Helpers/Pdf.php +++ b/src/Plugins/Export/Helpers/Pdf.php @@ -90,8 +90,9 @@ class Pdf extends PdfLib ) { parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache, $pdfa); - $this->relation = new Relation(DatabaseInterface::getInstance()); - $this->transformations = new Transformations(); + $dbi = DatabaseInterface::getInstance(); + $this->relation = new Relation($dbi); + $this->transformations = new Transformations($dbi, $this->relation); } /** diff --git a/src/Plugins/ExportPlugin.php b/src/Plugins/ExportPlugin.php index 7e201525ef..206da15b4d 100644 --- a/src/Plugins/ExportPlugin.php +++ b/src/Plugins/ExportPlugin.php @@ -39,7 +39,7 @@ abstract class ExportPlugin implements Plugin final public function __construct( public Relation $relation, protected Export $export, - protected Transformations $transformations, + public Transformations $transformations, ) { $this->init(); $this->properties = $this->setProperties(); diff --git a/src/Plugins/Schema/Pdf/PdfRelationSchema.php b/src/Plugins/Schema/Pdf/PdfRelationSchema.php index 835c926935..8b453d8a92 100644 --- a/src/Plugins/Schema/Pdf/PdfRelationSchema.php +++ b/src/Plugins/Schema/Pdf/PdfRelationSchema.php @@ -85,13 +85,15 @@ class PdfRelationSchema extends ExportRelationSchema private Transformations $transformations; private Pdf $pdf; + private DatabaseInterface $dbi; /** @see Pdf */ public function __construct(Relation $relation, DatabaseName $db) { parent::__construct($relation, $db); - $this->transformations = new Transformations(); + $this->dbi = DatabaseInterface::getInstance(); + $this->transformations = new Transformations($this->dbi, $relation); $this->setShowGrid(isset($_REQUEST['pdf_show_grid'])); $this->setShowColor(isset($_REQUEST['pdf_show_color'])); @@ -447,7 +449,6 @@ class PdfRelationSchema extends ExportRelationSchema $this->pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C'); $this->pdf->Ln(15); $i = 1; - $dbi = DatabaseInterface::getInstance(); foreach ($alltables as $table) { $this->pdf->customLinks['doc'][$table]['-'] = $this->pdf->AddLink(); $this->pdf->setX(10); @@ -465,7 +466,7 @@ class PdfRelationSchema extends ExportRelationSchema $this->pdf->setX(10); $this->pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', false, $this->pdf->customLinks['doc'][$table]['-']); // $this->diagram->Ln(1); - $fields = $dbi->getColumns($this->db->getName(), $table); + $fields = $this->dbi->getColumns($this->db->getName(), $table); foreach ($fields as $row) { $this->pdf->setX(20); $fieldName = $row->field; @@ -521,7 +522,7 @@ class PdfRelationSchema extends ExportRelationSchema $mimeMap = $this->transformations->getMime($this->db->getName(), $table, true); } - $showTable = $dbi->getTable($this->db->getName(), $table)->getStatusInfo(); + $showTable = $this->dbi->getTable($this->db->getName(), $table)->getStatusInfo(); $showComment = $showTable['Comment'] ?? ''; $createTime = isset($showTable['Create_time']) ? Util::localisedDate(new DateTimeImmutable($showTable['Create_time'])) @@ -536,7 +537,7 @@ class PdfRelationSchema extends ExportRelationSchema /** * Gets fields properties */ - $columns = $dbi->getColumns($this->db->getName(), $table); + $columns = $this->dbi->getColumns($this->db->getName(), $table); // Find which tables are related with the current one and write it in // an array diff --git a/src/Transformations.php b/src/Transformations.php index dd603093f2..df45df6f1a 100644 --- a/src/Transformations.php +++ b/src/Transformations.php @@ -52,6 +52,10 @@ class Transformations /** @var string[][]|null */ private static array|null $availableMimeTypesStack = null; + public function __construct(private readonly DatabaseInterface $dbi, private readonly Relation $relation) + { + } + /** * Returns array of options from string with options separated by comma, * removes quotes @@ -283,9 +287,7 @@ class Transformations */ public function getMime(string $db, string $table, bool $strict = false, bool $fullName = false): array|null { - $dbi = DatabaseInterface::getInstance(); - $relation = new Relation($dbi); - $browserTransformationFeature = $relation->getRelationParameters()->browserTransformationFeature; + $browserTransformationFeature = $this->relation->getRelationParameters()->browserTransformationFeature; if ($browserTransformationFeature === null) { return null; } @@ -303,8 +305,8 @@ class Transformations . '`input_transformation_options`' . ' FROM ' . Util::backquote($browserTransformationFeature->database) . '.' . Util::backquote($browserTransformationFeature->columnInfo) - . ' WHERE `db_name` = ' . $dbi->quoteString($db, ConnectionType::ControlUser) - . ' AND `table_name` = ' . $dbi->quoteString($table, ConnectionType::ControlUser) + . ' WHERE `db_name` = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser) + . ' AND `table_name` = ' . $this->dbi->quoteString($table, ConnectionType::ControlUser) . ' AND ( `mimetype` != \'\'' . (! $strict ? ' OR `transformation` != \'\'' . ' OR `transformation_options` != \'\'' @@ -321,7 +323,7 @@ class Transformations * input_transformation_options: string * }> $result */ - $result = $dbi->fetchResult($comQry, 'column_name', null, ConnectionType::ControlUser); + $result = $this->dbi->fetchResult($comQry, 'column_name', null, ConnectionType::ControlUser); foreach ($result as $column => $values) { // convert mimetype to new format (f.e. Text_Plain, etc) @@ -370,9 +372,7 @@ class Transformations string $inputTransformOpts, bool $forcedelete = false, ): bool { - $dbi = DatabaseInterface::getInstance(); - $relation = new Relation($dbi); - $browserTransformationFeature = $relation->getRelationParameters()->browserTransformationFeature; + $browserTransformationFeature = $this->relation->getRelationParameters()->browserTransformationFeature; if ($browserTransformationFeature === null) { return false; } @@ -394,11 +394,11 @@ class Transformations `comment` FROM ' . Util::backquote($browserTransformationFeature->database) . '.' . Util::backquote($browserTransformationFeature->columnInfo) . ' - WHERE `db_name` = ' . $dbi->quoteString($db, ConnectionType::ControlUser) . ' - AND `table_name` = ' . $dbi->quoteString($table, ConnectionType::ControlUser) . ' - AND `column_name` = ' . $dbi->quoteString($key, ConnectionType::ControlUser); + WHERE `db_name` = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ' + AND `table_name` = ' . $this->dbi->quoteString($table, ConnectionType::ControlUser) . ' + AND `column_name` = ' . $this->dbi->quoteString($key, ConnectionType::ControlUser); - $testRs = $dbi->queryAsControlUser($testQry); + $testRs = $this->dbi->queryAsControlUser($testQry); if ($testRs->numRows() > 0) { $row = $testRs->fetchAssoc(); @@ -409,15 +409,15 @@ class Transformations . Util::backquote($browserTransformationFeature->columnInfo) . ' SET ' . '`mimetype` = ' - . $dbi->quoteString($mimetype, ConnectionType::ControlUser) . ', ' + . $this->dbi->quoteString($mimetype, ConnectionType::ControlUser) . ', ' . '`transformation` = ' - . $dbi->quoteString($transformation, ConnectionType::ControlUser) . ', ' + . $this->dbi->quoteString($transformation, ConnectionType::ControlUser) . ', ' . '`transformation_options` = ' - . $dbi->quoteString($transformationOpts, ConnectionType::ControlUser) . ', ' + . $this->dbi->quoteString($transformationOpts, ConnectionType::ControlUser) . ', ' . '`input_transformation` = ' - . $dbi->quoteString($inputTransform, ConnectionType::ControlUser) . ', ' + . $this->dbi->quoteString($inputTransform, ConnectionType::ControlUser) . ', ' . '`input_transformation_options` = ' - . $dbi->quoteString($inputTransformOpts, ConnectionType::ControlUser); + . $this->dbi->quoteString($inputTransformOpts, ConnectionType::ControlUser); } else { $updQuery = 'DELETE FROM ' . Util::backquote($browserTransformationFeature->database) @@ -425,9 +425,9 @@ class Transformations } $updQuery .= ' - WHERE `db_name` = ' . $dbi->quoteString($db, ConnectionType::ControlUser) . ' - AND `table_name` = ' . $dbi->quoteString($table, ConnectionType::ControlUser) . ' - AND `column_name` = ' . $dbi->quoteString($key, ConnectionType::ControlUser); + WHERE `db_name` = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ' + AND `table_name` = ' . $this->dbi->quoteString($table, ConnectionType::ControlUser) . ' + AND `column_name` = ' . $this->dbi->quoteString($key, ConnectionType::ControlUser); } elseif ($hasValue) { $updQuery = 'INSERT INTO ' . Util::backquote($browserTransformationFeature->database) @@ -436,18 +436,18 @@ class Transformations . 'transformation, transformation_options, ' . 'input_transformation, input_transformation_options) ' . ' VALUES(' - . $dbi->quoteString($db, ConnectionType::ControlUser) . ',' - . $dbi->quoteString($table, ConnectionType::ControlUser) . ',' - . $dbi->quoteString($key, ConnectionType::ControlUser) . ',' - . $dbi->quoteString($mimetype, ConnectionType::ControlUser) . ',' - . $dbi->quoteString($transformation, ConnectionType::ControlUser) . ',' - . $dbi->quoteString($transformationOpts, ConnectionType::ControlUser) . ',' - . $dbi->quoteString($inputTransform, ConnectionType::ControlUser) . ',' - . $dbi->quoteString($inputTransformOpts, ConnectionType::ControlUser) . ')'; + . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ',' + . $this->dbi->quoteString($table, ConnectionType::ControlUser) . ',' + . $this->dbi->quoteString($key, ConnectionType::ControlUser) . ',' + . $this->dbi->quoteString($mimetype, ConnectionType::ControlUser) . ',' + . $this->dbi->quoteString($transformation, ConnectionType::ControlUser) . ',' + . $this->dbi->quoteString($transformationOpts, ConnectionType::ControlUser) . ',' + . $this->dbi->quoteString($inputTransform, ConnectionType::ControlUser) . ',' + . $this->dbi->quoteString($inputTransformOpts, ConnectionType::ControlUser) . ')'; } if (isset($updQuery)) { - return (bool) $dbi->queryAsControlUser($updQuery); + return (bool) $this->dbi->queryAsControlUser($updQuery); } return false; @@ -467,9 +467,7 @@ class Transformations */ public function clear(string $db, string $table = '', string $column = ''): bool { - $dbi = DatabaseInterface::getInstance(); - $relation = new Relation($dbi); - $browserTransformationFeature = $relation->getRelationParameters()->browserTransformationFeature; + $browserTransformationFeature = $this->relation->getRelationParameters()->browserTransformationFeature; if ($browserTransformationFeature === null) { return false; } @@ -490,6 +488,6 @@ class Transformations $deleteSql .= '`db_name` = \'' . $db . '\' '; } - return (bool) $dbi->tryQuery($deleteSql); + return (bool) $this->dbi->tryQuery($deleteSql); } } diff --git a/src/Twig/TransformationsExtension.php b/src/Twig/TransformationsExtension.php index 40a6066c48..89afd728e9 100644 --- a/src/Twig/TransformationsExtension.php +++ b/src/Twig/TransformationsExtension.php @@ -17,17 +17,9 @@ class TransformationsExtension extends AbstractExtension */ public function getFunctions(): array { - $transformations = new Transformations(); - return [ - new TwigFunction( - 'get_description', - $transformations->getDescription(...), - ), - new TwigFunction( - 'get_name', - $transformations->getName(...), - ), + new TwigFunction('get_description', [Transformations::class, 'getDescription']), + new TwigFunction('get_name', [Transformations::class, 'getName']), ]; } } diff --git a/tests/unit/Controllers/Normalization/AddNewPrimaryControllerTest.php b/tests/unit/Controllers/Normalization/AddNewPrimaryControllerTest.php index 35790e8f0d..b63f4514e8 100644 --- a/tests/unit/Controllers/Normalization/AddNewPrimaryControllerTest.php +++ b/tests/unit/Controllers/Normalization/AddNewPrimaryControllerTest.php @@ -34,9 +34,10 @@ class AddNewPrimaryControllerTest extends AbstractTestCase $response = new ResponseRenderer(); $template = new Template(); + $relation = new Relation($dbi); $controller = new AddNewPrimaryController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), new UserPrivilegesFactory($dbi), ); $controller(self::createStub(ServerRequest::class)); diff --git a/tests/unit/Controllers/Normalization/CreateNewColumnControllerTest.php b/tests/unit/Controllers/Normalization/CreateNewColumnControllerTest.php index aed5d712b7..22ab3c624e 100644 --- a/tests/unit/Controllers/Normalization/CreateNewColumnControllerTest.php +++ b/tests/unit/Controllers/Normalization/CreateNewColumnControllerTest.php @@ -35,9 +35,10 @@ class CreateNewColumnControllerTest extends AbstractTestCase $template = new Template(); $request = self::createStub(ServerRequest::class); + $relation = new Relation($dbi); $controller = new CreateNewColumnController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), new UserPrivilegesFactory($dbi), ); $controller($request); diff --git a/tests/unit/Controllers/Normalization/FirstNormalForm/FirstStepControllerTest.php b/tests/unit/Controllers/Normalization/FirstNormalForm/FirstStepControllerTest.php index 59ea5b5dcf..8e94a1f20d 100644 --- a/tests/unit/Controllers/Normalization/FirstNormalForm/FirstStepControllerTest.php +++ b/tests/unit/Controllers/Normalization/FirstNormalForm/FirstStepControllerTest.php @@ -37,9 +37,10 @@ class FirstStepControllerTest extends AbstractTestCase $request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/') ->withParsedBody(['normalizeTo' => $normalizeTo]); + $relation = new Relation($dbi); $controller = new FirstStepController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller($request); diff --git a/tests/unit/Controllers/Normalization/FirstNormalForm/FourthStepControllerTest.php b/tests/unit/Controllers/Normalization/FirstNormalForm/FourthStepControllerTest.php index 4ec275b392..17336f98ab 100644 --- a/tests/unit/Controllers/Normalization/FirstNormalForm/FourthStepControllerTest.php +++ b/tests/unit/Controllers/Normalization/FirstNormalForm/FourthStepControllerTest.php @@ -32,9 +32,10 @@ class FourthStepControllerTest extends AbstractTestCase $response = new ResponseRenderer(); $template = new Template(); + $relation = new Relation($dbi); $controller = new FourthStepController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller(self::createStub(ServerRequest::class)); diff --git a/tests/unit/Controllers/Normalization/FirstNormalForm/SecondStepControllerTest.php b/tests/unit/Controllers/Normalization/FirstNormalForm/SecondStepControllerTest.php index 56d2e75eda..55151ecb35 100644 --- a/tests/unit/Controllers/Normalization/FirstNormalForm/SecondStepControllerTest.php +++ b/tests/unit/Controllers/Normalization/FirstNormalForm/SecondStepControllerTest.php @@ -29,9 +29,10 @@ class SecondStepControllerTest extends AbstractTestCase $response = new ResponseRenderer(); $template = new Template(); + $relation = new Relation($dbi); $controller = new SecondStepController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller(self::createStub(ServerRequest::class)); diff --git a/tests/unit/Controllers/Normalization/FirstNormalForm/ThirdStepControllerTest.php b/tests/unit/Controllers/Normalization/FirstNormalForm/ThirdStepControllerTest.php index a8aab85099..1ce66bd156 100644 --- a/tests/unit/Controllers/Normalization/FirstNormalForm/ThirdStepControllerTest.php +++ b/tests/unit/Controllers/Normalization/FirstNormalForm/ThirdStepControllerTest.php @@ -32,9 +32,10 @@ class ThirdStepControllerTest extends AbstractTestCase $response = new ResponseRenderer(); $template = new Template(); + $relation = new Relation($dbi); $controller = new ThirdStepController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller(self::createStub(ServerRequest::class)); diff --git a/tests/unit/Controllers/Normalization/GetColumnsControllerTest.php b/tests/unit/Controllers/Normalization/GetColumnsControllerTest.php index cac04bec5a..5b8c611070 100644 --- a/tests/unit/Controllers/Normalization/GetColumnsControllerTest.php +++ b/tests/unit/Controllers/Normalization/GetColumnsControllerTest.php @@ -32,9 +32,10 @@ class GetColumnsControllerTest extends AbstractTestCase $response = new ResponseRenderer(); $template = new Template(); + $relation = new Relation($dbi); $controller = new GetColumnsController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller(self::createStub(ServerRequest::class)); diff --git a/tests/unit/Controllers/Normalization/MoveRepeatingGroupTest.php b/tests/unit/Controllers/Normalization/MoveRepeatingGroupTest.php index 80f30aae74..5e5d1ec7e9 100644 --- a/tests/unit/Controllers/Normalization/MoveRepeatingGroupTest.php +++ b/tests/unit/Controllers/Normalization/MoveRepeatingGroupTest.php @@ -47,9 +47,10 @@ class MoveRepeatingGroupTest extends AbstractTestCase 'primary_columns' => 'id,col1', ]); + $relation = new Relation($dbi); $controller = new MoveRepeatingGroup( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller($request); diff --git a/tests/unit/Controllers/Normalization/PartialDependenciesControllerTest.php b/tests/unit/Controllers/Normalization/PartialDependenciesControllerTest.php index 2c390f6466..a37c1ea96b 100644 --- a/tests/unit/Controllers/Normalization/PartialDependenciesControllerTest.php +++ b/tests/unit/Controllers/Normalization/PartialDependenciesControllerTest.php @@ -40,9 +40,10 @@ class PartialDependenciesControllerTest extends AbstractTestCase $response = new ResponseRenderer(); $template = new Template(); + $relation = new Relation($dbi); $controller = new PartialDependenciesController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller(self::createStub(ServerRequest::class)); diff --git a/tests/unit/Controllers/Normalization/SecondNormalForm/CreateNewTablesControllerTest.php b/tests/unit/Controllers/Normalization/SecondNormalForm/CreateNewTablesControllerTest.php index 8d2ddbc8a7..6402dca846 100644 --- a/tests/unit/Controllers/Normalization/SecondNormalForm/CreateNewTablesControllerTest.php +++ b/tests/unit/Controllers/Normalization/SecondNormalForm/CreateNewTablesControllerTest.php @@ -42,9 +42,10 @@ class CreateNewTablesControllerTest extends AbstractTestCase 'newTablesName' => json_encode(['ID, task' => 'batch_log2', 'task' => 'table2']), ]); + $relation = new Relation($dbi); $controller = new CreateNewTablesController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller($request); diff --git a/tests/unit/Controllers/Normalization/SecondNormalForm/FirstStepControllerTest.php b/tests/unit/Controllers/Normalization/SecondNormalForm/FirstStepControllerTest.php index c4389c5a6d..41479211d0 100644 --- a/tests/unit/Controllers/Normalization/SecondNormalForm/FirstStepControllerTest.php +++ b/tests/unit/Controllers/Normalization/SecondNormalForm/FirstStepControllerTest.php @@ -29,9 +29,10 @@ class FirstStepControllerTest extends AbstractTestCase $response = new ResponseRenderer(); $template = new Template(); + $relation = new Relation($dbi); $controller = new FirstStepController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller(self::createStub(ServerRequest::class)); diff --git a/tests/unit/Controllers/Normalization/SecondNormalForm/NewTablesControllerTest.php b/tests/unit/Controllers/Normalization/SecondNormalForm/NewTablesControllerTest.php index d2f138f9ab..aa301e2237 100644 --- a/tests/unit/Controllers/Normalization/SecondNormalForm/NewTablesControllerTest.php +++ b/tests/unit/Controllers/Normalization/SecondNormalForm/NewTablesControllerTest.php @@ -34,9 +34,10 @@ class NewTablesControllerTest extends AbstractTestCase ->withParsedBody([ 'pd' => json_encode(['ID, task' => [], 'task' => ['timestamp']]), ]); + $relation = new Relation($dbi); $controller = new NewTablesController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller($request); diff --git a/tests/unit/Controllers/Normalization/ThirdNormalForm/CreateNewTablesControllerTest.php b/tests/unit/Controllers/Normalization/ThirdNormalForm/CreateNewTablesControllerTest.php index 0d39b0acc2..03d7b816aa 100644 --- a/tests/unit/Controllers/Normalization/ThirdNormalForm/CreateNewTablesControllerTest.php +++ b/tests/unit/Controllers/Normalization/ThirdNormalForm/CreateNewTablesControllerTest.php @@ -56,9 +56,10 @@ class CreateNewTablesControllerTest extends AbstractTestCase $request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/') ->withParsedBody(['newTables' => $newTables]); + $relation = new Relation($dbi); $controller = new CreateNewTablesController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller($request); diff --git a/tests/unit/Controllers/Normalization/ThirdNormalForm/FirstStepControllerTest.php b/tests/unit/Controllers/Normalization/ThirdNormalForm/FirstStepControllerTest.php index 682f39419c..aa94b1bc57 100644 --- a/tests/unit/Controllers/Normalization/ThirdNormalForm/FirstStepControllerTest.php +++ b/tests/unit/Controllers/Normalization/ThirdNormalForm/FirstStepControllerTest.php @@ -34,9 +34,10 @@ class FirstStepControllerTest extends AbstractTestCase $request = self::createStub(ServerRequest::class); $request->method('getParsedBodyParam')->willReturnMap([['tables', null, ['test_table']]]); + $relation = new Relation($dbi); $controller = new FirstStepController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller($request); diff --git a/tests/unit/Controllers/Normalization/ThirdNormalForm/NewTablesControllerTest.php b/tests/unit/Controllers/Normalization/ThirdNormalForm/NewTablesControllerTest.php index 3c755993aa..0084ef08ce 100644 --- a/tests/unit/Controllers/Normalization/ThirdNormalForm/NewTablesControllerTest.php +++ b/tests/unit/Controllers/Normalization/ThirdNormalForm/NewTablesControllerTest.php @@ -45,9 +45,10 @@ class NewTablesControllerTest extends AbstractTestCase 'pd' => $pd, ]); + $relation = new Relation($dbi); $controller = new NewTablesController( $response, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template), + new Normalization($dbi, $relation, new Transformations($dbi, $relation), $template), ); $controller($request); diff --git a/tests/unit/Controllers/Server/Databases/DestroyControllerTest.php b/tests/unit/Controllers/Server/Databases/DestroyControllerTest.php index 6225079690..d668288605 100644 --- a/tests/unit/Controllers/Server/Databases/DestroyControllerTest.php +++ b/tests/unit/Controllers/Server/Databases/DestroyControllerTest.php @@ -39,11 +39,12 @@ class DestroyControllerTest extends AbstractTestCase $config = Config::getInstance(); $config->settings['AllowUserDropDatabase'] = true; + $relation = new Relation($dbi); $controller = new DestroyController( $response, $dbi, - new Transformations(), - new RelationCleanup($dbi, new Relation($dbi)), + new Transformations($dbi, $relation), + new RelationCleanup($dbi, $relation), new UserPrivilegesFactory($dbi), $config, ); diff --git a/tests/unit/Controllers/Table/AddFieldControllerTest.php b/tests/unit/Controllers/Table/AddFieldControllerTest.php index 9028b59731..2880839595 100644 --- a/tests/unit/Controllers/Table/AddFieldControllerTest.php +++ b/tests/unit/Controllers/Table/AddFieldControllerTest.php @@ -257,7 +257,7 @@ class AddFieldControllerTest extends AbstractTestCase ->withQueryParams(['db' => 'test_db', 'table' => 'test_table']) ->withParsedBody(['num_fields' => '1']); - $transformations = new Transformations(); + $transformations = new Transformations($dbi, $relation); (new AddFieldController( $response, $transformations, diff --git a/tests/unit/Controllers/Table/ChangeControllerTest.php b/tests/unit/Controllers/Table/ChangeControllerTest.php index 696cf676cf..1415704251 100644 --- a/tests/unit/Controllers/Table/ChangeControllerTest.php +++ b/tests/unit/Controllers/Table/ChangeControllerTest.php @@ -59,10 +59,19 @@ final class ChangeControllerTest extends AbstractTestCase $relation = new Relation($dbi); $template = new Template(); + $insertEdit = new InsertEdit( + $dbi, + $relation, + new Transformations($dbi, $relation), + new FileListing(), + $template, + $config, + ); + (new ChangeController( $response, $template, - new InsertEdit($dbi, $relation, new Transformations(), new FileListing(), $template, $config), + $insertEdit, $relation, $pageSettings, new DbTableExists($dbi), @@ -162,10 +171,19 @@ final class ChangeControllerTest extends AbstractTestCase $relation = new Relation($dbi); $template = new Template(); + $insertEdit = new InsertEdit( + $dbi, + $relation, + new Transformations($dbi, $relation), + new FileListing(), + $template, + $config, + ); + (new ChangeController( $response, $template, - new InsertEdit($dbi, $relation, new Transformations(), new FileListing(), $template, $config), + $insertEdit, $relation, $pageSettings, new DbTableExists($dbi), diff --git a/tests/unit/Controllers/Table/CreateControllerTest.php b/tests/unit/Controllers/Table/CreateControllerTest.php index a17b70f7d0..bc13c7b0ec 100644 --- a/tests/unit/Controllers/Table/CreateControllerTest.php +++ b/tests/unit/Controllers/Table/CreateControllerTest.php @@ -272,7 +272,7 @@ class CreateControllerTest extends AbstractTestCase $request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/') ->withParsedBody(['num_fields' => '2']); - $transformations = new Transformations(); + $transformations = new Transformations($dbi, $relation); (new CreateController( $response, $transformations, diff --git a/tests/unit/Controllers/Table/DeleteRowsControllerTest.php b/tests/unit/Controllers/Table/DeleteRowsControllerTest.php index 44cf088cc1..e3f92a8e9b 100644 --- a/tests/unit/Controllers/Table/DeleteRowsControllerTest.php +++ b/tests/unit/Controllers/Table/DeleteRowsControllerTest.php @@ -66,7 +66,7 @@ class DeleteRowsControllerTest extends AbstractTestCase $dbi, $relation, new RelationCleanup($dbi, $relation), - new Transformations(), + new Transformations($dbi, $relation), new Template($config), new BookmarkRepository($dbi, $relation), $config, diff --git a/tests/unit/Controllers/Table/ReplaceControllerTest.php b/tests/unit/Controllers/Table/ReplaceControllerTest.php index 49f6b737e4..870ec32097 100644 --- a/tests/unit/Controllers/Table/ReplaceControllerTest.php +++ b/tests/unit/Controllers/Table/ReplaceControllerTest.php @@ -95,7 +95,7 @@ class ReplaceControllerTest extends AbstractTestCase $dummyDbi = $this->createDbiDummy(); $dbi = $this->createDatabaseInterface($dummyDbi); $relation = new Relation($dbi); - $transformations = new Transformations(); + $transformations = new Transformations($dbi, $relation); $template = new Template(); $response = new ResponseRenderer(); diff --git a/tests/unit/Controllers/Table/SearchControllerTest.php b/tests/unit/Controllers/Table/SearchControllerTest.php index 4aad326aff..4dac227a45 100644 --- a/tests/unit/Controllers/Table/SearchControllerTest.php +++ b/tests/unit/Controllers/Table/SearchControllerTest.php @@ -51,7 +51,7 @@ final class SearchControllerTest extends AbstractTestCase $dbi, $relation, new RelationCleanup($dbi, $relation), - new Transformations(), + new Transformations($dbi, $relation), $template, new BookmarkRepository($dbi, $relation), $config, diff --git a/tests/unit/Controllers/Table/Structure/ChangeControllerTest.php b/tests/unit/Controllers/Table/Structure/ChangeControllerTest.php index b452c165a8..53c7c1e3e6 100644 --- a/tests/unit/Controllers/Table/Structure/ChangeControllerTest.php +++ b/tests/unit/Controllers/Table/Structure/ChangeControllerTest.php @@ -46,10 +46,11 @@ class ChangeControllerTest extends AbstractTestCase $class = new ReflectionClass(ChangeController::class); $method = $class->getMethod('displayHtmlForColumnChange'); + $relation = new Relation($this->dbi); $ctrl = new ChangeController( $response, $this->dbi, - new ColumnsDefinition($this->dbi, new Relation($this->dbi), new Transformations()), + new ColumnsDefinition($this->dbi, $relation, new Transformations($this->dbi, $relation)), new UserPrivilegesFactory($this->dbi), ); diff --git a/tests/unit/Controllers/Table/Structure/SaveControllerTest.php b/tests/unit/Controllers/Table/Structure/SaveControllerTest.php index 5651583e5c..15114f821d 100644 --- a/tests/unit/Controllers/Table/Structure/SaveControllerTest.php +++ b/tests/unit/Controllers/Table/Structure/SaveControllerTest.php @@ -94,10 +94,11 @@ class SaveControllerTest extends AbstractTestCase $mock->expects(self::once())->method('__invoke')->with($request) ->willReturn(ResponseFactory::create()->createResponse()); + $relation = new Relation($dbi); (new SaveController( new ResponseRenderer(), - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), $dbi, $mock, new UserPrivilegesFactory($dbi), @@ -117,10 +118,11 @@ class SaveControllerTest extends AbstractTestCase $class = new ReflectionClass(SaveController::class); $method = $class->getMethod('adjustColumnPrivileges'); + $relation = new Relation($dbi); $ctrl = new SaveController( new ResponseRenderer(), - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), $dbi, self::createStub(StructureController::class), new UserPrivilegesFactory($dbi), diff --git a/tests/unit/Controllers/Table/StructureControllerTest.php b/tests/unit/Controllers/Table/StructureControllerTest.php index 955ddba4eb..0d4a4429c6 100644 --- a/tests/unit/Controllers/Table/StructureControllerTest.php +++ b/tests/unit/Controllers/Table/StructureControllerTest.php @@ -99,7 +99,7 @@ class StructureControllerTest extends AbstractTestCase $response, $template, $relation, - new Transformations(), + new Transformations($this->dbi, $relation), $this->dbi, $pageSettings, new DbTableExists($this->dbi), diff --git a/tests/unit/Controllers/Transformation/OverviewControllerTest.php b/tests/unit/Controllers/Transformation/OverviewControllerTest.php index a4035224b6..4d21d3ca19 100644 --- a/tests/unit/Controllers/Transformation/OverviewControllerTest.php +++ b/tests/unit/Controllers/Transformation/OverviewControllerTest.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Controllers\Transformation; +use PhpMyAdmin\ConfigStorage\Relation; use PhpMyAdmin\Controllers\Transformation\OverviewController; use PhpMyAdmin\Current; -use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\Tests\AbstractTestCase; use PhpMyAdmin\Tests\Stubs\ResponseRenderer; @@ -27,8 +27,6 @@ class OverviewControllerTest extends AbstractTestCase $this->setGlobalConfig(); - DatabaseInterface::$instance = $this->createDatabaseInterface(); - Current::$database = 'db'; Current::$table = 'table'; } @@ -37,7 +35,8 @@ class OverviewControllerTest extends AbstractTestCase { $response = new ResponseRenderer(); - $controller = new OverviewController($response, new Transformations()); + $dbi = $this->createDatabaseInterface(); + $controller = new OverviewController($response, new Transformations($dbi, new Relation($dbi))); $controller(self::createStub(ServerRequest::class)); $actual = $response->getHTMLResult(); diff --git a/tests/unit/Display/ResultsTest.php b/tests/unit/Display/ResultsTest.php index 5b09a9b32e..c8c2c28c77 100644 --- a/tests/unit/Display/ResultsTest.php +++ b/tests/unit/Display/ResultsTest.php @@ -700,7 +700,7 @@ class ResultsTest extends AbstractTestCase DatabaseInterface::$instance = $dbi; - $transformations = new Transformations(); + $transformations = new Transformations($dbi, new Relation($dbi)); (new ReflectionProperty(DisplayResults::class, 'mediaTypeMap'))->setValue( $this->object, $transformations->getMime('db', 'table'), diff --git a/tests/unit/Export/ExportTest.php b/tests/unit/Export/ExportTest.php index 87e9195d25..bd0800da3d 100644 --- a/tests/unit/Export/ExportTest.php +++ b/tests/unit/Export/ExportTest.php @@ -67,11 +67,8 @@ class ExportTest extends AbstractTestCase $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; $export = new Export($dbi); - $exportPlugin = new ExportPhparray( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $exportPlugin = new ExportPhparray($relation, new Export($dbi), new Transformations($dbi, $relation)); $finalFileName = $export->getFinalFilename($exportPlugin, 'zip', 'myfilename'); self::assertSame('myfilename.php.zip', $finalFileName); $finalFileName = $export->getFinalFilename($exportPlugin, 'gzip', 'myfilename'); @@ -85,11 +82,8 @@ class ExportTest extends AbstractTestCase $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; $export = new Export($dbi); - $exportPlugin = new ExportPhparray( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $exportPlugin = new ExportPhparray($relation, new Export($dbi), new Transformations($dbi, $relation)); $mimeType = $export->getMimeType($exportPlugin, 'zip'); self::assertSame('application/zip', $mimeType); $mimeType = $export->getMimeType($exportPlugin, 'gzip'); @@ -131,12 +125,13 @@ class ExportTest extends AbstractTestCase $export = new Export($dbi); ExportPlugin::$exportType = ExportType::Database; + $relation = new Relation($dbi); $export->exportDatabase( DatabaseName::from('test_db'), ['test_table'], ['test_table'], ['test_table'], - new ExportSql(new Relation($dbi), $export, new Transformations()), + new ExportSql($relation, $export, new Transformations($dbi, $relation)), [], '', ); @@ -205,9 +200,10 @@ SQL; DatabaseInterface::$instance = $dbi; $export = new Export($dbi); + $relation = new Relation($dbi); $export->exportServer( ['test_db'], - new ExportSql(new Relation($dbi), $export, new Transformations()), + new ExportSql($relation, $export, new Transformations($dbi, $relation)), [], '', ); diff --git a/tests/unit/InsertEditTest.php b/tests/unit/InsertEditTest.php index 4d85386db5..5ce51f3d68 100644 --- a/tests/unit/InsertEditTest.php +++ b/tests/unit/InsertEditTest.php @@ -94,10 +94,11 @@ class InsertEditTest extends AbstractTestCase $config->settings['Confirm'] = true; $config->settings['LoginCookieValidity'] = 1440; $config->settings['enable_drag_drop_import'] = true; + $relation = new Relation($this->dbi); $this->insertEdit = new InsertEdit( $this->dbi, - new Relation($this->dbi), - new Transformations(), + $relation, + new Transformations($this->dbi, $relation), new FileListing(), new Template(), $config, @@ -207,10 +208,11 @@ class InsertEditTest extends AbstractTestCase ->willReturn([], []); DatabaseInterface::$instance = $dbi; + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), @@ -252,10 +254,11 @@ class InsertEditTest extends AbstractTestCase ->willReturn([$meta]); DatabaseInterface::$instance = $dbi; + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), @@ -287,10 +290,11 @@ class InsertEditTest extends AbstractTestCase ->willReturn($resultStub); DatabaseInterface::$instance = $dbi; + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), @@ -1026,10 +1030,11 @@ class InsertEditTest extends AbstractTestCase ->getMock(); DatabaseInterface::$instance = $dbi; + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), @@ -1241,10 +1246,11 @@ class InsertEditTest extends AbstractTestCase DatabaseInterface::$instance = $dbi; Current::$database = 'db'; Current::$table = 'table'; + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), @@ -1324,10 +1330,11 @@ class InsertEditTest extends AbstractTestCase $_POST['submit_type'] = ''; $dbi = DatabaseInterface::getInstance(); + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), @@ -1347,10 +1354,11 @@ class InsertEditTest extends AbstractTestCase $_POST['submit_type'] = ''; $dbi = DatabaseInterface::getInstance(); + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), @@ -1379,10 +1387,11 @@ class InsertEditTest extends AbstractTestCase ->willReturn($warnings); DatabaseInterface::$instance = $dbi; + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), @@ -1429,10 +1438,11 @@ class InsertEditTest extends AbstractTestCase ->willReturn('2'); DatabaseInterface::$instance = $dbi; + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), @@ -2169,10 +2179,11 @@ class InsertEditTest extends AbstractTestCase ->willReturn(false, '123', '2013-08-28 06:34:14'); DatabaseInterface::$instance = $dbi; + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), @@ -2217,10 +2228,11 @@ class InsertEditTest extends AbstractTestCase ->willReturn($columns); DatabaseInterface::$instance = $dbi; + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), @@ -2272,10 +2284,11 @@ class InsertEditTest extends AbstractTestCase $response = new ReflectionProperty(ResponseRenderer::class, 'instance'); $response->setValue(null, $responseMock); + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), @@ -2325,10 +2338,11 @@ class InsertEditTest extends AbstractTestCase ->willReturn(new Table('table', 'db', $dbi)); DatabaseInterface::$instance = $dbi; + $relation = new Relation($dbi); $this->insertEdit = new InsertEdit( $dbi, - new Relation($dbi), - new Transformations(), + $relation, + new Transformations($dbi, $relation), new FileListing(), new Template(), Config::getInstance(), diff --git a/tests/unit/NormalizationTest.php b/tests/unit/NormalizationTest.php index 6c53aa3573..5be5c0c01d 100644 --- a/tests/unit/NormalizationTest.php +++ b/tests/unit/NormalizationTest.php @@ -97,7 +97,8 @@ class NormalizationTest extends AbstractTestCase ->method('fetchSingleRow') ->willReturn(['`id`_cnt' => 0, '`col1`_cnt' => 0, '`col2`_cnt' => 0]); - $this->normalization = new Normalization($dbi, new Relation($dbi), new Transformations(), new Template()); + $relation = new Relation($dbi); + $this->normalization = new Normalization($dbi, $relation, new Transformations($dbi, $relation), new Template()); } /** @@ -131,10 +132,11 @@ class NormalizationTest extends AbstractTestCase $db = 'testdb'; $table = 'mytable'; $numFields = 1; + $relation = new Relation($this->dbi); $normalization = new Normalization( $this->dbi, - new Relation($this->dbi), - new Transformations(), + $relation, + new Transformations($this->dbi, $relation), new Template(), ); $result = $normalization->getHtmlForCreateNewColumn($userPrivileges, $numFields, $db, $table); diff --git a/tests/unit/Plugins/Export/ExportCodegenTest.php b/tests/unit/Plugins/Export/ExportCodegenTest.php index 624021ca04..d301e0633e 100644 --- a/tests/unit/Plugins/Export/ExportCodegenTest.php +++ b/tests/unit/Plugins/Export/ExportCodegenTest.php @@ -39,11 +39,8 @@ class ExportCodegenTest extends AbstractTestCase $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; - $this->object = new ExportCodegen( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $this->object = new ExportCodegen($relation, new Export($dbi), new Transformations($dbi, $relation)); } /** diff --git a/tests/unit/Plugins/Export/ExportCsvTest.php b/tests/unit/Plugins/Export/ExportCsvTest.php index f5630a3a7a..ced2fae7e3 100644 --- a/tests/unit/Plugins/Export/ExportCsvTest.php +++ b/tests/unit/Plugins/Export/ExportCsvTest.php @@ -46,11 +46,8 @@ class ExportCsvTest extends AbstractTestCase Current::$lang = ''; Export::$saveFilename = ''; - $this->object = new ExportCsv( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $this->object = new ExportCsv($relation, new Export($dbi), new Transformations($dbi, $relation)); } /** diff --git a/tests/unit/Plugins/Export/ExportExcelTest.php b/tests/unit/Plugins/Export/ExportExcelTest.php index 46d146328b..f114de3fcb 100644 --- a/tests/unit/Plugins/Export/ExportExcelTest.php +++ b/tests/unit/Plugins/Export/ExportExcelTest.php @@ -41,11 +41,8 @@ class ExportExcelTest extends AbstractTestCase $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; - $this->object = new ExportExcel( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $this->object = new ExportExcel($relation, new Export($dbi), new Transformations($dbi, $relation)); } /** diff --git a/tests/unit/Plugins/Export/ExportHtmlwordTest.php b/tests/unit/Plugins/Export/ExportHtmlwordTest.php index e05b19d398..04264bccca 100644 --- a/tests/unit/Plugins/Export/ExportHtmlwordTest.php +++ b/tests/unit/Plugins/Export/ExportHtmlwordTest.php @@ -57,10 +57,11 @@ class ExportHtmlwordTest extends AbstractTestCase $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; + $relation = new Relation($this->dbi); $this->object = new ExportHtmlword( - new Relation($this->dbi), + $relation, new Export($this->dbi), - new Transformations(), + new Transformations($this->dbi, $relation), ); Export::$outputKanjiConversion = false; Export::$outputCharsetConversion = false; @@ -375,9 +376,10 @@ class ExportHtmlwordTest extends AbstractTestCase public function testGetTableDef(): void { + $relation = new Relation($this->dbi); $this->object = $this->getMockBuilder(ExportHtmlword::class) ->onlyMethods(['formatOneColumnDefinition']) - ->setConstructorArgs([new Relation($this->dbi), new Export($this->dbi), new Transformations()]) + ->setConstructorArgs([$relation, new Export($this->dbi), new Transformations($this->dbi, $relation)]) ->getMock(); $keys = [['Non_unique' => 0, 'Column_name' => 'name1'], ['Non_unique' => 1, 'Column_name' => 'name2']]; @@ -421,7 +423,9 @@ class ExportHtmlwordTest extends AbstractTestCase ->willReturn(['comment' => 'testComment']); DatabaseInterface::$instance = $dbi; - $this->object->relation = new Relation($dbi); + $relation = new Relation($dbi); + $this->object->relation = $relation; + $this->object->transformations = new Transformations($dbi, $relation); $this->object->expects(self::exactly(3)) ->method('formatOneColumnDefinition') @@ -497,7 +501,9 @@ class ExportHtmlwordTest extends AbstractTestCase ->willReturn(['comment' => 'testComment']); DatabaseInterface::$instance = $dbi; - $this->object->relation = new Relation($dbi); + $relation = new Relation($dbi); + $this->object->relation = $relation; + $this->object->transformations = new Transformations($dbi, $relation); $relationParameters = RelationParameters::fromArray([ 'relwork' => true, diff --git a/tests/unit/Plugins/Export/ExportJsonTest.php b/tests/unit/Plugins/Export/ExportJsonTest.php index c558e45bae..a4d355b521 100644 --- a/tests/unit/Plugins/Export/ExportJsonTest.php +++ b/tests/unit/Plugins/Export/ExportJsonTest.php @@ -40,11 +40,8 @@ class ExportJsonTest extends AbstractTestCase Export::$bufferNeeded = false; Export::$asFile = true; Export::$saveOnServer = false; - $this->object = new ExportJson( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $this->object = new ExportJson($relation, new Export($dbi), new Transformations($dbi, $relation)); } /** diff --git a/tests/unit/Plugins/Export/ExportLatexTest.php b/tests/unit/Plugins/Export/ExportLatexTest.php index b21c96f6ad..1e2f35192b 100644 --- a/tests/unit/Plugins/Export/ExportLatexTest.php +++ b/tests/unit/Plugins/Export/ExportLatexTest.php @@ -58,11 +58,8 @@ class ExportLatexTest extends AbstractTestCase ExportPlugin::$singleTable = false; Current::$database = 'db'; Current::$table = 'table'; - $this->object = new ExportLatex( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $this->object = new ExportLatex($relation, new Export($dbi), new Transformations($dbi, $relation)); } /** @@ -606,7 +603,9 @@ class ExportLatexTest extends AbstractTestCase ->willReturn(['comment' => 'testComment']); DatabaseInterface::$instance = $dbi; - $this->object->relation = new Relation($dbi); + $relation = new Relation($dbi); + $this->object->relation = $relation; + $this->object->transformations = new Transformations($dbi, $relation); $relationParameters = RelationParameters::fromArray([ 'relwork' => true, @@ -689,7 +688,9 @@ class ExportLatexTest extends AbstractTestCase ->willReturn(['comment' => 'testComment']); DatabaseInterface::$instance = $dbi; - $this->object->relation = new Relation($dbi); + $relation = new Relation($dbi); + $this->object->relation = $relation; + $this->object->transformations = new Transformations($dbi, $relation); $relationParameters = RelationParameters::fromArray([ 'relwork' => true, diff --git a/tests/unit/Plugins/Export/ExportMediawikiTest.php b/tests/unit/Plugins/Export/ExportMediawikiTest.php index 0db64c1120..e3a7ca4c02 100644 --- a/tests/unit/Plugins/Export/ExportMediawikiTest.php +++ b/tests/unit/Plugins/Export/ExportMediawikiTest.php @@ -51,11 +51,8 @@ class ExportMediawikiTest extends AbstractTestCase Current::$database = ''; Current::$table = ''; Current::$lang = 'en'; - $this->object = new ExportMediawiki( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $this->object = new ExportMediawiki($relation, new Export($dbi), new Transformations($dbi, $relation)); } /** diff --git a/tests/unit/Plugins/Export/ExportOdsTest.php b/tests/unit/Plugins/Export/ExportOdsTest.php index ce290a18e9..48eb44e16b 100644 --- a/tests/unit/Plugins/Export/ExportOdsTest.php +++ b/tests/unit/Plugins/Export/ExportOdsTest.php @@ -57,11 +57,8 @@ class ExportOdsTest extends AbstractTestCase Export::$bufferNeeded = false; Export::$asFile = true; Export::$saveOnServer = false; - $this->object = new ExportOds( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $this->object = new ExportOds($relation, new Export($dbi), new Transformations($dbi, $relation)); } /** diff --git a/tests/unit/Plugins/Export/ExportOdtTest.php b/tests/unit/Plugins/Export/ExportOdtTest.php index 338d3ec3c6..677566b71b 100644 --- a/tests/unit/Plugins/Export/ExportOdtTest.php +++ b/tests/unit/Plugins/Export/ExportOdtTest.php @@ -75,11 +75,8 @@ class ExportOdtTest extends AbstractTestCase ExportPlugin::$exportType = ExportType::Table; ExportPlugin::$singleTable = false; Config::getInstance()->selectedServer['DisableIS'] = true; - $this->object = new ExportOdt( - new Relation($this->dbi), - new Export($this->dbi), - new Transformations(), - ); + $relation = new Relation($this->dbi); + $this->object = new ExportOdt($relation, new Export($this->dbi), new Transformations($this->dbi, $relation)); } /** @@ -574,9 +571,10 @@ class ExportOdtTest extends AbstractTestCase public function testGetTableDef(): void { + $relation = new Relation($this->dbi); $this->object = $this->getMockBuilder(ExportOdt::class) ->onlyMethods(['formatOneColumnDefinition']) - ->setConstructorArgs([new Relation($this->dbi), new Export($this->dbi), new Transformations()]) + ->setConstructorArgs([$relation, new Export($this->dbi), new Transformations($this->dbi, $relation)]) ->getMock(); // case 1 @@ -613,7 +611,9 @@ class ExportOdtTest extends AbstractTestCase ->willReturn(['comment' => 'testComment']); DatabaseInterface::$instance = $dbi; - $this->object->relation = new Relation($dbi); + $relation = new Relation($dbi); + $this->object->relation = $relation; + $this->object->transformations = new Transformations($dbi, $relation); $this->object->expects(self::exactly(2)) ->method('formatOneColumnDefinition') @@ -694,7 +694,9 @@ class ExportOdtTest extends AbstractTestCase ->willReturn(['comment' => 'testComment']); DatabaseInterface::$instance = $dbi; - $this->object->relation = new Relation($dbi); + $relation = new Relation($dbi); + $this->object->relation = $relation; + $this->object->transformations = new Transformations($dbi, $relation); $this->object->buffer = ''; $relationParameters = RelationParameters::fromArray([ 'relwork' => true, diff --git a/tests/unit/Plugins/Export/ExportPdfTest.php b/tests/unit/Plugins/Export/ExportPdfTest.php index 96ee8077ff..9e45fa5949 100644 --- a/tests/unit/Plugins/Export/ExportPdfTest.php +++ b/tests/unit/Plugins/Export/ExportPdfTest.php @@ -43,11 +43,8 @@ class ExportPdfTest extends AbstractTestCase Export::$bufferNeeded = false; Export::$asFile = true; Export::$saveOnServer = false; - $this->object = new ExportPdf( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $this->object = new ExportPdf($relation, new Export($dbi), new Transformations($dbi, $relation)); } /** diff --git a/tests/unit/Plugins/Export/ExportPhparrayTest.php b/tests/unit/Plugins/Export/ExportPhparrayTest.php index f95c333996..0b2c162444 100644 --- a/tests/unit/Plugins/Export/ExportPhparrayTest.php +++ b/tests/unit/Plugins/Export/ExportPhparrayTest.php @@ -46,11 +46,8 @@ class ExportPhparrayTest extends AbstractTestCase Current::$database = ''; Current::$table = ''; Current::$lang = 'en'; - $this->object = new ExportPhparray( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $this->object = new ExportPhparray($relation, new Export($dbi), new Transformations($dbi, $relation)); } /** diff --git a/tests/unit/Plugins/Export/ExportSqlTest.php b/tests/unit/Plugins/Export/ExportSqlTest.php index 4fe933db03..1215e4477f 100644 --- a/tests/unit/Plugins/Export/ExportSqlTest.php +++ b/tests/unit/Plugins/Export/ExportSqlTest.php @@ -74,11 +74,8 @@ class ExportSqlTest extends AbstractTestCase ExportPlugin::$exportType = ExportType::Table; ExportPlugin::$singleTable = false; - $this->object = new ExportSql( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $this->object = new ExportSql($relation, new Export($dbi), new Transformations($dbi, $relation)); $this->object->useSqlBackquotes(false); } @@ -889,7 +886,9 @@ SQL; ); DatabaseInterface::$instance = $dbi; - $this->object->relation = new Relation($dbi); + $relation = new Relation($dbi); + $this->object = new ExportSql($relation, new Export($dbi), new Transformations($dbi, $relation)); + $this->object->useSqlBackquotes(false); $request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/') ->withParsedBody(['sql_relation' => 'On', 'sql_mime' => 'On', 'sql_include_comments' => 'On']); diff --git a/tests/unit/Plugins/Export/ExportTexytextTest.php b/tests/unit/Plugins/Export/ExportTexytextTest.php index 46ac22a549..bf9a365c3e 100644 --- a/tests/unit/Plugins/Export/ExportTexytextTest.php +++ b/tests/unit/Plugins/Export/ExportTexytextTest.php @@ -68,10 +68,11 @@ class ExportTexytextTest extends AbstractTestCase Current::$table = ''; Current::$lang = 'en'; Config::getInstance()->selectedServer['DisableIS'] = true; + $relation = new Relation($this->dbi); $this->object = new ExportTexytext( - new Relation($this->dbi), + $relation, new Export($this->dbi), - new Transformations(), + new Transformations($this->dbi, $relation), ); } @@ -259,9 +260,10 @@ class ExportTexytextTest extends AbstractTestCase public function testGetTableDef(): void { + $relation = new Relation($this->dbi); $this->object = $this->getMockBuilder(ExportTexytext::class) ->onlyMethods(['formatOneColumnDefinition']) - ->setConstructorArgs([new Relation($this->dbi), new Export($this->dbi), new Transformations()]) + ->setConstructorArgs([$relation, new Export($this->dbi), new Transformations($this->dbi, $relation)]) ->getMock(); // case 1 @@ -297,7 +299,9 @@ class ExportTexytextTest extends AbstractTestCase ]); DatabaseInterface::$instance = $dbi; - $this->object->relation = new Relation($dbi); + $relation = new Relation($dbi); + $this->object->relation = $relation; + $this->object->transformations = new Transformations($dbi, $relation); $request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/') ->withParsedBody(['texytext_relation' => 'On', 'texytext_mime' => 'On', 'texytext_comments' => 'On']); diff --git a/tests/unit/Plugins/Export/ExportXmlTest.php b/tests/unit/Plugins/Export/ExportXmlTest.php index da7ac09aa6..22aaf91605 100644 --- a/tests/unit/Plugins/Export/ExportXmlTest.php +++ b/tests/unit/Plugins/Export/ExportXmlTest.php @@ -51,11 +51,8 @@ class ExportXmlTest extends AbstractTestCase ExportPlugin::$singleTable = false; Current::$database = 'db'; Config::getInstance()->selectedServer['DisableIS'] = true; - $this->object = new ExportXml( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $this->object = new ExportXml($relation, new Export($dbi), new Transformations($dbi, $relation)); } /** diff --git a/tests/unit/Plugins/Export/ExportYamlTest.php b/tests/unit/Plugins/Export/ExportYamlTest.php index 2c2e6ce780..51f075b8fa 100644 --- a/tests/unit/Plugins/Export/ExportYamlTest.php +++ b/tests/unit/Plugins/Export/ExportYamlTest.php @@ -45,11 +45,8 @@ class ExportYamlTest extends AbstractTestCase Current::$database = ''; Current::$table = ''; Current::$lang = 'en'; - $this->object = new ExportYaml( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ); + $relation = new Relation($dbi); + $this->object = new ExportYaml($relation, new Export($dbi), new Transformations($dbi, $relation)); } /** diff --git a/tests/unit/PluginsTest.php b/tests/unit/PluginsTest.php index e9e72262f0..59d6b4b9ea 100644 --- a/tests/unit/PluginsTest.php +++ b/tests/unit/PluginsTest.php @@ -99,27 +99,14 @@ class PluginsTest extends AbstractTestCase public function testGetChoice(): void { $dbi = DatabaseInterface::getInstance(); + $relation = new Relation($dbi); + $transformations = new Transformations($dbi, $relation); + $export = new Export($dbi); $exportList = [ - new Plugins\Export\ExportJson( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ), - new Plugins\Export\ExportOds( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ), - new Plugins\Export\ExportSql( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ), - new Plugins\Export\ExportXml( - new Relation($dbi), - new Export($dbi), - new Transformations(), - ), + new Plugins\Export\ExportJson($relation, $export, $transformations), + new Plugins\Export\ExportOds($relation, $export, $transformations), + new Plugins\Export\ExportSql($relation, $export, $transformations), + new Plugins\Export\ExportXml($relation, $export, $transformations), ]; $actual = Plugins::getChoice($exportList, 'xml'); $expected = [ diff --git a/tests/unit/SqlTest.php b/tests/unit/SqlTest.php index 25f1d776e2..c3a6b7d9c6 100644 --- a/tests/unit/SqlTest.php +++ b/tests/unit/SqlTest.php @@ -66,7 +66,7 @@ class SqlTest extends AbstractTestCase $this->dbi, $relation, new RelationCleanup($this->dbi, $relation), - new Transformations(), + new Transformations($this->dbi, $relation), new Template(), new BookmarkRepository($this->dbi, $relation), Config::getInstance(), diff --git a/tests/unit/Table/ColumnsDefinitionTest.php b/tests/unit/Table/ColumnsDefinitionTest.php index cc4b652fc4..f25f6ddffe 100644 --- a/tests/unit/Table/ColumnsDefinitionTest.php +++ b/tests/unit/Table/ColumnsDefinitionTest.php @@ -80,7 +80,7 @@ SQL; ); $relation = new Relation($dbi); - $columnsDefinition = new ColumnsDefinition($dbi, $relation, new Transformations()); + $columnsDefinition = new ColumnsDefinition($dbi, $relation, new Transformations($dbi, $relation)); Current::$database = 'sakila'; Current::$table = 'actor'; diff --git a/tests/unit/TransformationsTest.php b/tests/unit/TransformationsTest.php index 669cabc3ff..c314dad75e 100644 --- a/tests/unit/TransformationsTest.php +++ b/tests/unit/TransformationsTest.php @@ -27,7 +27,7 @@ class TransformationsTest extends AbstractTestCase { parent::setUp(); - DatabaseInterface::$instance = $this->createDatabaseInterface(); + $dbi = DatabaseInterface::$instance = $this->createDatabaseInterface(); Current::$table = 'table'; Current::$database = 'db'; $config = Config::getInstance(); @@ -40,7 +40,7 @@ class TransformationsTest extends AbstractTestCase $config->selectedServer['table_coords'] = ''; $config->selectedServer['column_info'] = 'column_info'; - $this->transformations = new Transformations(); + $this->transformations = new Transformations($dbi, new Relation($dbi)); } /** @@ -207,10 +207,10 @@ class TransformationsTest extends AbstractTestCase $dbi->expects(self::any()) ->method('tryQuery') ->willReturn(self::createStub(DummyResult::class)); - DatabaseInterface::$instance = $dbi; (new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); + $this->transformations = new Transformations($dbi, new Relation($dbi)); // Case 1 : no configuration storage $actual = $this->transformations->clear('db'); self::assertFalse($actual);