Skip to content

Commit 4be2d14

Browse files
committed
Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
2 parents c097b1d + f2e03dd commit 4be2d14

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Controllers/Import/SimulateDmlController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ static function ($token): bool {
7575

7676
private function process(Parser $parser): void
7777
{
78+
if ($parser->errors !== []) {
79+
$this->error = $parser->errors[0]->getMessage();
80+
81+
return;
82+
}
83+
7884
foreach ($parser->statements as $statement) {
7985
if (
8086
! $statement instanceof UpdateStatement && ! $statement instanceof DeleteStatement

tests/unit/Controllers/Import/SimulateDmlControllerTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpMyAdmin\Core;
99
use PhpMyAdmin\Current;
1010
use PhpMyAdmin\Html\Generator;
11+
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
1112
use PhpMyAdmin\Import\SimulateDml;
1213
use PhpMyAdmin\SqlParser\Parser;
1314
use PhpMyAdmin\SqlParser\Statements\DeleteStatement;
@@ -19,6 +20,7 @@
1920
use PHPUnit\Framework\Attributes\DataProvider;
2021

2122
use function count;
23+
use function json_decode;
2224

2325
#[CoversClass(SimulateDmlController::class)]
2426
final class SimulateDmlControllerTest extends AbstractTestCase
@@ -276,4 +278,31 @@ public static function providerForTestGetMatchedRows(): array
276278
],
277279
];
278280
}
281+
282+
public function testStatementWithParsingError(): void
283+
{
284+
Current::$sqlQuery = 'UPDATE actor SET';
285+
286+
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
287+
->withParsedBody(['sql_delimiter' => ';']);
288+
289+
$responseRenderer = new ResponseRenderer();
290+
$responseRenderer->setAjax(true);
291+
$controller = new SimulateDmlController($responseRenderer, new SimulateDml($this->createDatabaseInterface()));
292+
$response = $controller($request);
293+
294+
$expectedMessage = <<<'HTML'
295+
<div class="alert alert-danger" role="alert">
296+
<img src="themes/dot.gif" title="" alt="" class="icon ic_s_error"> Missing assignment in SET operation.
297+
</div>
298+
299+
HTML;
300+
301+
$body = (string) $response->getBody();
302+
self::assertJson($body);
303+
self::assertSame(
304+
['message' => $expectedMessage, 'sql_data' => false, 'success' => true],
305+
json_decode($body, true),
306+
);
307+
}
279308
}

0 commit comments

Comments
 (0)