ConditionTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 122
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B dataProvider() 0 104 1
A testConditionalMergeTags() 0 4 1
1
<?php
2
3
namespace FlorianKoerner\ChimpDrill\Tests;
4
5
use FlorianKoerner\ChimpDrill\ChimpDrill;
6
7
class ConditionTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @return array
11
     */
12
    public function dataProvider()
13
    {
14
        return array(
15
            array(
16
                'message' => '*|IF:HAPPY|*We are Happy.*|ELSE:|*We are very sad. But why?*|END:IF|*',
17
                'placeholder' => array(),
18
                'expected' => 'We are very sad. But why?'
19
            ),
20
            array(
21
                'message' => '*|IF:HAPPY|*We are Happy.*|ELSE:|*We are very sad. But why?*|END:IF|*',
22
                'placeholder' => array(
23
                    'HAPPY' => false
24
                ),
25
                'expected' => 'We are very sad. But why?'
26
            ),
27
            array(
28
                'message' => '*|IF:HAPPY|*We are Happy.*|ELSE:|*We are very sad. But why?*|END:IF|*',
29
                'placeholder' => array(
30
                    'HAPPY' => true
31
                ),
32
                'expected' => 'We are Happy.'
33
            ),
34
            array(
35
                'message' => 'Our happiness is *|IF:HAPPINESS > 75|*so high*|ELSEIF:HAPPINESS > 50|*ok*|ELSE:|*- wo don\'t want to talk about it*|END:IF|*.',
36
                'placeholder' => array(
37
                    'HAPPINESS' => 55
38
                ),
39
                'expected' => 'Our happiness is ok.'
40
            ),
41
            array(
42
                'message' => 'This is *|IF:EQUAL = equal|*equal*|END:IF|*',
43
                'placeholder' => array(
44
                    'EQUAL' => 'equal'
45
                ),
46
                'expected' => 'This is equal'
47
            ),
48
            array(
49
                'message' => 'This is *|IFNOT:EQUAL = equal|*not equal*|END:IF|*',
50
                'placeholder' => array(
51
                    'EQUAL' => 'not so equal'
52
                ),
53
                'expected' => 'This is not equal'
54
            ),
55
            array(
56
                'message' => 'This is *|IF:EQUAL != equal|*not equal*|END:IF|*',
57
                'placeholder' => array(
58
                    'EQUAL' => 'not so equal'
59
                ),
60
                'expected' => 'This is not equal'
61
            ),
62
            array(
63
                'message' => 'This is *|IF:NUMBER > 0|*greater than 0*|END:IF|*',
64
                'placeholder' => array(
65
                    'NUMBER' => 7
66
                ),
67
                'expected' => 'This is greater than 0'
68
            ),
69
            array(
70
                'message' => 'This is *|IF:NUMBER < 10|*lesser than 10*|END:IF|*',
71
                'placeholder' => array(
72
                    'NUMBER' => 7
73
                ),
74
                'expected' => 'This is lesser than 10'
75
            ),
76
            array(
77
                'message' => 'This is *|IF:NUMBER >= 0|*greater than or equal 0*|END:IF|*',
78
                'placeholder' => array(
79
                    'NUMBER' => 0
80
                ),
81
                'expected' => 'This is greater than or equal 0'
82
            ),
83
            array(
84
                'message' => 'This is *|IF:NUMBER >= 0|*greater than or equal 0*|END:IF|*',
85
                'placeholder' => array(
86
                    'NUMBER' => 3
87
                ),
88
                'expected' => 'This is greater than or equal 0'
89
            ),
90
            array(
91
                'message' => 'This is *|IF:NUMBER <= 10|*lesser than or equal 10*|END:IF|*',
92
                'placeholder' => array(
93
                    'NUMBER' => 7
94
                ),
95
                'expected' => 'This is lesser than or equal 10'
96
            ),
97
            array(
98
                'message' => 'This is *|IF:NUMBER <= 10|*lesser than or equal 10*|END:IF|*',
99
                'placeholder' => array(
100
                    'NUMBER' => 10
101
                ),
102
                'expected' => 'This is lesser than or equal 10'
103
            ),
104
            array(
105
                'message' => '*|IF:COOL|*' . PHP_EOL .
106
                                 'You are cool*|IF:BEAUTIFUL|* and beautiful*|END:IF|*.' . PHP_EOL .
107
                             '*|END:IF|*',
108
                'placeholder' => array(
109
                    'COOL' => true,
110
                    'BEAUTIFUL' => true
111
                ),
112
                'expected' => 'You are cool and beautiful.' . PHP_EOL
113
            )
114
        );
115
    }
116
117
    /**
118
     * @param string $message
119
     * @param array  $placeholder
120
     * @param string $expected
121
     *
122
     * @dataProvider dataProvider
123
     */
124
    public function testConditionalMergeTags($message, array $placeholder, $expected)
125
    {
126
        $this->assertEquals($expected, (string) new ChimpDrill($message, $placeholder));
127
    }
128
}