Skip to content

Commit

Permalink
Added tests for function call dumping for #173, #185 and #192
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Sep 27, 2014
1 parent 5be6fb9 commit d323890
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
Expand Up @@ -17,7 +17,10 @@
*/
class FunctionCallDefinitionDumperTest extends \PHPUnit_Framework_TestCase
{
public function testDump()
/**
* @test
*/
public function dump_closure()
{
$definition = new FunctionCallDefinition(function ($undefined, $foo, $link, $default = 'foo') {
});
Expand All @@ -27,7 +30,7 @@ public function testDump()
));
$dumper = new FunctionCallDefinitionDumper();

$str = 'closure defined in ' . __FILE__ . ' at line 22(
$str = 'closure defined in ' . __FILE__ . ' at line 25(
$undefined = #UNDEFINED#
$foo = \'bar\'
$link = link(foo)
Expand All @@ -37,7 +40,10 @@ public function testDump()
$this->assertEquals($str, $dumper->dump($definition));
}

public function testDumpWithMethod()
/**
* @test
*/
public function dump_object_method()
{
$object = new \SplDoublyLinkedList;
$definition = new FunctionCallDefinition(array($object, 'push'));
Expand All @@ -50,7 +56,40 @@ public function testDumpWithMethod()
$this->assertEquals($str, $dumper->dump($definition));
}

public function testDumpWithCallableObject()
/**
* @test
*/
public function dump_class_method()
{
$definition = new FunctionCallDefinition(array('SplDoublyLinkedList', 'push'));
$dumper = new FunctionCallDefinitionDumper();

$str = 'SplDoublyLinkedList::push(
$value = #UNDEFINED#
)';

$this->assertEquals($str, $dumper->dump($definition));
}

/**
* @test
*/
public function dump_static_method()
{
$definition = new FunctionCallDefinition(array('UnitTests\DI\Definition\Dumper\TestClass', 'bar'));
$dumper = new FunctionCallDefinitionDumper();

$str = 'UnitTests\DI\Definition\Dumper\TestClass::bar(
$value = #UNDEFINED#
)';

$this->assertEquals($str, $dumper->dump($definition));
}

/**
* @test
*/
public function dump_callable_object()
{
$definition = new FunctionCallDefinition(new CallableTestClass());
$dumper = new FunctionCallDefinitionDumper();
Expand All @@ -61,12 +100,33 @@ public function testDumpWithCallableObject()

$this->assertEquals($str, $dumper->dump($definition));
}

/**
* @test
*/
public function dump_callable_class()
{
$definition = new FunctionCallDefinition('UnitTests\DI\Definition\Dumper\CallableTestClass');
$dumper = new FunctionCallDefinitionDumper();

$str = 'UnitTests\DI\Definition\Dumper\CallableTestClass::__invoke(
$value = #UNDEFINED#
)';

$this->assertEquals($str, $dumper->dump($definition));
}
}

class TestClass
{
public static function bar($value)
{
}
}

class CallableTestClass
{
public function __invoke($value)
{
return 42;
}
}
Expand Up @@ -83,7 +83,7 @@ public function call_class_method()
/**
* @test
*/
public function call_class_static_method()
public function call_static_method()
{
$container = $this->assert_container();
$resolver = $this->assert_definition_resolver($container);
Expand Down

0 comments on commit d323890

Please sign in to comment.