ClassMultiMapTest::testGetSingleForNonAddedClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection;
3
4
use PHPUnit\Framework\TestCase;
5
use Skrz\Bundle\AutowiringBundle\DependencyInjection\ClassMultiMap;
6
use Skrz\Bundle\AutowiringBundle\Exception\MultipleValuesException;
7
use Skrz\Bundle\AutowiringBundle\Exception\NoValueException;
8
use Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\ClassMultipleMapSource\SomeClass;
9
use Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\ClassMultipleMapSource\SomeInterface;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
12
class ClassMultiMapTest extends TestCase
13
{
14
15 View Code Duplication
	public function testGetSingleForSimpleClass()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
	{
17
		$map = new ClassMultiMap(new ContainerBuilder());
18
19
		$map->put(SomeClass::class, "someValue");
20
		$this->assertSame(
21
			"someValue",
22
			$map->getSingle(SomeClass::class)
23
		);
24
	}
25
26 View Code Duplication
	public function testGetSingleForSimpleForInterface()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
	{
28
		$map = new ClassMultiMap(new ContainerBuilder());
29
30
		$map->put(SomeClass::class, "someValue");
31
		$this->assertSame("someValue", $map->getSingle(SomeInterface::class));
32
	}
33
34
	public function testGetSingleForNonAddedClass()
35
	{
36
		$this->expectException(NoValueException::class);
37
38
		$map = new ClassMultiMap(new ContainerBuilder());
39
		$map->getSingle(SomeClass::class);
40
	}
41
42
	public function testGetSingleForClassAddedTwice()
43
	{
44
		$this->expectException(MultipleValuesException::class);
45
46
		$map = new ClassMultiMap(new ContainerBuilder());
47
48
		$map->put(SomeClass::class, "someValue");
49
		$map->put(SomeClass::class, "someOtherValue");
50
		$map->getSingle(SomeClass::class);
51
	}
52
53
	public function testGetMultiForNonAddedClass()
54
	{
55
		$map = new ClassMultiMap(new ContainerBuilder());
56
57
		$this->assertSame([], $map->getMulti(SomeClass::class));
58
	}
59
60
	public function testGetMultiForClassAddedTwice()
61
	{
62
		$map = new ClassMultiMap(new ContainerBuilder());
63
64
		$map->put(SomeClass::class, "someValue");
65
		$map->put(SomeClass::class, "someOtherValue");
66
		$this->assertSame(["someValue", "someOtherValue"], $map->getMulti(SomeClass::class));
67
	}
68
69
}
70