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

HelperArrayTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testStringToArray() 0 17 1
A testMakeArray() 0 10 1
A testFilter() 0 20 1
A testIsNotEmpty() 0 9 1
A testFilterEmpty() 0 16 1
A testStringToArrayFilterEmpty() 0 7 1
A tearDown() 0 3 1
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')));
0 ignored issues
show
Bug introduced by
$test = array('test') cannot be passed to makearray() as the parameter $value expects a reference.
Loading history...
43
44
    // Value with default index
45
    $this->assertEquals(array(0 => 'test'), HelperArray::makeArray($test = 'test'));
0 ignored issues
show
Bug introduced by
$test = 'test' cannot be passed to makearray() as the parameter $value expects a reference.
Loading history...
46
47
    // Value with non-default index
48
    $this->assertEquals(array(1 => 'test'), HelperArray::makeArray($test = 'test', 1));
0 ignored issues
show
Bug introduced by
$test = 'test' cannot be passed to makearray() as the parameter $value expects a reference.
Loading history...
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));
0 ignored issues
show
Bug introduced by
$test = 1 cannot be passed to filter() as the parameter $array expects a reference.
Loading history...
61
62
    // Empty array
63
    $this->assertEquals(array(), HelperArray::filter($test = array(), $callback));
0 ignored issues
show
Bug introduced by
$test = array() cannot be passed to filter() as the parameter $array expects a reference.
Loading history...
64
65
    // Not empty array with one empty element
66
    $this->assertEquals(array(), HelperArray::filter($test = array(''), $callback));
0 ignored issues
show
Bug introduced by
$test = array('') cannot be passed to filter() as the parameter $array expects a reference.
Loading history...
67
68
    // Not empty array with one filterable element
69
    $this->assertEquals(array('test'), HelperArray::filter($test = array('test', ''), $callback));
0 ignored issues
show
Bug introduced by
$test = array('test', '') cannot be passed to filter() as the parameter $array expects a reference.
Loading history...
70
71
    // Not empty array with both filterable elements
72
    $this->assertEquals(array(), HelperArray::filter($test = array('0', ''), $callback));
0 ignored issues
show
Bug introduced by
$test = array('0', '') cannot be passed to filter() as the parameter $array expects a reference.
Loading history...
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