Skip to content

Commit dc67af6

Browse files
committed
tests: added
1 parent c774e98 commit dc67af6

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?php
2+
3+
/**
4+
* Test: PHP native error messages for undeclared method.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Tester\Assert;
10+
11+
require __DIR__ . '/../bootstrap.php';
12+
13+
14+
class ParentClass
15+
{
16+
public function callPrivate()
17+
{
18+
$this->privateMethod();
19+
}
20+
21+
22+
public function callPrivateStatic()
23+
{
24+
static::privateStaticMethod();
25+
}
26+
27+
28+
private function callPrivateParent()
29+
{
30+
}
31+
}
32+
33+
34+
class InterClass extends ParentClass
35+
{
36+
public function callParents()
37+
{
38+
parent::callParents();
39+
}
40+
}
41+
42+
43+
class ChildClass extends InterClass
44+
{
45+
public function callParents()
46+
{
47+
parent::callParents();
48+
}
49+
50+
51+
public function callMissingParent()
52+
{
53+
parent::callMissingParent();
54+
}
55+
56+
57+
public static function callMissingParentStatic()
58+
{
59+
parent::callMissingParentStatic();
60+
}
61+
62+
63+
public function callPrivateParent()
64+
{
65+
parent::callPrivateParent();
66+
}
67+
68+
69+
protected function protectedMethod()
70+
{
71+
}
72+
73+
74+
protected static function protectedStaticMethod()
75+
{
76+
}
77+
78+
79+
private function privateMethod()
80+
{
81+
}
82+
83+
84+
private static function privateStaticMethod()
85+
{
86+
}
87+
}
88+
89+
90+
91+
Assert::exception(function () {
92+
$obj = new ParentClass;
93+
$obj->undef();
94+
}, Error::class, 'Call to undefined method ParentClass::undef()');
95+
96+
Assert::exception(function () {
97+
$obj = new ChildClass;
98+
$obj->undef();
99+
}, Error::class, 'Call to undefined method ChildClass::undef()');
100+
101+
Assert::exception(function () {
102+
$obj = new ChildClass;
103+
$obj->callParents();
104+
}, Error::class, 'Call to undefined method ParentClass::callParents()');
105+
106+
Assert::exception(function () {
107+
$obj = new ChildClass;
108+
$obj->callMissingParent();
109+
}, Error::class, 'Call to undefined method InterClass::callMissingParent()');
110+
111+
Assert::exception(function () {
112+
$obj = new ChildClass;
113+
$obj->callMissingParentStatic();
114+
}, Error::class, 'Call to undefined method InterClass::callMissingParentStatic()');
115+
116+
Assert::exception(function () {
117+
$obj = new ChildClass;
118+
$obj::callMissingParentStatic();
119+
}, Error::class, 'Call to undefined method InterClass::callMissingParentStatic()');
120+
121+
Assert::exception(function () {
122+
$obj = new ChildClass;
123+
$obj->callPrivateParent();
124+
}, Error::class, 'Call to private method ParentClass::callPrivateParent() from scope ChildClass');
125+
126+
Assert::exception(function () {
127+
$obj = new ChildClass;
128+
$obj->protectedMethod();
129+
}, Error::class, 'Call to protected method ChildClass::protectedMethod() from global scope');
130+
131+
Assert::exception(function () {
132+
$obj = new ChildClass;
133+
$obj->protectedStaticMethod();
134+
}, Error::class, 'Call to protected method ChildClass::protectedStaticMethod() from global scope');
135+
136+
Assert::exception(function () {
137+
$obj = new ChildClass;
138+
$obj::protectedStaticMethod();
139+
}, Error::class, 'Call to protected method ChildClass::protectedStaticMethod() from global scope');
140+
141+
Assert::exception(function () {
142+
$obj = new ChildClass;
143+
$obj->callPrivate();
144+
}, Error::class, 'Call to private method ChildClass::privateMethod() from scope ParentClass');
145+
146+
Assert::exception(function () {
147+
$obj = new ChildClass;
148+
$obj->callPrivateStatic();
149+
}, Error::class, 'Call to private method ChildClass::privateStaticMethod() from scope ParentClass');

0 commit comments

Comments
 (0)