-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dmitry Gladyshev
committed
Apr 4, 2017
1 parent
37427d4
commit 7801435
Showing
4 changed files
with
152 additions
and
7 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,51 @@ | ||
<?php | ||
/** | ||
* @author Dmitry Gladyshev <[email protected]> | ||
* @date 04.04.17 12:00 | ||
*/ | ||
|
||
namespace Yandex\Direct\Test; | ||
|
||
use ReflectionClass; | ||
use ReflectionMethod; | ||
use ReflectionProperty; | ||
|
||
/** | ||
* Class Helper | ||
* @package Yandex\Direct\Test | ||
*/ | ||
class Helper | ||
{ | ||
/** | ||
* getPrivateProperty | ||
* | ||
* @author Joe Sexton <[email protected]> | ||
* @param string $className | ||
* @param string $propertyName | ||
* @return ReflectionProperty | ||
*/ | ||
public static function getPrivateProperty( $className, $propertyName ) { | ||
$reflector = new ReflectionClass( $className ); | ||
$property = $reflector->getProperty( $propertyName ); | ||
$property->setAccessible( true ); | ||
|
||
return $property; | ||
} | ||
|
||
/** | ||
* Get a private or protected method for testing/documentation purposes. | ||
* How to use for MyClass->foo(): | ||
* $cls = new MyClass(); | ||
* $foo = PHPUnitUtil::getPrivateMethod($cls, 'foo'); | ||
* $foo->invoke($cls, $...); | ||
* @param object $obj The instantiated instance of your class | ||
* @param string $name The name of your private/protected method | ||
* @return ReflectionMethod The method you asked for | ||
*/ | ||
public static function getPrivateMethod($obj, $name) { | ||
$class = new ReflectionClass($obj); | ||
$method = $class->getMethod($name); | ||
$method->setAccessible(true); | ||
return $method; | ||
} | ||
} |
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