ComponentContainerTest::testContainerGet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 11
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Copyright 2017 NanoSector
4
 *
5
 * You should have received a copy of the MIT license with the project.
6
 * See the LICENSE file for more information.
7
 */
8
9
use Yoshi2889\Container\ComponentContainer;
10
use PHPUnit\Framework\TestCase;
11
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
27
	public function testGetInvalidComponent()
28
	{
29
		$container = new ComponentContainer();
30
		$this->expectException(\Yoshi2889\Container\NotFoundException::class);
31
		$container->get(\Yoshi2889\Container\Tests\SampleInvalidComponent::class);
32
	}
33
34
	public function testGetInvalidType()
35
	{
36
		$container = new ComponentContainer();
37
		$this->expectException(\Yoshi2889\Container\ContainerException::class);
38
		$container->get(10);
39
	}
40
41
	public function testGetNotFound()
42
	{
43
		$emptyContainer = new ComponentContainer();
44
		$this->expectException(\Yoshi2889\Container\NotFoundException::class);
45
		\Yoshi2889\Container\Tests\SampleComponent::fromContainer($emptyContainer);
46
	}
47
48
	public function testContainerHas()
49
	{
50
		$container = new ComponentContainer();
51
52
		self::assertFalse($container->has(\Yoshi2889\Container\Tests\SampleComponent::class));
53
54
		$sampleComponent = new \Yoshi2889\Container\Tests\SampleComponent();
55
		$container->add($sampleComponent);
56
57
		self::assertTrue($container->has(\Yoshi2889\Container\Tests\SampleComponent::class));
58
59
		$this->expectException(\Yoshi2889\Container\ContainerException::class);
60
		$container->has(10);
61
	}
62
}
63