Passed
Push — main ( ddea62...53290d )
by Leo
02:46
created

ConfigurationTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 58
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testConfigCatProviderWillSuccedWithCorrectConfig() 0 17 1
A testConfigCatProviderWillFailIfConfigIsNotSet() 0 10 1
A testConfigCatProviderWillFailIfSdkKeyIsNotSet() 0 12 1
A testServiceWiring() 0 11 1
1
<?php
2
3
namespace MetroMarkets\FFBundle\Tests;
4
5
use MetroMarkets\FFBundle\FeatureFlagService;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
8
9
class ConfigurationTest extends TestCase
10
{
11
    public function testServiceWiring()
12
    {
13
        $kernel = new TestingKernel();
14
        $kernel->boot();
15
16
        $container = $kernel->getContainer();
17
18
        /** @var FeatureFlagService $service */
19
        $service = $container->get(FeatureFlagService::class);
20
21
        $this->assertInstanceOf(FeatureFlagService::class, $service);
22
    }
23
24
    public function testConfigCatProviderWillFailIfConfigIsNotSet()
25
    {
26
        $this->expectException(InvalidConfigurationException::class);
27
        $this->expectExceptionMessage('Configcat config must be set when using provider:configcat');
28
29
        $kernel = new TestingKernel([
30
            'provider' => 'configcat',
31
        ]);
32
33
        $kernel->boot();
34
    }
35
36
    public function testConfigCatProviderWillFailIfSdkKeyIsNotSet()
37
    {
38
        $this->expectException(InvalidConfigurationException::class);
39
        $this->expectExceptionMessage('Configcat sdk_key must be set');
40
41
        $kernel = new TestingKernel([
42
            'provider' => 'configcat',
43
            'configcat' => [
44
            ],
45
        ]);
46
47
        $kernel->boot();
48
    }
49
50
    public function testConfigCatProviderWillSuccedWithCorrectConfig()
51
    {
52
        $kernel = new TestingKernel([
53
            'provider' => 'configcat',
54
            'configcat' => [
55
                'sdk_key' => 'key'
56
            ],
57
        ]);
58
59
        $kernel->boot();
60
61
        $container = $kernel->getContainer();
62
63
        /** @var FeatureFlagService $service */
64
        $service = $container->get(FeatureFlagService::class);
65
66
        $this->assertInstanceOf(FeatureFlagService::class, $service);
67
    }
68
}