Passed
Push — master ( b59adb...796449 )
by Rick
05:25
created

ComponentContainerTest::testContainerHas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 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
		$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