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