1 | <?php |
||
12 | class ComponentContainerTest extends TestCase |
||
13 | { |
||
14 | public function testContainerGet() |
||
15 | { |
||
16 | $container = new ComponentContainer(); |
||
17 | |||
18 | $sampleComponent = new \Yoshi2889\Container\Tests\SampleComponent(); |
||
19 | $container->add($sampleComponent); |
||
20 | |||
21 | $sampleComponentFromContainer = \Yoshi2889\Container\Tests\SampleComponent::fromContainer($container); |
||
22 | |||
23 | self::assertInstanceOf(\Yoshi2889\Container\Tests\SampleComponent::class, $sampleComponentFromContainer); |
||
24 | self::assertEquals($sampleComponent, $sampleComponentFromContainer); |
||
25 | |||
26 | $this->expectException(\Yoshi2889\Container\NotFoundException::class); |
||
27 | $container->get(\Yoshi2889\Container\Tests\SampleInvalidComponent::class); |
||
28 | |||
29 | $this->expectException(\Yoshi2889\Container\ContainerException::class); |
||
30 | $container->get(10); |
||
31 | |||
32 | $emptyContainer = new ComponentContainer(); |
||
33 | self::assertNull(\Yoshi2889\Container\Tests\SampleComponent::fromContainer($emptyContainer)); |
||
34 | } |
||
35 | |||
36 | public function testContainerHas() |
||
37 | { |
||
38 | $container = new ComponentContainer(); |
||
39 | |||
40 | self::assertFalse($container->has(\Yoshi2889\Container\Tests\SampleComponent::class)); |
||
41 | |||
42 | $sampleComponent = new \Yoshi2889\Container\Tests\SampleComponent(); |
||
43 | $container->add($sampleComponent); |
||
44 | |||
45 | self::assertTrue($container->has(\Yoshi2889\Container\Tests\SampleComponent::class)); |
||
46 | |||
47 | $this->expectException(\Yoshi2889\Container\ContainerException::class); |
||
48 | $container->has(10); |
||
49 | } |
||
50 | } |
||
51 |