|
1
|
|
|
<?php |
|
2
|
|
|
namespace Slince\Di\Tests; |
|
3
|
|
|
|
|
4
|
|
|
use Slince\Di\Definition; |
|
5
|
|
|
use Slince\Di\Tests\TestClass\Director; |
|
6
|
|
|
|
|
7
|
|
|
class DefinitionTest extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
protected function createDefinition($class, $arguments = [], $methodCalls = []) |
|
11
|
|
|
{ |
|
12
|
|
|
return new Definition($class, $arguments, $methodCalls); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function testSetAndGetArgument() |
|
16
|
|
|
{ |
|
17
|
|
|
$definition = $this->createDefinition(Director::class); |
|
18
|
|
|
$definition->setArgument(0, 'LiAn'); |
|
19
|
|
|
$this->assertEquals('LiAn', $definition->getArgument(0)); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testSetAndGetArguments() |
|
23
|
|
|
{ |
|
24
|
|
|
$definition = $this->createDefinition(Director::class); |
|
25
|
|
|
$arguments = ['Jumi', 12]; |
|
26
|
|
|
$definition->setArguments($arguments); |
|
27
|
|
|
$this->assertEquals($arguments, $definition->getArguments()); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testSetAndGetMethodCall() |
|
31
|
|
|
{ |
|
32
|
|
|
$definition = $this->createDefinition(Director::class); |
|
33
|
|
|
$definition->setMethodCall('setName', ['LiAn']); |
|
34
|
|
|
$this->assertEquals(['LiAn'], $definition->getMethodCall('setName')); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testSetAndGetMethodCalls() |
|
38
|
|
|
{ |
|
39
|
|
|
$definition = $this->createDefinition(Director::class); |
|
40
|
|
|
$methodCalls = [ |
|
41
|
|
|
'setName' => ['LiAn'], |
|
42
|
|
|
'setAge' => [18], |
|
43
|
|
|
]; |
|
44
|
|
|
$definition->setMethodCalls($methodCalls); |
|
45
|
|
|
$this->assertEquals($methodCalls, $definition->getMethodCalls()); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|