Passed
Push — master ( 6af80e...b59adb )
by Rick
02:19
created

ComponentContainerTest::testContainerGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 13
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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