Skip to content

Commit f963748

Browse files
committed
IHF: array_except_value fully covered.
1 parent 8c6d6b2 commit f963748

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

tests/array/ArrayExceptValueTest.php

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
class ArrayExceptValueTest extends TestCase
4+
{
5+
/** @test */
6+
public function it_works_with_an_empty_array_and_empty_value()
7+
{
8+
$this->assertEquals([], array_except_value([], null));
9+
}
10+
11+
/** @test */
12+
public function it_works_with_an_empty_array_and_not_empty_value()
13+
{
14+
$this->assertEquals([], array_except_value([], 'foo'));
15+
}
16+
17+
/** @test */
18+
public function it_works_with_unexisting_value()
19+
{
20+
$this->assertEquals(['foo', 'bar', 'baz'], array_except_value(['foo', 'bar', 'baz'], 'bax'));
21+
}
22+
23+
/** @test */
24+
public function it_preserves_keys()
25+
{
26+
$this->assertEquals(
27+
[0 => 'foo', 2 => 'baz'],
28+
array_except_value(['foo', 'bar', 'baz'], 'bar')
29+
);
30+
}
31+
32+
/** @test */
33+
public function it_works_with_multiple_occurrences()
34+
{
35+
$this->assertEquals(
36+
[0 => 'foo', 4 => 'bar'],
37+
array_except_value(['foo', 'baz', 'baz', 'baz', 'bar'], 'baz')
38+
);
39+
}
40+
41+
/** @test */
42+
public function it_works_with_null_value()
43+
{
44+
$this->assertEquals(['foo', 'bar', 'baz'], array_except_value(['foo', 'bar', 'baz', null], null));
45+
}
46+
47+
/** @test */
48+
public function it_works_with_boolean_true_value()
49+
{
50+
$this->assertEquals(['foo', 'bar', 'baz'], array_except_value(['foo', 'bar', 'baz', true, true], true));
51+
}
52+
53+
/** @test */
54+
public function it_works_with_boolean_false_value()
55+
{
56+
$this->assertEquals(
57+
['foo', 'bar', 'baz', 5 => null],
58+
array_except_value(['foo', 'bar', 'baz', false, false, null], false)
59+
);
60+
}
61+
62+
/** @test */
63+
public function it_works_with_integer_value()
64+
{
65+
$this->assertEquals(
66+
[0 => 23, 2 => 14, 3 => 11],
67+
array_except_value([23, 17, 14, 11], 17)
68+
);
69+
}
70+
71+
/** @test */
72+
public function it_works_with_float_value()
73+
{
74+
$this->assertEquals(
75+
[0 => 23.3, 1 => 17.2, 3 => 11.1],
76+
array_except_value([23.3, 17.2, 14.5, 11.1], 14.5)
77+
);
78+
}
79+
80+
/** @test */
81+
public function it_works_with_string_value()
82+
{
83+
$this->assertEquals(['foo', 'bar'], array_except_value(['foo', 'bar', 'baz'], 'baz'));
84+
}
85+
86+
/** @test */
87+
public function it_works_with_associative_array_and_string_value()
88+
{
89+
$array = [
90+
'foo' => 'bar',
91+
'baz' => 'bax',
92+
'foz' => 'faz',
93+
];
94+
$this->assertEquals(['foo' => 'bar', 'foz' => 'faz'], array_except_value($array, 'bax'));
95+
}
96+
97+
/** @test */
98+
public function it_works_with_associative_array_and_array_value()
99+
{
100+
$array = [
101+
'foo' => 'bar',
102+
'baz' => 'bax',
103+
'foz' => 'faz',
104+
];
105+
$this->assertEquals(['baz' => 'bax'], array_except_value($array, ['bar', 'faz', 'maz']));
106+
}
107+
}

0 commit comments

Comments
 (0)