LoevgaardPakkelabelsExtensionTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 37.5 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testThrowsExceptionUnlessApiUsernameSet() 9 9 1
A testThrowsExceptionUnlessApiPasswordSet() 9 9 1
A testGettersSetters() 0 10 1
A getEmptyConfig() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

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
2
3
namespace Loevgaard\PakkelabelsBundle\Tests\DependencyInjection;
4
5
use Loevgaard\PakkelabelsBundle\DependencyInjection\LoevgaardPakkelabelsExtension;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\Yaml\Parser;
10
11
class LoevgaardPakkelabelsExtensionTest extends TestCase
12
{
13 View Code Duplication
    public function testThrowsExceptionUnlessApiUsernameSet()
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...
14
    {
15
        $this->expectException(InvalidConfigurationException::class);
16
17
        $loader = new LoevgaardPakkelabelsExtension();
18
        $config = $this->getEmptyConfig();
19
        unset($config['api_username']);
20
        $loader->load([$config], new ContainerBuilder());
21
    }
22
23 View Code Duplication
    public function testThrowsExceptionUnlessApiPasswordSet()
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...
24
    {
25
        $this->expectException(InvalidConfigurationException::class);
26
27
        $loader = new LoevgaardPakkelabelsExtension();
28
        $config = $this->getEmptyConfig();
29
        unset($config['api_password']);
30
        $loader->load([$config], new ContainerBuilder());
31
    }
32
33
    public function testGettersSetters()
34
    {
35
        $loader = new LoevgaardPakkelabelsExtension();
36
        $config = $this->getEmptyConfig();
37
        $container = new ContainerBuilder();
38
        $loader->load([$config], $container);
39
40
        $this->assertSame($config['api_username'], $container->getParameter('loevgaard_pakkelabels.api_username'));
41
        $this->assertSame($config['api_password'], $container->getParameter('loevgaard_pakkelabels.api_password'));
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    protected function getEmptyConfig()
48
    {
49
        $yaml = <<<EOF
50
api_username: username
51
api_password: password
52
label_dir: /label/dir
53
EOF;
54
        $parser = new Parser();
55
56
        return $parser->parse($yaml);
57
    }
58
}
59