Completed
Pull Request — master (#12)
by Jakub
03:54
created

testAutowireOverriddenTraitMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
dl 24
loc 24
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\Compiler;
3
4
use Doctrine\Common\Annotations\AnnotationReader;
5
use Doctrine\Common\Annotations\PhpParser;
6
use PHPUnit\Framework\TestCase;
7
use Skrz\Bundle\AutowiringBundle\DependencyInjection\ClassMultiMap;
8
use Skrz\Bundle\AutowiringBundle\DependencyInjection\Compiler\AutowiringCompilerPass;
9
use Skrz\Bundle\AutowiringBundle\DependencyInjection\Compiler\ClassMapBuildCompilerPass;
10
use Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\Compiler\AutowiringCompilerPassSource\AutowiredClassOverridesMethodTrait;
11
use Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\Compiler\AutowiringCompilerPassSource\AutowiredClassUsesMethodTrait;
12
use Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\Compiler\AutowiringCompilerPassSource\Foo\Bar;
13
use Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\Compiler\AutowiringCompilerPassSource\Foo2\Bar2;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Definition;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
class AutowiringCompilerPassMethodTest extends TestCase
19
{
20
21 View Code Duplication
	public function testAutowireTraitMethod()
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...
22
	{
23
		$containerBuilder = new ContainerBuilder();
24
		$classMultiMap = new ClassMultiMap($containerBuilder);
25
26
		$classMapBuildCompilerPass = new ClassMapBuildCompilerPass($classMultiMap);
27
		$autowiringCompilerPass = new AutowiringCompilerPass($classMultiMap, new AnnotationReader(), new PhpParser());
28
29
		$definition = $containerBuilder->setDefinition("service", new Definition(AutowiredClassUsesMethodTrait::class));
30
		$containerBuilder->setDefinition("bar", new Definition(Bar::class));
31
32
		$this->assertSame([], $definition->getMethodCalls());
33
34
		$classMapBuildCompilerPass->process($containerBuilder);
35
		$autowiringCompilerPass->process($containerBuilder);
36
37
		$calls = $definition->getMethodCalls();
38
		$this->assertCount(1, $calls);
39
		$this->assertSame("setBar", $calls[0][0]);
40
		$this->assertCount(1, $calls[0][1]);
41
		$this->assertInstanceOf(Reference::class, $calls[0][1][0]);
42
		$this->assertSame("bar", (string)$calls[0][1][0]);
43
	}
44
45 View Code Duplication
	public function testAutowireOverriddenTraitMethod()
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...
46
	{
47
		$containerBuilder = new ContainerBuilder();
48
		$classMultiMap = new ClassMultiMap($containerBuilder);
49
50
		$classMapBuildCompilerPass = new ClassMapBuildCompilerPass($classMultiMap);
51
		$autowiringCompilerPass = new AutowiringCompilerPass($classMultiMap, new AnnotationReader(), new PhpParser());
52
53
		$definition = $containerBuilder->setDefinition("service", new Definition(AutowiredClassOverridesMethodTrait::class));
54
		$containerBuilder->setDefinition("bar", new Definition(Bar::class));
55
		$containerBuilder->setDefinition("bar2", new Definition(Bar2::class));
56
57
		$this->assertSame([], $definition->getMethodCalls());
58
59
		$classMapBuildCompilerPass->process($containerBuilder);
60
		$autowiringCompilerPass->process($containerBuilder);
61
62
		$calls = $definition->getMethodCalls();
63
		$this->assertCount(1, $calls);
64
		$this->assertSame("setBar", $calls[0][0]);
65
		$this->assertCount(1, $calls[0][1]);
66
		$this->assertInstanceOf(Reference::class, $calls[0][1][0]);
67
		$this->assertSame("bar2", (string)$calls[0][1][0]);
68
	}
69
70
}
71