Skip to content

Commit

Permalink
#12 added unit test for ClosureMethodInvocation
Browse files Browse the repository at this point in the history
  • Loading branch information
lisachenko committed Dec 20, 2012
1 parent 5e73c29 commit 17632fe
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 0 deletions.
113 changes: 113 additions & 0 deletions tests/Go/Aop/Framework/ClosureMethodInvocationTest.php
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'),
);
}

}
63 changes: 63 additions & 0 deletions tests/Go/Tests/First.php
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();
}
}

0 comments on commit 17632fe

Please sign in to comment.