-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SmartObject: added support for annotations in traits (thx @matej21) [C…
…loses #121]
- Loading branch information
Showing
3 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\SmartObject properties and inheritance. | ||
*/ | ||
|
||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
/** | ||
* @property int $traitA | ||
*/ | ||
trait TraitA | ||
{ | ||
public function getTraitA() | ||
{ | ||
return __FUNCTION__; | ||
} | ||
} | ||
|
||
/** | ||
* @property int $traitB | ||
*/ | ||
trait TraitB | ||
{ | ||
public function getTraitB() | ||
{ | ||
return __FUNCTION__; | ||
} | ||
} | ||
|
||
/** | ||
* @property int $traitC | ||
*/ | ||
trait TraitC | ||
{ | ||
use TraitB; | ||
|
||
public function getTraitC() | ||
{ | ||
return __FUNCTION__; | ||
} | ||
} | ||
|
||
/** | ||
* @property int $classA | ||
*/ | ||
class ParentClass | ||
{ | ||
use Nette\SmartObject; | ||
use TraitA; | ||
|
||
public function getClassA() | ||
{ | ||
return __FUNCTION__; | ||
} | ||
} | ||
|
||
/** | ||
* @property int $classB | ||
*/ | ||
class ChildClass extends ParentClass | ||
{ | ||
use TraitC; | ||
|
||
public function getClassB() | ||
{ | ||
return __FUNCTION__; | ||
} | ||
} | ||
|
||
|
||
$obj = new ChildClass; | ||
|
||
Assert::same('getTraitA', $obj->traitA); | ||
Assert::same('getTraitB', $obj->traitB); | ||
Assert::same('getTraitC', $obj->traitC); | ||
Assert::same('getClassA', $obj->classA); | ||
Assert::same('getClassB', $obj->classB); | ||
|
||
Assert::exception(function () use ($obj) { | ||
$obj->classBX; | ||
}, Nette\MemberAccessException::class, 'Cannot read an undeclared property ChildClass::$classBX, did you mean $classB?'); | ||
|
||
Assert::exception(function () use ($obj) { | ||
$obj->classAX; | ||
}, Nette\MemberAccessException::class, 'Cannot read an undeclared property ChildClass::$classAX, did you mean $classA?'); | ||
|
||
Assert::exception(function () use ($obj) { | ||
$obj->traitCX; | ||
}, Nette\MemberAccessException::class, 'Cannot read an undeclared property ChildClass::$traitCX, did you mean $traitC?'); | ||
|
||
Assert::exception(function () use ($obj) { | ||
$obj->traitBX; | ||
}, Nette\MemberAccessException::class, 'Cannot read an undeclared property ChildClass::$traitBX, did you mean $traitB?'); | ||
|
||
Assert::exception(function () use ($obj) { | ||
$obj->traitAX; | ||
}, Nette\MemberAccessException::class, 'Cannot read an undeclared property ChildClass::$traitAX, did you mean $traitA?'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\SmartObject undeclared method and annotation @method. | ||
*/ | ||
|
||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
/** | ||
* @method traitA() | ||
*/ | ||
trait TraitA | ||
{} | ||
|
||
/** | ||
* @method traitB() | ||
*/ | ||
trait TraitB | ||
{} | ||
|
||
/** | ||
* @method traitC() | ||
*/ | ||
trait TraitC | ||
{ | ||
use TraitB; | ||
} | ||
|
||
/** | ||
* @method classA() | ||
*/ | ||
class ParentClass | ||
{ | ||
use Nette\SmartObject; | ||
use TraitA; | ||
} | ||
|
||
/** | ||
* @method classB() | ||
*/ | ||
class ChildClass extends ParentClass | ||
{ | ||
use TraitC; | ||
} | ||
|
||
|
||
$obj = new ChildClass; | ||
|
||
Assert::exception(function () use ($obj) { | ||
$obj->classBX(); | ||
}, Nette\MemberAccessException::class, 'Call to undefined method ChildClass::classBX(), did you mean classB()?'); | ||
|
||
Assert::exception(function () use ($obj) { | ||
$obj->classAX(); | ||
}, Nette\MemberAccessException::class, 'Call to undefined method ChildClass::classAX(), did you mean classA()?'); | ||
|
||
Assert::exception(function () use ($obj) { | ||
$obj->traitCX(); | ||
}, Nette\MemberAccessException::class, 'Call to undefined method ChildClass::traitCX(), did you mean traitC()?'); | ||
|
||
Assert::exception(function () use ($obj) { | ||
$obj->traitBX(); | ||
}, Nette\MemberAccessException::class, 'Call to undefined method ChildClass::traitBX(), did you mean traitB()?'); | ||
|
||
Assert::exception(function () use ($obj) { | ||
$obj->traitAX(); | ||
}, Nette\MemberAccessException::class, 'Call to undefined method ChildClass::traitAX(), did you mean traitA()?'); |