@@ -15,18 +15,12 @@ class ParseErrorsTest extends TestCase
15
15
*/
16
16
private $ textDocument ;
17
17
18
- public function setUp ()
19
- {
20
- $ client = new LanguageClient (new MockProtocolStream ());
21
- $ project = new Project ($ client );
22
- $ this ->textDocument = new Server \TextDocument ($ project , $ client );
23
- }
18
+ private $ args ;
24
19
25
- public function testParseErrorsArePublishedAsDiagnostics ()
20
+ public function setUp ()
26
21
{
27
- $ args = null ;
28
22
$ client = new LanguageClient (new MockProtocolStream ());
29
- $ client ->textDocument = new class ($ args ) extends Client \TextDocument {
23
+ $ client ->textDocument = new class ($ this -> args ) extends Client \TextDocument {
30
24
private $ args ;
31
25
public function __construct (&$ args )
32
26
{
@@ -38,18 +32,22 @@ public function publishDiagnostics(string $uri, array $diagnostics)
38
32
$ this ->args = func_get_args ();
39
33
}
40
34
};
41
-
42
35
$ project = new Project ($ client );
36
+ $ this ->textDocument = new Server \TextDocument ($ project , $ client );
37
+ }
43
38
44
- $ textDocument = new Server \TextDocument ($ project , $ client );
45
-
46
- // Trigger parsing of source
39
+ private function openFile ($ file ) {
47
40
$ textDocumentItem = new TextDocumentItem ();
48
41
$ textDocumentItem ->uri = 'whatever ' ;
49
42
$ textDocumentItem ->languageId = 'php ' ;
50
43
$ textDocumentItem ->version = 1 ;
51
- $ textDocumentItem ->text = file_get_contents (__DIR__ . '/../../../fixtures/invalid_file.php ' );
52
- $ textDocument ->didOpen ($ textDocumentItem );
44
+ $ textDocumentItem ->text = file_get_contents ($ file );
45
+ $ this ->textDocument ->didOpen ($ textDocumentItem );
46
+ }
47
+
48
+ public function testParseErrorsArePublishedAsDiagnostics ()
49
+ {
50
+ $ this ->openFile (__DIR__ . '/../../../fixtures/invalid_file.php ' );
53
51
$ this ->assertEquals ([
54
52
'whatever ' ,
55
53
[[
@@ -68,6 +66,30 @@ public function publishDiagnostics(string $uri, array $diagnostics)
68
66
'source ' => 'php ' ,
69
67
'message ' => "Syntax error, unexpected T_CLASS, expecting T_STRING "
70
68
]]
71
- ], json_decode (json_encode ($ args ), true ));
69
+ ], json_decode (json_encode ($ this ->args ), true ));
70
+ }
71
+
72
+ public function testParseErrorsWithOnlyStartLine ()
73
+ {
74
+ $ this ->openFile (__DIR__ . '/../../../fixtures/namespace_not_first.php ' );
75
+ $ this ->assertEquals ([
76
+ 'whatever ' ,
77
+ [[
78
+ 'range ' => [
79
+ 'start ' => [
80
+ 'line ' => 4 ,
81
+ 'character ' => 0
82
+ ],
83
+ 'end ' => [
84
+ 'line ' => 4 ,
85
+ 'character ' => 0
86
+ ]
87
+ ],
88
+ 'severity ' => DiagnosticSeverity::ERROR ,
89
+ 'code ' => null ,
90
+ 'source ' => 'php ' ,
91
+ 'message ' => "Namespace declaration statement has to be the very first statement in the script "
92
+ ]]
93
+ ], json_decode (json_encode ($ this ->args ), true ));
72
94
}
73
95
}
0 commit comments