Completed
Push — work-fleets ( 5ee2f8...740447 )
by SuperNova.WS
05:13
created

HelperArrayTest::testStringToArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.4285
1
<?php
2
3
/**
4
 * Class HelperArrayTest
5
 *
6
 * @cover HelperArray
7
 */
8
class HelperArrayTest extends PHPUnit_Framework_TestCase {
9
10
  public function setUp() {
11
    parent::setUp(); // TODO: Change the autogenerated stub
12
  }
13
14
  /**
15
   * @cover ::StringToArray
16
   * @cover ::stringToArrayFilterEmpty
17
   */
18
  public function testStringToArray() {
19
    // Only string would be converted to array
20
    $this->assertEquals(array(), HelperArray::stringToArray(123));
21
22
    // Empty data would be converted to empty array()
23
    $this->assertEquals(array(), HelperArray::stringToArray(''));
24
25
    // One element string
26
    $this->assertEquals(array('123'), HelperArray::stringToArray('123'));
27
28
    // Two element string
29
    $this->assertEquals(array('123', '234'), HelperArray::stringToArray('123,234'));
30
31
    // Specified delimiter
32
    $this->assertEquals(array('123;234'), HelperArray::stringToArray('123;234'));
33
    $this->assertEquals(array('123', '234'), HelperArray::stringToArray('123;234', ';'));
34
  }
35
36
37
  /**
38
   * @cover ::makeArray
39
   */
40
  public function testMakeArray() {
41
    // Straightforward: just array
42
    $this->assertEquals(array('test'), HelperArray::makeArray($test = array('test')));
43
44
    // Value with default index
45
    $this->assertEquals(array(0 => 'test'), HelperArray::makeArray($test = 'test'));
46
47
    // Value with non-default index
48
    $this->assertEquals(array(1 => 'test'), HelperArray::makeArray($test = 'test', 1));
49
  }
50
51
  /**
52
   * @cover ::filter
53
   */
54
  public function testFilter() {
55
    $callback = function ($value) {
56
      return !empty($value);
57
    };
58
59
    // Not array
60
    $this->assertEquals(array(), HelperArray::filter($test = 1, $callback));
61
62
    // Empty array
63
    $this->assertEquals(array(), HelperArray::filter($test = array(), $callback));
64
65
    // Not empty array with one empty element
66
    $this->assertEquals(array(), HelperArray::filter($test = array(''), $callback));
67
68
    // Not empty array with one filterable element
69
    $this->assertEquals(array('test'), HelperArray::filter($test = array('test', ''), $callback));
70
71
    // Not empty array with both filterable elements
72
    $this->assertEquals(array(), HelperArray::filter($test = array('0', ''), $callback));
73
  }
74
75
  /**
76
   * @cover ::isNotEmpty
77
   * @cover ::stringToArrayFilterEmpty
78
   */
79
  public function testIsNotEmpty() {
80
    $tested = new HelperArray();
81
82
    // Not empty
83
    $this->assertTrue(invokeMethod($tested, 'isNotEmpty', array('1')));
84
85
    // Empty
86
    $this->assertFalse(invokeMethod($tested, 'isNotEmpty', array('0')));
87
  }
88
89
  /**
90
   * @cover ::filterEmpty
91
   * @cover ::stringToArrayFilterEmpty
92
   */
93
  public function testFilterEmpty() {
94
    // Not array
95
    $this->assertEquals(array(), HelperArray::filterEmpty($test = 1));
96
97
    // Empty array
98
    $this->assertEquals(array(), HelperArray::filterEmpty($test = array()));
99
100
    // Not empty array with one empty element
101
    $this->assertEquals(array(), HelperArray::filterEmpty($test = array('')));
102
103
    // Not empty array with one filterable element
104
    $this->assertEquals(array('test'), HelperArray::filterEmpty($test = array('test', '')));
105
106
    // Not empty array with both filterable elements
107
    $this->assertEquals(array(), HelperArray::filterEmpty($test = array('0', '')));
108
  }
109
110
111
  /**
112
   * @cover ::stringToArrayFilterEmpty
113
   */
114
  public function testStringToArrayFilterEmpty() {
115
    // Not string
116
    $this->assertEquals(array(), HelperArray::stringToArrayFilterEmpty(1));
117
118
    // Empty string
119
    $this->assertEquals(array(), HelperArray::stringToArrayFilterEmpty(''));
120
  }
121
122
123
  public function tearDown() {
124
    parent::tearDown(); // TODO: Change the autogenerated stub
125
  }
126
127
}
128