EloquentSettingRepositoryTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 110
Duplicated Lines 34.55 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 6
Bugs 0 Features 4
Metric Value
wmc 6
lcom 1
cbo 2
dl 38
loc 110
rs 10
c 6
b 0
f 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A it_creates_translated_setting() 19 19 1
A it_creates_plain_setting() 0 15 1
A it_finds_setting_by_name() 19 19 1
A it_returns_module_settings() 0 21 1
A it_encodes_array_of_non_translatable_data() 0 19 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace Modules\Setting\Tests;
2
3
class EloquentSettingRepositoryTest extends BaseSettingTest
4
{
5
    public function setUp()
6
    {
7
        parent::setUp();
8
    }
9
10
    /** @test */
11 View Code Duplication
    public function it_creates_translated_setting()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
12
    {
13
        // Prepare
14
        $data = [
15
            'core::site-name' => [
16
                'en' => 'AsgardCMS_en',
17
                'fr' => 'AsgardCMS_fr',
18
            ],
19
        ];
20
21
        // Run
22
        $this->settingRepository->createOrUpdate($data);
23
24
        // Assert
25
        $setting = $this->settingRepository->find(1);
26
        $this->assertEquals('core::site-name', $setting->name);
27
        $this->assertEquals('AsgardCMS_en', $setting->translate('en')->value);
28
        $this->assertEquals('AsgardCMS_fr', $setting->translate('fr')->value);
29
    }
30
31
    /** @test */
32
    public function it_creates_plain_setting()
33
    {
34
        // Prepare
35
        $data = [
36
            'core::template' => 'asgard',
37
        ];
38
39
        // Run
40
        $this->settingRepository->createOrUpdate($data);
41
42
        // Assert
43
        $setting = $this->settingRepository->find(1);
44
        $this->assertEquals('core::template', $setting->name);
45
        $this->assertEquals('asgard', $setting->plainValue);
46
    }
47
48
    /** @test */
49 View Code Duplication
    public function it_finds_setting_by_name()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
50
    {
51
        // Prepare
52
        $data = [
53
            'core::site-name' => [
54
                'en' => 'AsgardCMS_en',
55
                'fr' => 'AsgardCMS_fr',
56
            ],
57
        ];
58
59
        // Run
60
        $this->settingRepository->createOrUpdate($data);
61
62
        // Assert
63
        $setting = $this->settingRepository->findByName('core::site-name');
64
        $this->assertEquals('core::site-name', $setting->name);
65
        $this->assertEquals('AsgardCMS_en', $setting->translate('en')->value);
66
        $this->assertEquals('AsgardCMS_fr', $setting->translate('fr')->value);
67
    }
68
69
    /** @test */
70
    public function it_returns_module_settings()
71
    {
72
        // Prepare
73
        $data = [
74
            'core::site-name' => [
75
                'en' => 'AsgardCMS_en',
76
                'fr' => 'AsgardCMS_fr',
77
            ],
78
            'core::template' => 'asgard',
79
            'blog::posts-per-page' => 10,
80
        ];
81
82
        // Run
83
        $this->settingRepository->createOrUpdate($data);
84
85
        // Assert
86
        $blogSettings = $this->settingRepository->findByModule('blog');
87
        $this->assertEquals(1, $blogSettings->count());
88
        $coreSettings = $this->settingRepository->findByModule('core');
89
        $this->assertEquals(2, $coreSettings->count());
90
    }
91
92
    /** @test */
93
    public function it_encodes_array_of_non_translatable_data()
94
    {
95
        // Prepare
96
        $data = [
97
            'core::locales' => [
98
                "su",
99
                "bi",
100
                "bs",
101
            ],
102
        ];
103
104
        // Run
105
        $this->settingRepository->createOrUpdate($data);
106
107
        // Assert
108
        $setting = $this->settingRepository->find(1);
109
        $this->assertEquals('core::locales', $setting->name);
110
        $this->assertEquals('["su","bi","bs"]', $setting->plainValue);
111
    }
112
}
113