99use PhpMyAdmin \Plugins \Import \ImportLdi ;
1010use PhpMyAdmin \Tests \AbstractTestCase ;
1111use PhpMyAdmin \Tests \Stubs \DummyResult ;
12- use PHPUnit \Framework \MockObject \MockObject ;
1312
1413use function __ ;
1514
1817 */
1918class ImportLdiTest extends AbstractTestCase
2019{
21- /** @var ImportLdi */
22- protected $ object ;
23-
24- /** @var DatabaseInterface */
25- protected $ dbi ;
26-
2720 /**
2821 * Sets up the fixture, for example, opens a network connection.
2922 * This method is called before a test is executed.
@@ -66,24 +59,6 @@ protected function setUp(): void
6659 $ GLOBALS ['cfg ' ]['Import ' ]['ldi_columns ' ] = '' ;
6760 $ GLOBALS ['cfg ' ]['Import ' ]['ldi_local_option ' ] = false ;
6861 $ GLOBALS ['table ' ] = 'phpmyadmintest ' ;
69-
70- //Mock DBI
71- $ this ->dbi = $ this ->getMockBuilder (DatabaseInterface::class)
72- ->disableOriginalConstructor ()
73- ->getMock ();
74- $ GLOBALS ['dbi ' ] = $ this ->dbi ;
75-
76- $ this ->object = new ImportLdi ();
77- }
78-
79- /**
80- * Tears down the fixture, for example, closes a network connection.
81- * This method is called after a test is executed.
82- */
83- protected function tearDown (): void
84- {
85- parent ::tearDown ();
86- unset($ this ->object );
8762 }
8863
8964 /**
@@ -93,7 +68,7 @@ protected function tearDown(): void
9368 */
9469 public function testGetProperties (): void
9570 {
96- $ properties = $ this -> object ->getProperties ();
71+ $ properties = ( new ImportLdi ()) ->getProperties ();
9772 $ this ->assertEquals (
9873 __ ('CSV using LOAD DATA ' ),
9974 $ properties ->getText ()
@@ -111,12 +86,8 @@ public function testGetProperties(): void
11186 */
11287 public function testGetPropertiesAutoLdi (): void
11388 {
114- /**
115- * The \PhpMyAdmin\DatabaseInterface mocked object
116- *
117- * @var MockObject $dbi
118- */
119- $ dbi = $ this ->dbi ;
89+ $ dbi = $ this ->createMock (DatabaseInterface::class);
90+ $ GLOBALS ['dbi ' ] = $ dbi ;
12091
12192 $ resultStub = $ this ->createMock (DummyResult::class);
12293
@@ -130,8 +101,7 @@ public function testGetPropertiesAutoLdi(): void
130101 ->will ($ this ->returnValue ('ON ' ));
131102
132103 $ GLOBALS ['cfg ' ]['Import ' ]['ldi_local_option ' ] = 'auto ' ;
133- $ this ->object = new ImportLdi ();
134- $ properties = $ this ->object ->getProperties ();
104+ $ properties = (new ImportLdi ())->getProperties ();
135105 $ this ->assertTrue ($ GLOBALS ['cfg ' ]['Import ' ]['ldi_local_option ' ]);
136106 $ this ->assertEquals (
137107 __ ('CSV using LOAD DATA ' ),
@@ -153,12 +123,7 @@ public function testDoImport(): void
153123 //$sql_query_disabled will show the import SQL detail
154124
155125 $ GLOBALS ['sql_query_disabled ' ] = false ;
156- /**
157- * The \PhpMyAdmin\DatabaseInterface mocked object
158- *
159- * @var MockObject $dbi
160- */
161- $ dbi = $ this ->dbi ;
126+ $ dbi = $ this ->createMock (DatabaseInterface::class);
162127 $ dbi ->expects ($ this ->any ())->method ('escapeString ' )
163128 ->will ($ this ->returnArgument (0 ));
164129 $ GLOBALS ['dbi ' ] = $ dbi ;
@@ -167,7 +132,7 @@ public function testDoImport(): void
167132 $ importHandle ->open ();
168133
169134 //Test function called
170- $ this -> object ->doImport ($ importHandle );
135+ ( new ImportLdi ()) ->doImport ($ importHandle );
171136
172137 //asset that all sql are executed
173138 $ this ->assertStringContainsString (
@@ -188,7 +153,7 @@ public function testDoImportInvalidFile(): void
188153 $ GLOBALS ['import_file ' ] = 'none ' ;
189154
190155 //Test function called
191- $ this -> object ->doImport ();
156+ ( new ImportLdi ()) ->doImport ();
192157
193158 // We handle only some kind of data!
194159 $ this ->assertStringContainsString (
@@ -209,12 +174,7 @@ public function testDoImportLDISetting(): void
209174 //$sql_query_disabled will show the import SQL detail
210175
211176 $ GLOBALS ['sql_query_disabled ' ] = false ;
212- /**
213- * The \PhpMyAdmin\DatabaseInterface mocked object
214- *
215- * @var MockObject $dbi
216- */
217- $ dbi = $ this ->dbi ;
177+ $ dbi = $ this ->createMock (DatabaseInterface::class);
218178 $ dbi ->expects ($ this ->any ())->method ('escapeString ' )
219179 ->will ($ this ->returnArgument (0 ));
220180 $ GLOBALS ['dbi ' ] = $ dbi ;
@@ -231,7 +191,7 @@ public function testDoImportLDISetting(): void
231191 $ importHandle ->open ();
232192
233193 //Test function called
234- $ this -> object ->doImport ($ importHandle );
194+ ( new ImportLdi ()) ->doImport ($ importHandle );
235195
236196 //asset that all sql are executed
237197 //replace
0 commit comments