SimpleMapTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
cbo 3
dl 0
loc 102
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testExists() 0 3 1
A test__toString() 0 3 1
A testSimpleNode() 0 11 1
A testProperties() 0 18 1
A testNamedProperties() 0 16 1
A testDefaultValue() 0 12 1
A testFilteredValue() 0 13 1
1
<?php
2
3
namespace Fwk\Xml;
4
5
/**
6
 * Test class for XmlFile.
7
 * Generated by PHPUnit on 2012-07-25 at 22:30:05.
8
 */
9
class SimpleMapTest extends \PHPUnit_Framework_TestCase {
10
11
    /**
12
     * @var XmlFile
13
     */
14
    protected $object;
15
16
    /**
17
     * Sets up the fixture, for example, opens a network connection.
18
     * This method is called before a test is executed.
19
     */
20
    protected function setUp() {
21
        $this->object = new XmlFile(__DIR__.'/test.xml');
22
    }
23
24
    /**
25
     */
26
    public function testExists() {
27
        $this->assertTrue($this->object->exists());
28
    }
29
30
    /**
31
     */
32
    public function test__toString() {
0 ignored issues
show
Coding Style introduced by
function test__toString() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
33
        $this->assertInternalType('string', $this->object->__toString());
34
    }
35
36
    public function testSimpleNode()
37
    {
38
        $map = new Map();
39
        $map->add(Path::factory('/test/description', 'desc'));
40
        
41
        $result = $map->execute($this->object);
42
        
43
        $this->assertTrue(is_array($result));
44
        $this->assertArrayHasKey('desc', $result);
45
        $this->assertEquals('test description', $result['desc']);
46
    }
47
    
48
    public function testProperties()
49
    {
50
        $map = new Map();
51
        $map->add(Path::factory('/test/properties/property', 'props')
52
                ->loop(true)
53
                ->attribute('name')
54
                ->value('value'));
55
        
56
        $result = $map->execute($this->object);
57
        
58
        $this->assertTrue(is_array($result));
59
        $this->assertArrayHasKey('props', $result);
60
        $this->assertTrue(is_array($result['props']));
61
        $this->assertEquals(2, count($result['props']));
62
        $this->assertArrayHasKey('name', $result['props'][0]);
63
        $this->assertArrayHasKey('value', $result['props'][0]);
64
        $this->assertEquals('test_value', $result['props'][0]['value']);
65
    }
66
    
67
    public function testNamedProperties()
68
    {
69
        $map = new Map();
70
        $map->add(Path::factory('/test/properties/property', 'props')
71
                ->loop(true, '@name'));
72
        
73
        $result = $map->execute($this->object);
74
        
75
        $this->assertTrue(is_array($result));
76
        $this->assertArrayHasKey('props', $result);
77
        $this->assertTrue(is_array($result['props']));
78
        $this->assertEquals(2, count($result['props']));
79
        $this->assertArrayHasKey('test', $result['props']);
80
        $this->assertArrayHasKey('test2', $result['props']);
81
        $this->assertEquals('test_value', $result['props']['test']);
82
    }
83
    
84
    public function testDefaultValue()
85
    {
86
        $map = new Map();
87
        $map->add(Path::factory('/test/test-default', 'default')
88
                ->setDefault('value'));
89
        
90
        $result = $map->execute($this->object);
91
        
92
        $this->assertTrue(is_array($result));
93
        $this->assertArrayHasKey('default', $result);
94
        $this->assertEquals('value', $result['default']);
95
    }
96
    
97
    public function testFilteredValue()
98
    {
99
        $map = new Map();
100
        $map->add(Path::factory('/test/description', 'desc')
101
                ->setDefault('value')
102
                ->filter(function($val) { return strrev($val); }));
103
        
104
        $result = $map->execute($this->object);
105
        
106
        $this->assertTrue(is_array($result));
107
        $this->assertArrayHasKey('desc', $result);
108
        $this->assertEquals(strrev("test description"), $result['desc']);
109
    }
110
}
111