Passed
Branch main (45b422)
by Andreas
01:40
created

ArrayUtilsTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2
rs 10
1
<?php
2
/**
3
 * @author Antoine Hedgcock
4
 */
5
6
namespace CrateTest\Stdlib;
7
8
use ArrayIterator;
9
use Crate\Stdlib\ArrayUtils;
10
use Crate\Stdlib\Exception\InvalidArgumentException;
11
use PHPUnit\Framework\TestCase;
12
13
/**
14
 * Class ArrayUtilsTest
15
 *
16
 * @coversDefaultClass \Crate\Stdlib\ArrayUtils
17
 * @covers ::<!public>
18
 *
19
 * @group unit
20
 */
21
class ArrayUtilsTest extends TestCase
22
{
23
    /**
24
     * @covers ::toArray
25
     */
26
    public function testToArrayWithNull()
27
    {
28
        $this->assertEquals([], ArrayUtils::toArray(null));
29
    }
30
31
    /**
32
     * @covers ::toArray
33
     */
34
    public function testToArrayWithArray()
35
    {
36
        $this->assertEquals(['hello' => 'world'], ArrayUtils::toArray(['hello' => 'world']));
37
    }
38
39
    /**
40
     * @covers ::toArray
41
     */
42
    public function testToArrayWithIterator()
43
    {
44
        $this->assertEquals(['hello' => 'world'], ArrayUtils::toArray(new ArrayIterator(['hello' => 'world'])));
45
    }
46
47
    /**
48
     * @covers ::toArray
49
     */
50
    public function testToArrayWithInvalidValue()
51
    {
52
        $this->expectException(InvalidArgumentException::class);
53
        ArrayUtils::toArray('foo');
54
    }
55
}
56