-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#12 added unit test for ClosureMethodInvocation
- Loading branch information
1 parent
5e73c29
commit 17632fe
Showing
2 changed files
with
176 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
namespace Go\Aop\Framework; | ||
|
||
/** | ||
* Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2012-12-20 at 11:58:54. | ||
*/ | ||
class ClosureMethodInvocationTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
const FIRST_CLASS_NAME = 'Go\Tests\First'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function setUpBeforeClass() | ||
{ | ||
include_once __DIR__ . '/../../Tests/First.php'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() | ||
{ | ||
if (version_compare(PHP_VERSION, '5.4.0') < 0) { | ||
$this->markTestSkipped("Closure Method Invocation works only on PHP 5.4 and greater"); | ||
} | ||
} | ||
|
||
/** | ||
* Tests dynamic method invocations | ||
* | ||
* @dataProvider dynamicMethodsBatch | ||
*/ | ||
public function testDynamicMethodInvocation($methodName, $expectedResult) | ||
{ | ||
$child = $this->getMock(self::FIRST_CLASS_NAME, array('none')); | ||
$invocation = new ClosureMethodInvocation(get_class($child), $methodName, array()); | ||
|
||
$result = $invocation($child); | ||
$this->assertEquals($expectedResult, $result); | ||
} | ||
|
||
/** | ||
* Tests static method invocations with self | ||
* | ||
* @dataProvider staticSelfMethodsBatch | ||
*/ | ||
public function testStaticSelfMethodInvocation($methodName, $expectedResult) | ||
{ | ||
$childClass = $this->getMockClass(self::FIRST_CLASS_NAME, array('none')); | ||
$invocation = new ClosureMethodInvocation($childClass, $methodName, array()); | ||
|
||
$result = $invocation($childClass); | ||
$this->assertEquals($expectedResult, $result); | ||
} | ||
|
||
/** | ||
* Tests static method invocations with self not overridden with parent | ||
* | ||
* @dataProvider staticSelfMethodsBatch | ||
*/ | ||
public function testStaticSelfNotOverridden($methodName, $expectedResult) | ||
{ | ||
$childClass = $this->getMockClass(self::FIRST_CLASS_NAME, array($methodName)); | ||
$invocation = new ClosureMethodInvocation($childClass, $methodName, array()); | ||
|
||
$result = $invocation($childClass); | ||
$this->assertEquals($expectedResult, $result); | ||
} | ||
|
||
/** | ||
* Tests static method invocations with self not overridden with parent | ||
* | ||
* @dataProvider staticLsbMethodsBatch | ||
*/ | ||
public function testStaticLsbIsWorking($methodName) | ||
{ | ||
$childClass = $this->getMockClass(self::FIRST_CLASS_NAME, array($methodName)); | ||
$invocation = new ClosureMethodInvocation($childClass, $methodName, array()); | ||
|
||
$result = $invocation($childClass); | ||
$this->assertEquals($childClass, $result); | ||
} | ||
|
||
public function dynamicMethodsBatch() | ||
{ | ||
return array( | ||
array('publicMethod', T_PUBLIC), | ||
array('protectedMethod', T_PROTECTED), | ||
array('privateMethod', T_PRIVATE), | ||
); | ||
} | ||
|
||
public function staticSelfMethodsBatch() | ||
{ | ||
return array( | ||
array('staticSelfPublic', T_PUBLIC), | ||
array('staticSelfProtected', T_PROTECTED), | ||
// array('staticSelfPrivate', T_PRIVATE), // This will give a Fatal Error for scope | ||
); | ||
} | ||
|
||
public function staticLsbMethodsBatch() | ||
{ | ||
return array( | ||
array('staticLsbPublic'), | ||
array('staticLsbProtected'), | ||
); | ||
} | ||
|
||
} |
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,63 @@ | ||
<?php | ||
|
||
namespace Go\Tests; | ||
|
||
class First | ||
{ | ||
|
||
private $private = T_PRIVATE; | ||
protected $protected = T_PROTECTED; | ||
public $public = T_PUBLIC; | ||
|
||
private static $staticPrivate = T_PRIVATE; | ||
protected static $staticProtected = T_PROTECTED; | ||
protected static $staticPublic = T_PUBLIC; | ||
|
||
// Dynamic methods that access $this-> properties | ||
private function privateMethod() | ||
{ | ||
return $this->private; | ||
} | ||
|
||
protected function protectedMethod() | ||
{ | ||
return $this->protected; | ||
} | ||
|
||
public function publicMethod() | ||
{ | ||
return $this->public; | ||
} | ||
|
||
// Static methods that access self:: properties | ||
private static function staticSelfPrivate() | ||
{ | ||
return self::$staticPrivate; | ||
} | ||
|
||
protected static function staticSelfProtected() | ||
{ | ||
return self::$staticProtected; | ||
} | ||
|
||
public static function staticSelfPublic() | ||
{ | ||
return self::$staticPublic; | ||
} | ||
|
||
public static function staticSelfPublicAccessPrivate() | ||
{ | ||
return self::$staticPrivate; | ||
} | ||
|
||
// Static methods that access static:: properties with LSB | ||
protected static function staticLsbProtected() | ||
{ | ||
return get_called_class(); | ||
} | ||
|
||
public static function staticLsbPublic() | ||
{ | ||
return get_called_class(); | ||
} | ||
} |