1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-10 16:14:57 +02:00

DibiObject: shows suggestions for undeclared members

This commit is contained in:
David Grudl
2015-10-06 12:49:23 +02:00
parent f42d1b1611
commit a119921832
3 changed files with 98 additions and 7 deletions

View File

@@ -9,6 +9,24 @@ class TestClass
{
use DibiStrict;
public $public;
protected $protected;
public static $publicStatic;
public function publicMethod()
{}
public static function publicMethodStatic()
{}
protected function protectedMethod()
{}
protected static function protectedMethodS()
{}
public function getBar()
{
return 123;
@@ -44,6 +62,21 @@ Assert::exception(function () {
$obj->callParent();
}, 'LogicException', 'Call to undefined method parent::callParent().');
Assert::exception(function () {
$obj = new TestClass;
$obj->publicMethodX();
}, 'LogicException', 'Call to undefined method TestClass::publicMethodX(), did you mean publicMethod()?');
Assert::exception(function () { // suggest static method
$obj = new TestClass;
$obj->publicMethodStaticX();
}, 'LogicException', 'Call to undefined method TestClass::publicMethodStaticX(), did you mean publicMethodStatic()?');
Assert::exception(function () { // suggest only public method
$obj = new TestClass;
$obj->protectedMethodX();
}, 'LogicException', 'Call to undefined method TestClass::protectedMethodX().');
// writing
Assert::exception(function () {
@@ -51,6 +84,21 @@ Assert::exception(function () {
$obj->undeclared = 'value';
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$undeclared.');
Assert::exception(function () {
$obj = new TestClass;
$obj->publicX = 'value';
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$publicX, did you mean $public?');
Assert::exception(function () { // suggest only non-static property
$obj = new TestClass;
$obj->publicStaticX = 'value';
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$publicStaticX.');
Assert::exception(function () { // suggest only public property
$obj = new TestClass;
$obj->protectedX = 'value';
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$protectedX.');
// property getter
$obj = new TestClass;
@@ -66,6 +114,21 @@ Assert::exception(function () {
$val = $obj->undeclared;
}, 'LogicException', 'Attempt to read undeclared property TestClass::$undeclared.');
Assert::exception(function () {
$obj = new TestClass;
$val = $obj->publicX;
}, 'LogicException', 'Attempt to read undeclared property TestClass::$publicX, did you mean $public?');
Assert::exception(function () { // suggest only non-static property
$obj = new TestClass;
$val = $obj->publicStaticX;
}, 'LogicException', 'Attempt to read undeclared property TestClass::$publicStaticX.');
Assert::exception(function () { // suggest only public property
$obj = new TestClass;
$val = $obj->protectedX;
}, 'LogicException', 'Attempt to read undeclared property TestClass::$protectedX.');
// unset/isset
Assert::exception(function () {