Skip to content

Instantly share code, notes, and snippets.

@koriym
Created April 21, 2015 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koriym/d45133f50941d3803772 to your computer and use it in GitHub Desktop.
Save koriym/d45133f50941d3803772 to your computer and use it in GitHub Desktop.
最初のDependencyCompilerTest
<?php
namespace Ray\Di;
use Ray\Aop\Compiler;
use Ray\Aop\Matcher;
use Ray\Aop\Pointcut;
use Ray\Aop\WeavedInterface;
class DependencyCompilerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Dependency
*/
private $dependency;
public function setUp()
{
$class = new \ReflectionClass(FakeCar::class);
$setters = [];
$name = new Name(Name::ANY);
$setters[] = new SetterMethod(new \ReflectionMethod(FakeCar::class, 'setTires'), $name);
$setters[] = new SetterMethod(new \ReflectionMethod(FakeCar::class, 'setHardtop'), $name);
$setterMethods = new SetterMethods($setters);
$newInstance = new NewInstance($class, $setterMethods);
$this->dependency = new Dependency($newInstance, new \ReflectionMethod(FakeCar::class, 'postConstruct'));
}
public function testInstanceCompileString()
{
$dependencyIndex = 'FooInterface-foo_name';
$dependencyInstance = new Instance('bear');
$code = (new DependencyCompiler)->compile($dependencyIndex, $dependencyInstance);
$expected =<<<'EOT'
<?php
return 'bear';
EOT;
$this->assertSame($expected, (string) $code);
}
public function testInstanceCompileInt()
{
$dependencyIndex = 'FooInterface-foo_name';
$dependencyInstance = new Instance((int) 1);
$code = (new DependencyCompiler)->compile($dependencyIndex, $dependencyInstance);
$expected =<<<'EOT'
<?php
return 1;
EOT;
$this->assertSame($expected, (string) $code);
}
public function testInstanceCompileArray()
{
$dependencyIndex = 'FooInterface-foo_name';
$dependencyInstance = new Instance([1 ,2, 3]);
$code = (new DependencyCompiler)->compile($dependencyIndex, $dependencyInstance);
$expected =<<<'EOT'
<?php
return array(1, 2, 3);
EOT;
$this->assertSame($expected, (string) $code);
}
public function testDependencyCompile()
{
$dependency = new Dependency(new NewInstance(new \ReflectionClass('\Ray\Di\FakeCar'), new SetterMethods([])));
$code = (new DependencyCompiler)->compile('FooInterface-current', $dependency);
$expected =<<<'EOT'
<?php
namespace Ray\Di\Compiler;
$instance = new \Ray\Di\FakeCar();
return $instance;
EOT;
$this->assertSame($expected, (string) $code);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment