These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\TranslatorBundle\Tests\Service\Exporter; |
||
4 | |||
5 | use Kunstmaan\TranslatorBundle\DependencyInjection\Compiler\KunstmaanTranslatorCompilerPass; |
||
6 | use Kunstmaan\TranslatorBundle\Service\Command\Exporter\Exporter; |
||
7 | use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
||
8 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
9 | use Symfony\Component\DependencyInjection\Definition; |
||
10 | |||
11 | class ExporterTest extends AbstractCompilerPassTestCase |
||
12 | { |
||
13 | protected function registerCompilerPass(ContainerBuilder $container) |
||
14 | { |
||
15 | $container->addCompilerPass(new KunstmaanTranslatorCompilerPass()); |
||
16 | } |
||
17 | |||
18 | private function registerDefinations() |
||
19 | { |
||
20 | $svcId = 'kunstmaan_translator.service.exporter.exporter'; |
||
21 | $svc = new Definition('Kunstmaan\TranslatorBundle\Service\Command\Exporter\Exporter'); |
||
22 | $svc->setPublic(true); |
||
23 | $this->setDefinition($svcId, $svc); |
||
24 | |||
25 | $svcId = 'kunstmaan_translator.service.exporter.yaml'; |
||
26 | $svc = new Definition('Kunstmaan\TranslatorBundle\Service\Command\Exporter\YamlFileExporter'); |
||
27 | $svc->addTag('translation.exporter', ['alias' => 'yml']); |
||
28 | $this->setDefinition($svcId, $svc); |
||
29 | } |
||
30 | |||
31 | public function testExportServiceExists() |
||
32 | { |
||
33 | $this->registerDefinations(); |
||
34 | $this->compile(); |
||
35 | |||
36 | $this->assertContainerBuilderHasService('kunstmaan_translator.service.exporter.exporter', 'Kunstmaan\TranslatorBundle\Service\Command\Exporter\Exporter'); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @group exporter |
||
41 | */ |
||
42 | public function testGetExporterByExtension() |
||
43 | { |
||
44 | $this->registerDefinations(); |
||
45 | $this->compile(); |
||
46 | |||
47 | $exporterService = $this->container->get('kunstmaan_translator.service.exporter.exporter'); |
||
48 | |||
49 | /** @var Exporter $exporter */ |
||
50 | $exporter = $exporterService->getExporterByExtension('yml'); |
||
51 | $this->assertInstanceOf('\Kunstmaan\TranslatorBundle\Service\Command\Exporter\YamlFileExporter', $exporter); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @group exporter |
||
56 | * @expectedException \Exception |
||
57 | */ |
||
58 | public function testGetExporterByExtensionNonFound() |
||
59 | { |
||
60 | $this->expectException('\Exception'); |
||
61 | $this->expectExceptionMessage('No exotic file exporter found or defined.'); |
||
62 | $this->registerDefinations(); |
||
63 | $this->compile(); |
||
64 | |||
65 | $exporterService = $this->container->get('kunstmaan_translator.service.exporter.exporter'); |
||
66 | |||
67 | /** @var Exporter $exporter */ |
||
68 | $exporter = $exporterService->getExporterByExtension('exotic'); |
||
0 ignored issues
–
show
|
|||
69 | } |
||
70 | } |
||
71 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.