ConfigCachingServiceTest::tearDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
}