Completed
Push — refactoring ( 84ac1f...ab1ebc )
by Oleg
04:25
created

AttributesTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 96
wmc 10
lcom 1
cbo 2
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A attributeFactory() 0 7 1
A testGet() 0 6 1
A testSet() 0 9 1
A testForget() 0 8 1
A testPut() 0 8 1
A testPush() 0 11 1
A testHas() 0 6 1
A testMerge() 0 13 1
A testBuild() 0 9 1
A testMergeArrayValuesException() 0 4 1
1
<?php
2
3
namespace Malezha\Menu\Tests;
4
5
use Malezha\Menu\Entity\Attributes;
6
7
class AttributesTest extends TestCase
8
{
9
    protected function attributeFactory()
10
    {
11
        return new Attributes([
12
            'class' => 'some-style',
13
            'id' => 'test',
14
        ]);
15
    }
16
    
17
    public function testGet()
18
    {
19
        $attributes = $this->attributeFactory();
20
        
21
        $this->assertEquals('some-style', $attributes->get('class'));
22
    }
23
    
24
    public function testSet()
25
    {
26
        $attributes = $this->attributeFactory();
27
        $subset = ['class' => 'new-style', 'id' => 'link'];
28
        
29
        $attributes->set($subset);
30
        
31
        $this->assertArraySubset($subset, $attributes->all());
32
    }
33
    
34
    public function testForget()
35
    {
36
        $attributes = $this->attributeFactory();
37
        
38
        $attributes->forget('id');
39
        
40
        $this->assertEquals(null, $attributes->get('id'));
41
    }
42
    
43
    public function testPut()
44
    {
45
        $attributes = $this->attributeFactory();
46
47
        $attributes->put('data-test', 'value');
48
49
        $this->assertEquals('value', $attributes->get('data-test'));
50
    }
51
    
52
    public function testPush()
53
    {
54
        $attributes = $this->attributeFactory();
55
56
        $subset = $attributes->all();
57
        $push = ['data-value' => 'some'];
58
        
59
        $attributes->push($push);
60
61
        $this->assertArraySubset(array_merge($subset, $push), $attributes->all());
62
    }
63
    
64
    public function testHas()
65
    {
66
        $attributes = $this->attributeFactory();
67
        
68
        $this->assertTrue($attributes->has('class'));
69
    }
70
71
    public function testMerge()
72
    {
73
        $attributes = $this->attributeFactory();
74
        
75
        $attributes->merge([
76
            'class' => 'another-style',
77
        ]);
78
        
79
        $this->assertArraySubset([
80
            'class' => 'some-style another-style',
81
            'id' => 'test',
82
        ], $attributes->all());
83
    }
84
85
    public function testBuild()
86
    {
87
        $attributes = $this->attributeFactory();
88
        $expected = ' class="some-style active" id="test"';
89
        $expectedString = ' class="some-style" id="test"';
90
        
91
        $this->assertEquals($expected, $attributes->build(['class' => 'active']));
92
        $this->assertEquals($expectedString, (string) $attributes);
93
    }
94
95
    /**
96
     * @expectedException \RuntimeException
97
     */
98
    public function testMergeArrayValuesException()
99
    {
100
        Attributes::mergeArrayValues();
101
    }
102
}