-
Notifications
You must be signed in to change notification settings - Fork 282
Expand file tree
/
Copy pathDInjectorTest.php
More file actions
76 lines (66 loc) · 2.2 KB
/
DInjectorTest.php
File metadata and controls
76 lines (66 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace ezsql\Tests;
use Psr\Container\ContainerInterface;
use ezsql\DInjector;
use ezsql\Tests\EZTestCase;
use ezsql\Exception\ContainerException;
use ezsql\Exception\NotFoundException;
use ezsql\Tests\ezInterface;
use ezsql\Tests\Baz;
use ezsql\Tests\Bar;
use ezsql\Tests\Foo;
class DInjectorTest extends EZTestCase
{
public function testSet()
{
$container = new DInjector();
$this->assertTrue($container instanceof ContainerInterface);
$container->set('Baz');
$this->assertTrue($container->has('Baz'));
}
public function testHas()
{
$container = new DInjector();
$container->set('Test', 'Test');
$this->assertTrue($container->has('Test'));
$this->assertFalse($container->has('TestOther'));
}
public function testAutoWire()
{
$container = new DInjector();
$container->set('Baz', 'Baz');
$container->set('ezsql\Tests\ezInterface', 'ezsql\Tests\Foo');
$baz = $container->autoWire('ezsql\Tests\Baz');
$this->assertTrue($baz instanceof Baz);
$this->assertTrue($baz->foo instanceof Foo);
}
public function testAutoWire_Exception()
{
$container = new DInjector();
$this->expectException(\ReflectionException::class);
$baz = $container->autoWire('Baz');
}
public function testAutoWire_Error()
{
$container = new DInjector();
$this->expectException(ContainerException::class);
$this->expectExceptionMessageRegExp('/[is not instantiable]/');
$baz = $container->autoWire('ezsql\Tests\Baz');
}
public function testGet()
{
$container = new DInjector();
$container->set('ezsql\Tests\Baz', 'ezsql\Tests\Baz');
$container->set('ezsql\Tests\ezInterface', 'ezsql\Tests\Bar');
$baz = $container->get('ezsql\Tests\Baz');
$this->assertTrue($baz instanceof Baz);
$this->assertTrue($baz->foo instanceof Bar);
}
public function testGet_Error()
{
$container = new DInjector();
$this->expectException(NotFoundException::class);
$this->expectExceptionMessageRegExp('/[does not exists]/');
$baz = $container->get('Baz');
}
}