ConfigCachingServiceTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A tearDown() 0 6 1
A testIsDisabled() 0 8 1
A testGetConfigJson() 0 9 1
A testGetConfigJsonWithCacheDisabled() 0 14 1
1
<?php
2
3
use Mockery as m;
4
use JsLocalization\Facades\ConfigCachingService;
5
6
class ConfigCachingServiceTest extends TestCase {
7
8
    public function setUp()
9
    {
10
        parent::setUp();
11
12
        Cache::forget(JsLocalization\Caching\ConfigCachingService::CACHE_KEY);
13
        Cache::forget(JsLocalization\Caching\ConfigCachingService::CACHE_TIMESTAMP_KEY);
14
    }
15
16
    public function tearDown()
17
    {
18
        m::close();
19
20
        parent::tearDown();
21
    }
22
    
23
    public function testIsDisabled()
24
    {
25
        Config::set('js-localization.disable_config_cache', false);
26
        $this->assertFalse(ConfigCachingService::isDisabled());
27
28
        Config::set('js-localization.disable_config_cache', true);
29
        $this->assertTrue(ConfigCachingService::isDisabled());
30
    }
31
    
32
    public function testGetConfigJson()
33
    {
34
        $expectedJson = json_encode($this->testConfigExportFlat);
35
        $this->assertEquals($expectedJson, ConfigCachingService::getConfigJson());
36
        
37
        // Test that getConfigJson() returns the old value after Config::set()
38
        Config::set('js-localization.test-config', 'new value');
39
        $this->assertEquals($expectedJson, ConfigCachingService::getConfigJson());
40
    }
41
42
    public function testGetConfigJsonWithCacheDisabled()
43
    {
44
        Config::set('js-localization.disable_config_cache', true);
45
        
46
        $expectedJson = json_encode($this->testConfigExportFlat);
47
        $this->assertEquals($expectedJson, ConfigCachingService::getConfigJson());
48
49
        // Test that getConfigJson() returns the new value after Config::set()
50
        $this->testConfigExportFlat['js-localization.test-config'] = 'new value';
51
        $expectedJson = json_encode($this->testConfigExportFlat);
52
        
53
        Config::set('js-localization.test-config', 'new value');
54
        $this->assertEquals($expectedJson, ConfigCachingService::getConfigJson());
55
    }
56
    
57
}