SaasProviderExtensionTest::getEmptyConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
/*
4
 * This file is part of the SaasProviderBundle package.
5
 * (c) Fluxter <http://fluxter.net/>
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Fluxter\SaasProviderBundle\Tests\DependencyInjection;
11
12
use Fluxter\SaasProviderBundle\DependencyInjection\SaasProviderExtension;
13
use PHPUnit\Framework\TestCase;
14
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\Yaml\Parser;
17
18
class SaasProviderExtensionTest extends TestCase
19
{
20
    /** @var ContainerBuilder */
21
    protected $configuration;
22
23
    protected function tearDown(): void
24
    {
25
        $this->configuration = null;
26
    }
27
28
    public function testExceptionThrownIfClientEntityNotSet()
29
    {
30
        $loader = new SaasProviderExtension();
31
        $config = $this->getEmptyConfig();
32
        unset($config['client_entity']);
33
34
        $this->expectException(InvalidConfigurationException::class);
35
        $loader->load([$config], new ContainerBuilder());
36
    }
37
38
    public function testExceptionThrownIfClientEntityEmpty()
39
    {
40
        $loader = new SaasProviderExtension();
41
        $config = $this->getEmptyConfig();
42
        $config['client_entity'] = '';
43
44
        $this->expectException(InvalidConfigurationException::class);
45
        $loader->load([$config], new ContainerBuilder());
46
    }
47
48
    public function testExceptionThrownIfApiKeyNotSet()
49
    {
50
        $loader = new SaasProviderExtension();
51
        $config = $this->getEmptyConfig();
52
        unset($config['apikey']);
53
54
        $this->expectException(InvalidConfigurationException::class);
55
        $loader->load([$config], new ContainerBuilder());
56
    }
57
58
    public function testExceptionThrownIfApiKeyEmpty()
59
    {
60
        $loader = new SaasProviderExtension();
61
        $config = $this->getEmptyConfig();
62
        $config['apikey'] = '';
63
64
        $this->expectException(InvalidConfigurationException::class);
65
        $loader->load([$config], new ContainerBuilder());
66
    }
67
68
    /**
69
     * getEmptyConfig.
70
     *
71
     * @return array
72
     */
73
    protected function getEmptyConfig()
74
    {
75
        $yaml = <<<EOF
76
client_entity: Acme\MyBundle\Entity\User
77
apikey: test
78
EOF;
79
        $parser = new Parser();
80
81
        return $parser->parse($yaml);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $parser->parse($yaml) also could return the type Symfony\Component\Yaml\Tag\TaggedValue|string which is incompatible with the documented return type array.
Loading history...
82
    }
83
}
84