Skip to content

Commit a891e2e

Browse files
committed
Refactor for PSR4 compliance
1 parent d64f5df commit a891e2e

File tree

4 files changed

+65
-44
lines changed

4 files changed

+65
-44
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Overblog\GraphQLBundle\Tests\DependencyInjection\Compiler;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Reference;
8+
9+
/**
10+
* Class FakeCompilerPass
11+
* @package DependencyInjection\Compiler
12+
*/
13+
class FakeCompilerPass implements CompilerPassInterface
14+
{
15+
public function process(ContainerBuilder $container)
16+
{
17+
$container
18+
->getDefinition('test_resolver')
19+
->addArgument(new Reference('injected_service'))
20+
;
21+
}
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Overblog\GraphQLBundle\Tests\DependencyInjection\Compiler;
4+
5+
/**
6+
* Class FakeInjectedService
7+
*/
8+
class FakeInjectedService
9+
{
10+
public function doSomething()
11+
{
12+
return true;
13+
}
14+
}

Tests/DependencyInjection/Compiler/ResolverTaggedServiceMappingPassTest.php

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
namespace Overblog\GraphQLBundle\Tests\DependencyInjection\Compiler;
44

55
use Overblog\GraphQLBundle\DependencyInjection\Compiler\ResolverTaggedServiceMappingPass;
6-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
96
use Symfony\Component\DependencyInjection\ContainerBuilder;
107
use Symfony\Component\DependencyInjection\Definition;
11-
use Symfony\Component\DependencyInjection\Reference;
128

139
/**
1410
* Class ResolverTaggedServiceMappingPassTest
@@ -34,21 +30,20 @@ public function setUp()
3430
"Overblog\\GraphQLBundle\\Resolver\\ResolverResolver"
3531
);
3632

37-
$fakeResolver = new Definition('Overblog\GraphQLBundle\Tests\DependencyInjection\Compiler\FakeResolverService');
38-
$fakeResolver
33+
$testResolver = new Definition('Overblog\GraphQLBundle\Tests\DependencyInjection\Compiler\ResolverTestService');
34+
$testResolver
3935
->addTag( 'overblog_graphql.resolver', [
40-
'alias' => 'fake_resolver', 'method' => 'doSomethingWithContainer'
36+
'alias' => 'test_resolver', 'method' => 'doSomethingWithContainer'
4137
]);
4238

43-
$container->setDefinition('fake_resolver', $fakeResolver);
39+
$container->setDefinition('test_resolver', $testResolver);
4440

4541
$this->container = $container;
4642
}
4743

4844
private function addCompilerPassesAndCompile()
4945
{
5046
$this->container->addCompilerPass(new ResolverTaggedServiceMappingPass());
51-
// Manipulate container after ResolverTaggedServiceMappingPass
5247
$this->container->addCompilerPass(new FakeCompilerPass());
5348
$this->container->compile();
5449
}
@@ -57,40 +52,6 @@ public function testCompilationWorksPassConfigDirective()
5752
{
5853
$this->addCompilerPassesAndCompile();
5954

60-
$this->assertTrue($this->container->has('fake_resolver'));
61-
}
62-
}
63-
64-
class FakeCompilerPass implements CompilerPassInterface
65-
{
66-
public function process(ContainerBuilder $container)
67-
{
68-
$container
69-
->getDefinition('fake_resolver')
70-
->addArgument(new Reference('injected_service'))
71-
;
72-
}
73-
}
74-
75-
// Instantiate ContainerAwareInterface to trigger the problem in ResolverTaggedServiceMappingPass
76-
class FakeResolverService implements ContainerAwareInterface
77-
{
78-
use ContainerAwareTrait;
79-
80-
public function __construct($service)
81-
{
82-
}
83-
84-
public function doSomethingWithContainer()
85-
{
86-
return $this->container->get('injected_service')->doSomething();
87-
}
88-
}
89-
90-
class FakeInjectedService
91-
{
92-
public function doSomething()
93-
{
94-
return true;
55+
$this->assertTrue($this->container->has('test_resolver'));
9556
}
9657
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace DependencyInjection\Compiler;
4+
5+
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
6+
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
7+
8+
/**
9+
* Class ResolverTestService
10+
* @package DependencyInjection\Compiler
11+
*/
12+
class ResolverTestService implements ContainerAwareInterface
13+
{
14+
use ContainerAwareTrait;
15+
16+
public function __construct($service)
17+
{
18+
}
19+
20+
public function doSomethingWithContainer()
21+
{
22+
return $this->container->get('injected_service')->doSomething();
23+
}
24+
}

0 commit comments

Comments
 (0)