createDatabaseInterface(); } public function testWithoutParams(): void { $request = $this->createStub(ServerRequest::class); $request->method('getParsedBodyParam')->willReturnMap([ ['sql_query', '', ''], ['options', null, null], ]); $this->getLintController()($request); $output = $this->getActualOutputForAssertion(); $this->assertJson($output); $this->assertJsonStringEqualsJsonString('[]', $output); } public function testWithoutSqlErrors(): void { $request = $this->createStub(ServerRequest::class); $request->method('getParsedBodyParam')->willReturnMap([ ['sql_query', '', 'SELECT * FROM `actor` WHERE `actor_id` = 1;'], ['options', null, null], ]); $this->getLintController()($request); $output = $this->getActualOutputForAssertion(); $this->assertJson($output); $this->assertJsonStringEqualsJsonString('[]', $output); } public function testWithSqlErrors(): void { $expectedJson = json_encode([ [ 'message' => 'An alias was previously found. (near `actor_id`)', 'fromLine' => 0, 'fromColumn' => 29, 'toLine' => 0, 'toColumn' => 39, 'severity' => 'error', ], [ 'message' => 'Unexpected token. (near `actor_id`)', 'fromLine' => 0, 'fromColumn' => 29, 'toLine' => 0, 'toColumn' => 39, 'severity' => 'error', ], [ 'message' => 'Unexpected token. (near =)', 'fromLine' => 0, 'fromColumn' => 40, 'toLine' => 0, 'toColumn' => 41, 'severity' => 'error', ], [ 'message' => 'Unexpected token. (near 1)', 'fromLine' => 0, 'fromColumn' => 42, 'toLine' => 0, 'toColumn' => 43, 'severity' => 'error', ], ]); $this->assertNotFalse($expectedJson); $request = $this->createStub(ServerRequest::class); $request->method('getParsedBodyParam')->willReturnMap([ ['sql_query', '', 'SELECT * FROM `actor` WHEREE `actor_id` = 1;'], ['options', null, null], ]); $this->getLintController()($request); $output = $this->getActualOutputForAssertion(); $this->assertJson($output); $this->assertJsonStringEqualsJsonString($expectedJson, $output); } private function getLintController(): LintController { return new LintController(new ResponseRenderer(), new Template()); } }