We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
11 | class ResolverTaggedServiceMappingPassTest extends TestCase |
||
12 | { |
||
13 | /** @var ContainerBuilder */ |
||
14 | private $container; |
||
15 | |||
16 | public function setUp() |
||
17 | { |
||
18 | $container = new ContainerBuilder(); |
||
19 | $container->setDefinition('injected_service', new Definition(FakeInjectedService::class)); |
||
20 | |||
21 | $container->register('overblog_graphql.resolver_resolver', ResolverResolver::class); |
||
22 | |||
23 | $this->container = $container; |
||
24 | } |
||
25 | |||
26 | private function addCompilerPassesAndCompile() |
||
27 | { |
||
28 | $this->container->addCompilerPass(new ResolverTaggedServiceMappingPass()); |
||
29 | $this->container->addCompilerPass(new FakeCompilerPass()); |
||
30 | $this->container->compile(); |
||
31 | } |
||
32 | |||
33 | public function testCompilationWorksPassConfigDirective() |
||
34 | { |
||
35 | $testResolver = new Definition(ResolverTestService::class); |
||
36 | $testResolver |
||
37 | ->addTag('overblog_graphql.resolver', [ |
||
38 | 'alias' => 'test_resolver', 'method' => 'doSomethingWithContainer', |
||
39 | ]); |
||
40 | |||
41 | $this->container->setDefinition('test_resolver', $testResolver); |
||
42 | |||
43 | $this->addCompilerPassesAndCompile(); |
||
44 | |||
45 | $this->assertTrue($this->container->has('test_resolver')); |
||
46 | } |
||
47 | |||
48 | public function testTagAliasIsValid() |
||
49 | { |
||
50 | $testResolver = new Definition(ResolverTestService::class); |
||
51 | $testResolver |
||
52 | ->addTag('overblog_graphql.resolver', [ |
||
53 | 'alias' => false, 'method' => 'doSomethingWithContainer', |
||
54 | ]); |
||
55 | |||
56 | $this->container->setDefinition('test_resolver', $testResolver); |
||
57 | |||
58 | $this->expectException(\InvalidArgumentException::class); |
||
59 | $this->expectExceptionMessage('Service tagged "test_resolver" must have valid "alias" argument.'); |
||
60 | |||
61 | $this->addCompilerPassesAndCompile(); |
||
62 | } |
||
63 | |||
64 | public function testTagMethodIsValid() |
||
65 | { |
||
66 | $testResolver = new Definition(ResolverTestService::class); |
||
67 | $testResolver |
||
68 | ->addTag('overblog_graphql.resolver', [ |
||
69 | 'alias' => 'test_resolver', 'method' => false, |
||
70 | ]); |
||
71 | |||
72 | $this->container->setDefinition('test_resolver', $testResolver); |
||
73 | |||
74 | $this->expectException(\InvalidArgumentException::class); |
||
75 | $this->expectExceptionMessage('Service tagged "test_resolver" must have valid "method" argument.'); |
||
76 | |||
77 | $this->addCompilerPassesAndCompile(); |
||
78 | } |
||
79 | } |
||
80 |