ExporterTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 60
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A registerCompilerPass() 0 4 1
A registerDefinations() 0 12 1
A testExportServiceExists() 0 7 1
A testGetExporterByExtension() 0 11 1
A testGetExporterByExtensionNonFound() 0 13 1
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): void
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
     */
57
    public function testGetExporterByExtensionNonFound()
58
    {
59
        $this->expectException(\Exception::class);
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
Unused Code introduced by
$exporter is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
69
    }
70
}
71