|
16 | 16 | */ |
17 | 17 | class LintControllerTest extends AbstractTestCase |
18 | 18 | { |
19 | | - public function testInvoke(): void |
| 19 | + public function testWithoutParams(): void |
20 | 20 | { |
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;'; |
22 | 33 |
|
23 | | - (new LintController(new ResponseRenderer(), new Template()))(); |
| 34 | + $this->getLintController()(); |
24 | 35 |
|
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([ |
26 | 46 | [ |
27 | 47 | 'message' => 'An alias was previously found. (near <code>`actor_id`</code>)', |
28 | 48 | 'fromLine' => 0, |
@@ -55,10 +75,18 @@ public function testInvoke(): void |
55 | 75 | 'toColumn' => 43, |
56 | 76 | 'severity' => 'error', |
57 | 77 | ], |
58 | | - ]; |
| 78 | + ]); |
| 79 | + $this->assertNotFalse($expectedJson); |
| 80 | + |
| 81 | + $this->getLintController()(); |
59 | 82 |
|
60 | 83 | $output = $this->getActualOutputForAssertion(); |
61 | 84 | $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()); |
63 | 91 | } |
64 | 92 | } |
0 commit comments