Skip to content

Commit 37d269c

Browse files
committed
Add more tests for LintController
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent c5cb4f9 commit 37d269c

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

test/classes/Controllers/LintControllerTest.php

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,33 @@
1616
*/
1717
class LintControllerTest extends AbstractTestCase
1818
{
19-
public function testInvoke(): void
19+
public function testWithoutParams(): void
2020
{
21-
$_POST['sql_query'] = 'SELECT * FROM `actor` WHEREE `actor_id` = 1;';
21+
$_POST = [];
22+
23+
$this->getLintController()();
24+
25+
$output = $this->getActualOutputForAssertion();
26+
$this->assertJson($output);
27+
$this->assertJsonStringEqualsJsonString('[]', $output);
28+
}
29+
30+
public function testWithoutSqlErrors(): void
31+
{
32+
$_POST['sql_query'] = 'SELECT * FROM `actor` WHERE `actor_id` = 1;';
2233

23-
(new LintController(new ResponseRenderer(), new Template()))();
34+
$this->getLintController()();
2435

25-
$expectedJson = [
36+
$output = $this->getActualOutputForAssertion();
37+
$this->assertJson($output);
38+
$this->assertJsonStringEqualsJsonString('[]', $output);
39+
}
40+
41+
public function testWithSqlErrors(): void
42+
{
43+
$_POST['sql_query'] = 'SELECT * FROM `actor` WHEREE `actor_id` = 1;';
44+
45+
$expectedJson = json_encode([
2646
[
2747
'message' => 'An alias was previously found. (near <code>`actor_id`</code>)',
2848
'fromLine' => 0,
@@ -55,10 +75,18 @@ public function testInvoke(): void
5575
'toColumn' => 43,
5676
'severity' => 'error',
5777
],
58-
];
78+
]);
79+
$this->assertNotFalse($expectedJson);
80+
81+
$this->getLintController()();
5982

6083
$output = $this->getActualOutputForAssertion();
6184
$this->assertJson($output);
62-
$this->assertJsonStringEqualsJsonString(json_encode($expectedJson), $output);
85+
$this->assertJsonStringEqualsJsonString($expectedJson, $output);
86+
}
87+
88+
private function getLintController(): LintController
89+
{
90+
return new LintController(new ResponseRenderer(), new Template());
6391
}
6492
}

0 commit comments

Comments
 (0)