ComponentContainerTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 49
rs 10
c 3
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetInvalidComponent() 0 5 1
A testGetNotFound() 0 5 1
A testGetInvalidType() 0 5 1
A testContainerHas() 0 13 1
A testContainerGet() 0 11 1
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