php5 test coverage

This commit is contained in:
z7zmey 2018-02-13 12:16:53 +02:00
parent b5e6d263f3
commit 172f46d0f7
5 changed files with 1553 additions and 1305 deletions

22
diff
View File

@ -159,8 +159,10 @@
159 159
-160 -160
-161 -161
-162
163 163
164 164
-165
166 166
167 167
168 168
@ -172,6 +174,7 @@
174 174
175 175
176 176
-177
178 178
179 179
180 180
@ -180,10 +183,14 @@
183 183
184 184
185 185
-186
187 187
188 188
189 189
-190
191 191
-192
-193
194 194
195 195
196 196
@ -192,7 +199,11 @@
199 199
200 200
201 201
-202
-203
204 204
-205
-206
208 208
209 209
211 211
@ -380,17 +391,6 @@
528 528
-162
-165
-177
-186
-190
-192
-193
-202
-203
-205
-206
-207 -207
-210 -210
-215 -215

2522
log

File diff suppressed because it is too large Load Diff

View File

@ -36,6 +36,45 @@ func TestSimpleClassMethod(t *testing.T) {
assertEqual(t, expected, actual) assertEqual(t, expected, actual)
} }
func TestPrivateProtectedClassMethod(t *testing.T) {
src := `<? class foo{ final private function bar() {} protected function baz() {} }`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Stmts: []node.Node{
&stmt.ClassMethod{
PhpDocComment: "",
ReturnsRef: false,
MethodName: &node.Identifier{Value: "bar"},
Modifiers: []node.Node{
&node.Identifier{Value: "final"},
&node.Identifier{Value: "private"},
},
Stmts: []node.Node{},
},
&stmt.ClassMethod{
PhpDocComment: "",
ReturnsRef: false,
MethodName: &node.Identifier{Value: "baz"},
Modifiers: []node.Node{
&node.Identifier{Value: "protected"},
},
Stmts: []node.Node{},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestPhp5ClassMethod(t *testing.T) { func TestPhp5ClassMethod(t *testing.T) {
src := `<? class foo{ public static function &bar() {} }` src := `<? class foo{ public static function &bar() {} }`
@ -91,6 +130,67 @@ func TestPhp7ClassMethod(t *testing.T) {
}, },
} }
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestAbstractClassMethod(t *testing.T) {
src := `<? abstract class Foo{ abstract public function bar(); }`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Class{
Modifiers: []node.Node{&node.Identifier{Value: "abstract"}},
ClassName: &node.Identifier{Value: "Foo"},
Stmts: []node.Node{
&stmt.ClassMethod{
PhpDocComment: "",
ReturnsRef: false,
MethodName: &node.Identifier{Value: "bar"},
Modifiers: []node.Node{
&node.Identifier{Value: "abstract"},
&node.Identifier{Value: "public"},
},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestPhp7AbstractClassMethod(t *testing.T) {
src := `<? abstract class Foo{ public function bar(): void; }`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Class{
Modifiers: []node.Node{&node.Identifier{Value: "abstract"}},
ClassName: &node.Identifier{Value: "Foo"},
Stmts: []node.Node{
&stmt.ClassMethod{
PhpDocComment: "",
ReturnsRef: false,
MethodName: &node.Identifier{Value: "bar"},
Modifiers: []node.Node{
&node.Identifier{Value: "public"},
},
ReturnType: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "void"},
},
},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php") actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual) assertEqual(t, expected, actual)
} }

View File

@ -76,6 +76,128 @@ func TestTraitsUse(t *testing.T) {
assertEqual(t, expected, actual) assertEqual(t, expected, actual)
} }
func TestTraitsUseEmptyAdaptations(t *testing.T) {
src := `<? class Foo { use Bar, Baz {} }`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Class{
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Foo"},
Stmts: []node.Node{
&stmt.TraitUse{
Traits: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
},
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
},
},
},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestTraitsUseModifier(t *testing.T) {
src := `<? class Foo { use Bar, Baz { one as public; } }`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Class{
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Foo"},
Stmts: []node.Node{
&stmt.TraitUse{
Traits: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
},
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
},
},
},
Adaptations: []node.Node{
&stmt.TraitUseAlias{
Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
},
Modifier: &node.Identifier{Value: "public"},
},
},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestTraitsUseAliasModifier(t *testing.T) {
src := `<? class Foo { use Bar, Baz { one as public two; } }`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Class{
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Foo"},
Stmts: []node.Node{
&stmt.TraitUse{
Traits: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
},
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
},
},
},
Adaptations: []node.Node{
&stmt.TraitUseAlias{
Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
},
Modifier: &node.Identifier{Value: "public"},
Alias: &node.Identifier{Value: "two"},
},
},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestTraitsUseAdaptions(t *testing.T) { func TestTraitsUseAdaptions(t *testing.T) {
src := `<? class Foo { use Bar, Baz { Bar::one insteadof Baz, Quux; Baz::one as two; } }` src := `<? class Foo { use Bar, Baz { Bar::one insteadof Baz, Quux; Baz::one as two; } }`

View File

@ -106,8 +106,8 @@ CAD;
class foo{ const FOO = 1, BAR = 2; } class foo{ const FOO = 1, BAR = 2; }
class foo{ function bar() {} } class foo{ function bar() {} }
class foo{ public static function &bar() {} } class foo{ public static function &bar() {} }
class foo{ public static function &bar() {} } class foo{ final private function bar() {} protected function baz() {} }
abstract class foo{ } abstract class foo{ abstract public function bar(); }
final class foo extends bar { } final class foo extends bar { }
final class foo implements bar { } final class foo implements bar { }
final class foo implements bar, baz { } final class foo implements bar, baz { }
@ -187,7 +187,9 @@ CAD;
throw $e; throw $e;
trait Foo {} trait Foo {}
class Foo { use Bar; } class Foo { use Bar; }
class Foo { use Bar, Baz; } class Foo { use Bar, Baz {} }
class Foo { use Bar, Baz { one as public; } }
class Foo { use Bar, Baz { one as public two; } }
class Foo { use Bar, Baz { Bar::one insteadof Baz, Quux; Baz::one as two; } } class Foo { use Bar, Baz { Bar::one insteadof Baz, Quux; Baz::one as two; } }
try {} try {}
@ -684,11 +686,20 @@ CAD;
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.ClassMethod{ &stmt.ClassMethod{
PhpDocComment: "", PhpDocComment: "",
ReturnsRef: true, ReturnsRef: false,
MethodName: &node.Identifier{Value: "bar"}, MethodName: &node.Identifier{Value: "bar"},
Modifiers: []node.Node{ Modifiers: []node.Node{
&node.Identifier{Value: "public"}, &node.Identifier{Value: "final"},
&node.Identifier{Value: "static"}, &node.Identifier{Value: "private"},
},
Stmts: []node.Node{},
},
&stmt.ClassMethod{
PhpDocComment: "",
ReturnsRef: false,
MethodName: &node.Identifier{Value: "baz"},
Modifiers: []node.Node{
&node.Identifier{Value: "protected"},
}, },
Stmts: []node.Node{}, Stmts: []node.Node{},
}, },
@ -699,7 +710,17 @@ CAD;
Modifiers: []node.Node{ Modifiers: []node.Node{
&node.Identifier{Value: "abstract"}, &node.Identifier{Value: "abstract"},
}, },
Stmts: []node.Node{}, Stmts: []node.Node{
&stmt.ClassMethod{
PhpDocComment: "",
ReturnsRef: false,
MethodName: &node.Identifier{Value: "bar"},
Modifiers: []node.Node{
&node.Identifier{Value: "abstract"},
&node.Identifier{Value: "public"},
},
},
},
}, },
&stmt.Class{ &stmt.Class{
ClassName: &node.Identifier{Value: "foo"}, ClassName: &node.Identifier{Value: "foo"},
@ -1310,6 +1331,63 @@ CAD;
}, },
}, },
}, },
&stmt.Class{
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Foo"},
Stmts: []node.Node{
&stmt.TraitUse{
Traits: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
},
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
},
},
},
Adaptations: []node.Node{
&stmt.TraitUseAlias{
Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
},
Modifier: &node.Identifier{Value: "public"},
},
},
},
},
},
&stmt.Class{
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Foo"},
Stmts: []node.Node{
&stmt.TraitUse{
Traits: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
},
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
},
},
},
Adaptations: []node.Node{
&stmt.TraitUseAlias{
Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
},
Modifier: &node.Identifier{Value: "public"},
Alias: &node.Identifier{Value: "two"},
},
},
},
},
},
&stmt.Class{ &stmt.Class{
PhpDocComment: "", PhpDocComment: "",
ClassName: &node.Identifier{Value: "Foo"}, ClassName: &node.Identifier{Value: "Foo"},