11<?php
22
33/**
4- * Test: Nette\SmartObject undeclared method.
4+ * Test: Nette\SmartObject error messages for undeclared method.
55 */
66
77declare (strict_types=1 );
@@ -11,51 +11,147 @@ use Tester\Assert;
1111require __DIR__ . '/../bootstrap.php ' ;
1212
1313
14- class TestClass
14+ class ParentClass
1515{
1616 use Nette \SmartObject;
1717
18- private function methodO ()
18+ public function callPrivate ()
1919 {
20+ $ this ->privateMethod ();
2021 }
2122
2223
23- public function methodO2 ()
24+ public function callPrivateStatic ()
2425 {
26+ static ::privateStaticMethod ();
2527 }
2628
2729
28- private static function methodS ()
30+ private function callPrivateParent ()
2931 {
3032 }
33+ }
3134
3235
33- public static function methodS2 ()
36+ class InterClass extends ParentClass
37+ {
38+ public function callParents ()
3439 {
40+ parent ::callParents ();
3541 }
3642}
3743
3844
45+ class ChildClass extends InterClass
46+ {
47+ public function callParents ()
48+ {
49+ parent ::callParents ();
50+ }
51+
52+
53+ public function callMissingParent ()
54+ {
55+ parent ::callMissingParent ();
56+ }
57+
58+
59+ public static function callMissingParentStatic ()
60+ {
61+ parent ::callMissingParentStatic ();
62+ }
63+
64+
65+ public function callPrivateParent ()
66+ {
67+ parent ::callPrivateParent ();
68+ }
69+
70+
71+ protected function protectedMethod ()
72+ {
73+ }
74+
75+
76+ protected static function protectedStaticMethod ()
77+ {
78+ }
79+
80+
81+ private function privateMethod ()
82+ {
83+ }
84+
85+
86+ private static function privateStaticMethod ()
87+ {
88+ }
89+ }
90+
91+
92+
3993Assert::exception (function () {
40- $ obj = new TestClass ;
41- $ obj ->abc ();
42- }, Nette \MemberAccessException::class, 'Call to undefined method TestClass::abc (). ' );
94+ $ obj = new ParentClass ;
95+ $ obj ->undef ();
96+ }, Nette \MemberAccessException::class, 'Call to undefined method ParentClass::undef (). ' );
4397
4498Assert::exception (function () {
45- $ obj = new TestClass ;
46- $ obj ->method ();
47- }, Nette \MemberAccessException::class, 'Call to undefined method TestClass::method(), did you mean methodO2()? ' );
99+ $ obj = new ChildClass ;
100+ $ obj ->undef ();
101+ }, Nette \MemberAccessException::class, 'Call to undefined method ChildClass::undef(). ' );
48102
49103Assert::exception (function () {
50- TestClass::abc ();
51- }, Nette \MemberAccessException::class, 'Call to undefined static method TestClass::abc(). ' );
104+ $ obj = new ChildClass ;
105+ $ obj ->callParents ();
106+ }, Nette \MemberAccessException::class, 'Call to undefined method ParentClass::callParents(). ' );
52107
53108Assert::exception (function () {
54- TestClass::method ();
55- }, Nette \MemberAccessException::class, 'Call to undefined static method TestClass::method(), did you mean methodS2()? ' );
109+ $ obj = new ChildClass ;
110+ $ obj ->callMissingParent ();
111+ }, Nette \MemberAccessException::class, 'Call to undefined method InterClass::callMissingParent(). ' );
56112
57- if (extension_loaded ('gd ' )) {
58- Assert::exception (function () {
59- Nette \Utils \Image::fromBlank (1 , 1 )->filledElippse ();
60- }, Nette \MemberAccessException::class, 'Call to undefined method Nette\Utils\Image::filledElippse(), did you mean filledEllipse()? ' );
61- }
113+ Assert::exception (function () {
114+ $ obj = new ChildClass ;
115+ $ obj ->callMissingParentStatic ();
116+ }, Nette \MemberAccessException::class, 'Call to undefined static method InterClass::callMissingParentStatic(). ' );
117+
118+ Assert::exception (function () {
119+ $ obj = new ChildClass ;
120+ $ obj ::callMissingParentStatic ();
121+ }, Nette \MemberAccessException::class, 'Call to undefined static method InterClass::callMissingParentStatic(). ' );
122+
123+ Assert::exception (
124+ function () {
125+ $ obj = new ChildClass ;
126+ $ obj ->callPrivateParent ();
127+ },
128+ Nette \MemberAccessException::class,
129+ PHP_VERSION_ID < 70400
130+ ? 'Call to private method InterClass::callPrivateParent() from scope ChildClass. '
131+ : 'Call to undefined static method InterClass::callPrivateParent(). '
132+ );
133+
134+ Assert::exception (function () {
135+ $ obj = new ChildClass ;
136+ $ obj ->protectedMethod ();
137+ }, Nette \MemberAccessException::class, 'Call to protected method ChildClass::protectedMethod() from global scope. ' );
138+
139+ Assert::exception (function () {
140+ $ obj = new ChildClass ;
141+ $ obj ->protectedStaticMethod ();
142+ }, Nette \MemberAccessException::class, 'Call to protected method ChildClass::protectedStaticMethod() from global scope. ' );
143+
144+ Assert::exception (function () {
145+ $ obj = new ChildClass ;
146+ $ obj ::protectedStaticMethod ();
147+ }, Nette \MemberAccessException::class, 'Call to protected method ChildClass::protectedStaticMethod() from global scope. ' );
148+
149+ Assert::exception (function () {
150+ $ obj = new ChildClass ;
151+ $ obj ->callPrivate ();
152+ }, Nette \MemberAccessException::class, 'Call to private method ChildClass::privateMethod() from scope ParentClass. ' );
153+
154+ Assert::exception (function () {
155+ $ obj = new ChildClass ;
156+ $ obj ->callPrivateStatic ();
157+ }, Nette \MemberAccessException::class, 'Call to private method ChildClass::privateStaticMethod() from scope ParentClass. ' );
0 commit comments