Skip to content

Commit 27bdd0d

Browse files
committed
Extract InsertEdit dependencies to constructor params
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 866861e commit 27bdd0d

File tree

4 files changed

+139
-42
lines changed

4 files changed

+139
-42
lines changed

libraries/classes/InsertEdit.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<?php
2-
/**
3-
* set of functions with the insert/edit features in pma
4-
*/
52

63
declare(strict_types=1);
74

@@ -54,16 +51,9 @@
5451
use const ENT_COMPAT;
5552
use const PASSWORD_DEFAULT;
5653

57-
/**
58-
* PhpMyAdmin\InsertEdit class
59-
*/
6054
class InsertEdit
6155
{
62-
/**
63-
* DatabaseInterface instance
64-
*
65-
* @var DatabaseInterface
66-
*/
56+
/** @var DatabaseInterface */
6757
private $dbi;
6858

6959
/** @var Relation */
@@ -76,18 +66,20 @@ class InsertEdit
7666
private $fileListing;
7767

7868
/** @var Template */
79-
public $template;
80-
81-
/**
82-
* @param DatabaseInterface $dbi DatabaseInterface instance
83-
*/
84-
public function __construct(DatabaseInterface $dbi)
85-
{
69+
private $template;
70+
71+
public function __construct(
72+
DatabaseInterface $dbi,
73+
Relation $relation,
74+
Transformations $transformations,
75+
FileListing $fileListing,
76+
Template $template
77+
) {
8678
$this->dbi = $dbi;
87-
$this->relation = new Relation($this->dbi);
88-
$this->transformations = new Transformations();
89-
$this->fileListing = new FileListing();
90-
$this->template = new Template();
79+
$this->relation = $relation;
80+
$this->transformations = $transformations;
81+
$this->fileListing = $fileListing;
82+
$this->template = $template;
9183
}
9284

9385
/**

libraries/services.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
'expression_language' => [
8888
'class' => Symfony\Component\ExpressionLanguage\ExpressionLanguage::class,
8989
],
90+
'file_listing' => ['class' => PhpMyAdmin\FileListing::class],
9091
'flash' => [
9192
'class' => PhpMyAdmin\FlashMessages::class,
9293
],
@@ -102,7 +103,7 @@
102103
],
103104
'insert_edit' => [
104105
'class' => PhpMyAdmin\InsertEdit::class,
105-
'arguments' => ['@dbi'],
106+
'arguments' => ['@dbi', '@relation', '@transformations', '@file_listing', '@template'],
106107
],
107108
'navigation' => [
108109
'class' => PhpMyAdmin\Navigation\Navigation::class,

test/classes/Controllers/Table/ChangeControllerTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
use PhpMyAdmin\Config\PageSettings;
88
use PhpMyAdmin\ConfigStorage\Relation;
99
use PhpMyAdmin\Controllers\Table\ChangeController;
10+
use PhpMyAdmin\FileListing;
1011
use PhpMyAdmin\InsertEdit;
1112
use PhpMyAdmin\Template;
1213
use PhpMyAdmin\Tests\AbstractTestCase;
1314
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
15+
use PhpMyAdmin\Transformations;
1416

1517
/**
1618
* @covers \PhpMyAdmin\Controllers\Table\ChangeController
@@ -37,11 +39,13 @@ public function testChangeController(): void
3739
$response = new ResponseRenderer();
3840
$pageSettings = new PageSettings('Edit');
3941

42+
$relation = new Relation($dbi);
43+
$template = new Template();
4044
(new ChangeController(
4145
$response,
42-
new Template(),
43-
new InsertEdit($dbi),
44-
new Relation($dbi)
46+
$template,
47+
new InsertEdit($dbi, $relation, new Transformations(), new FileListing(), $template),
48+
$relation
4549
))();
4650
$actual = $response->getHTMLResult();
4751

test/classes/InsertEditTest.php

Lines changed: 116 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44

55
namespace PhpMyAdmin\Tests;
66

7+
use PhpMyAdmin\ConfigStorage\Relation;
78
use PhpMyAdmin\Core;
89
use PhpMyAdmin\DatabaseInterface;
910
use PhpMyAdmin\Dbal\Warning;
1011
use PhpMyAdmin\FieldMetadata;
12+
use PhpMyAdmin\FileListing;
1113
use PhpMyAdmin\InsertEdit;
1214
use PhpMyAdmin\ResponseRenderer;
1315
use PhpMyAdmin\Table;
16+
use PhpMyAdmin\Template;
1417
use PhpMyAdmin\Tests\Stubs\DummyResult;
18+
use PhpMyAdmin\Transformations;
1519
use PhpMyAdmin\Url;
1620
use ReflectionProperty;
1721
use stdClass;
@@ -70,7 +74,13 @@ protected function setUp(): void
7074
$GLOBALS['cfg']['Confirm'] = true;
7175
$GLOBALS['cfg']['LoginCookieValidity'] = 1440;
7276
$GLOBALS['cfg']['enable_drag_drop_import'] = true;
73-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
77+
$this->insertEdit = new InsertEdit(
78+
$this->dbi,
79+
new Relation($this->dbi),
80+
new Transformations(),
81+
new FileListing(),
82+
new Template()
83+
);
7484
}
7585

7686
/**
@@ -198,7 +208,13 @@ public function testAnalyzeWhereClause(): void
198208
);
199209

200210
$GLOBALS['dbi'] = $dbi;
201-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
211+
$this->insertEdit = new InsertEdit(
212+
$GLOBALS['dbi'],
213+
new Relation($GLOBALS['dbi']),
214+
new Transformations(),
215+
new FileListing(),
216+
new Template()
217+
);
202218
$result = $this->callFunction(
203219
$this->insertEdit,
204220
InsertEdit::class,
@@ -252,7 +268,13 @@ public function testShowEmptyResultMessageOrSetUniqueCondition(): void
252268
->will($this->returnValue($meta_arr));
253269

254270
$GLOBALS['dbi'] = $dbi;
255-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
271+
$this->insertEdit = new InsertEdit(
272+
$GLOBALS['dbi'],
273+
new Relation($GLOBALS['dbi']),
274+
new Transformations(),
275+
new FileListing(),
276+
new Template()
277+
);
256278

257279
$result = $this->callFunction(
258280
$this->insertEdit,
@@ -361,7 +383,13 @@ public function testLoadFirstRow($configValue, array $rowsValue): void
361383
->will($this->returnValue($resultStub));
362384

363385
$GLOBALS['dbi'] = $dbi;
364-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
386+
$this->insertEdit = new InsertEdit(
387+
$GLOBALS['dbi'],
388+
new Relation($GLOBALS['dbi']),
389+
new Transformations(),
390+
new FileListing(),
391+
new Template()
392+
);
365393

366394
$result = $this->callFunction(
367395
$this->insertEdit,
@@ -1414,7 +1442,13 @@ public function testGetSpecialCharsAndBackupFieldForExistingRow(): void
14141442
->getMock();
14151443

14161444
$GLOBALS['dbi'] = $dbi;
1417-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
1445+
$this->insertEdit = new InsertEdit(
1446+
$GLOBALS['dbi'],
1447+
new Relation($GLOBALS['dbi']),
1448+
new Transformations(),
1449+
new FileListing(),
1450+
new Template()
1451+
);
14181452

14191453
$current_row['f'] = '123';
14201454
$extracted_columnspec['spec_in_brackets'] = '20';
@@ -1639,7 +1673,13 @@ public function testSetSessionForEditNext(): void
16391673
$GLOBALS['dbi'] = $dbi;
16401674
$GLOBALS['db'] = 'db';
16411675
$GLOBALS['table'] = 'table';
1642-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
1676+
$this->insertEdit = new InsertEdit(
1677+
$GLOBALS['dbi'],
1678+
new Relation($GLOBALS['dbi']),
1679+
new Transformations(),
1680+
new FileListing(),
1681+
new Template()
1682+
);
16431683
$this->insertEdit->setSessionForEditNext('`a` = 2');
16441684

16451685
$this->assertEquals('CONCAT(`table`.`orgname`) IS NULL', $_SESSION['edit_next']);
@@ -1738,7 +1778,13 @@ public function testExecuteSqlQuery(): void
17381778
$GLOBALS['cfg']['IgnoreMultiSubmitErrors'] = false;
17391779
$_POST['submit_type'] = '';
17401780

1741-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
1781+
$this->insertEdit = new InsertEdit(
1782+
$GLOBALS['dbi'],
1783+
new Relation($GLOBALS['dbi']),
1784+
new Transformations(),
1785+
new FileListing(),
1786+
new Template()
1787+
);
17421788
$result = $this->insertEdit->executeSqlQuery([], $query);
17431789

17441790
$this->assertEquals(['sql_query' => 'SELECT * FROM `test_db`.`test_table`;'], $result[0]);
@@ -1759,7 +1805,13 @@ public function testExecuteSqlQueryWithTryQuery(): void
17591805
$GLOBALS['cfg']['IgnoreMultiSubmitErrors'] = true;
17601806
$_POST['submit_type'] = '';
17611807

1762-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
1808+
$this->insertEdit = new InsertEdit(
1809+
$GLOBALS['dbi'],
1810+
new Relation($GLOBALS['dbi']),
1811+
new Transformations(),
1812+
new FileListing(),
1813+
new Template()
1814+
);
17631815
$result = $this->insertEdit->executeSqlQuery([], $query);
17641816

17651817
$this->assertEquals(['sql_query' => 'SELECT * FROM `test_db`.`test_table`;'], $result[0]);
@@ -1786,7 +1838,13 @@ public function testGetWarningMessages(): void
17861838
->will($this->returnValue($warnings));
17871839

17881840
$GLOBALS['dbi'] = $dbi;
1789-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
1841+
$this->insertEdit = new InsertEdit(
1842+
$GLOBALS['dbi'],
1843+
new Relation($GLOBALS['dbi']),
1844+
new Transformations(),
1845+
new FileListing(),
1846+
new Template()
1847+
);
17901848

17911849
$result = $this->callFunction(
17921850
$this->insertEdit,
@@ -1831,7 +1889,13 @@ public function testGetDisplayValueForForeignTableColumn(): void
18311889
->will($this->returnValue('2'));
18321890

18331891
$GLOBALS['dbi'] = $dbi;
1834-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
1892+
$this->insertEdit = new InsertEdit(
1893+
$GLOBALS['dbi'],
1894+
new Relation($GLOBALS['dbi']),
1895+
new Transformations(),
1896+
new FileListing(),
1897+
new Template()
1898+
);
18351899

18361900
$result = $this->insertEdit->getDisplayValueForForeignTableColumn('=1', $map, 'f');
18371901

@@ -2054,7 +2118,13 @@ public function testGetCurrentValueAsAnArrayForMultipleEdit(): void
20542118
->will($this->returnValue('uuid1234'));
20552119

20562120
$GLOBALS['dbi'] = $dbi;
2057-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
2121+
$this->insertEdit = new InsertEdit(
2122+
$GLOBALS['dbi'],
2123+
new Relation($GLOBALS['dbi']),
2124+
new Transformations(),
2125+
new FileListing(),
2126+
new Template()
2127+
);
20582128

20592129
$result = $this->insertEdit->getCurrentValueAsAnArrayForMultipleEdit(
20602130
$multi_edit_funcs,
@@ -2118,7 +2188,13 @@ public function testGetCurrentValueAsAnArrayForMultipleEdit(): void
21182188
*/
21192189
public function testGetCurrentValueForDifferentTypes(): void
21202190
{
2121-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
2191+
$this->insertEdit = new InsertEdit(
2192+
$GLOBALS['dbi'],
2193+
new Relation($GLOBALS['dbi']),
2194+
new Transformations(),
2195+
new FileListing(),
2196+
new Template()
2197+
);
21222198

21232199
$result = $this->insertEdit->getCurrentValueForDifferentTypes(
21242200
'123',
@@ -2355,7 +2431,13 @@ public function testVerifyWhetherValueCanBeTruncatedAndAppendExtraData(): void
23552431
->will($this->onConsecutiveCalls(false, '123', '2013-08-28 06:34:14'));
23562432

23572433
$GLOBALS['dbi'] = $dbi;
2358-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
2434+
$this->insertEdit = new InsertEdit(
2435+
$GLOBALS['dbi'],
2436+
new Relation($GLOBALS['dbi']),
2437+
new Transformations(),
2438+
new FileListing(),
2439+
new Template()
2440+
);
23592441

23602442
$this->insertEdit->verifyWhetherValueCanBeTruncatedAndAppendExtraData('db', 'table', 'a', $extra_data);
23612443

@@ -2394,7 +2476,13 @@ public function testGetTableColumns(): void
23942476
]));
23952477

23962478
$GLOBALS['dbi'] = $dbi;
2397-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
2479+
$this->insertEdit = new InsertEdit(
2480+
$GLOBALS['dbi'],
2481+
new Relation($GLOBALS['dbi']),
2482+
new Transformations(),
2483+
new FileListing(),
2484+
new Template()
2485+
);
23982486

23992487
$result = $this->insertEdit->getTableColumns('db', 'table');
24002488

@@ -2442,7 +2530,13 @@ public function testDetermineInsertOrEdit(): void
24422530
$response->setAccessible(true);
24432531
$response->setValue($responseMock);
24442532

2445-
$this->insertEdit = new InsertEdit($dbi);
2533+
$this->insertEdit = new InsertEdit(
2534+
$GLOBALS['dbi'],
2535+
new Relation($GLOBALS['dbi']),
2536+
new Transformations(),
2537+
new FileListing(),
2538+
new Template()
2539+
);
24462540

24472541
$result = $this->insertEdit->determineInsertOrEdit('1', 'db', 'table');
24482542

@@ -2521,7 +2615,13 @@ public function testGetCommentsMap(): void
25212615
);
25222616

25232617
$GLOBALS['dbi'] = $dbi;
2524-
$this->insertEdit = new InsertEdit($GLOBALS['dbi']);
2618+
$this->insertEdit = new InsertEdit(
2619+
$GLOBALS['dbi'],
2620+
new Relation($GLOBALS['dbi']),
2621+
new Transformations(),
2622+
new FileListing(),
2623+
new Template()
2624+
);
25252625

25262626
$this->assertEquals(
25272627
[],

0 commit comments

Comments
 (0)