-
-
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.
Reflection::getPropertyDeclaringClass() takes into account doc commen…
…ts [Closes nette/di#169]
- Loading branch information
Showing
3 changed files
with
109 additions
and
1 deletion.
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
51 changes: 51 additions & 0 deletions
51
tests/Utils/Reflection.getPropertyDeclaringClass.overwrite.phpt
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,51 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Utils\Reflection::getPropertyDeclaringClass | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Utils\Reflection; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
trait A | ||
{ | ||
protected $foo; | ||
} | ||
|
||
trait B | ||
{ | ||
use A; | ||
|
||
protected $foo; | ||
} | ||
|
||
class C | ||
{ | ||
use B; | ||
|
||
protected $foo; | ||
} | ||
|
||
class D extends C | ||
{ | ||
protected $foo; | ||
} | ||
|
||
|
||
// Property in class | ||
Assert::same('D', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('D', 'foo'))->getName()); | ||
|
||
// Property in class - wrong, but impossible to solve in PHP https://github.com/nette/di/issues/169 | ||
Assert::same('A', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('C', 'foo'))->getName()); | ||
|
||
// Property in trait - wrong, but impossible to solve in PHP https://github.com/nette/di/issues/169 | ||
Assert::same('A', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('B', 'foo'))->getName()); | ||
|
||
// Property in trait | ||
Assert::same('A', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('A', 'foo'))->getName()); |
55 changes: 55 additions & 0 deletions
55
tests/Utils/Reflection.getPropertyDeclaringClass.overwrite2.phpt
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,55 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Utils\Reflection::getPropertyDeclaringClass + doccomment workaround | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Utils\Reflection; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
trait A | ||
{ | ||
/** a */ | ||
protected $foo; | ||
} | ||
|
||
trait B | ||
{ | ||
use A; | ||
|
||
/** b */ | ||
protected $foo; | ||
} | ||
|
||
class C | ||
{ | ||
use B; | ||
|
||
/** c */ | ||
protected $foo; | ||
} | ||
|
||
class D extends C | ||
{ | ||
/** d */ | ||
protected $foo; | ||
} | ||
|
||
|
||
// Property in class | ||
Assert::same('D', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('D', 'foo'))->getName()); | ||
|
||
// Property in class | ||
Assert::same('C', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('C', 'foo'))->getName()); | ||
|
||
// Property in trait | ||
Assert::same('B', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('B', 'foo'))->getName()); | ||
|
||
// Property in trait | ||
Assert::same('A', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('A', 'foo'))->getName()); |