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() |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
|
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.