Completed
Pull Request — master (#15)
by James
02:25
created

ChangesTest::invalidChangeProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace RoaveTest\ApiCompare;
5
6
use InvalidArgumentException;
7
use Roave\ApiCompare\Change;
8
use Roave\ApiCompare\Changes;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * @covers \Roave\ApiCompare\Changes
13
 */
14
final class ChangesTest extends TestCase
15
{
16
    public function testFromArray() : void
17
    {
18
        $change = Change::added('added', true);
19
20
        self::assertSame(
21
            [$change],
22
            iterator_to_array(Changes::fromArray([$change]))
23
        );
24
    }
25
26
    /**
27
     * @return mixed[]
28
     * @throws \Exception
29
     */
30
    public function invalidChangeProvider() : array
31
    {
32
        return [
33
            [random_int(1, 100)],
34
            [random_int(1, 100) / 1000],
35
            [uniqid('string', true)],
36
            [random_bytes(24)],
37
            [[]],
38
            [null],
39
            [true],
40
            [false],
41
            [new \stdClass()],
42
        ];
43
    }
44
45
    /**
46
     * @param mixed $invalidChange
47
     * @dataProvider invalidChangeProvider
48
     */
49
    public function testFromArrayThowsExceptionWhenInvalidChangePassed($invalidChange) : void
50
    {
51
        $this->expectException(InvalidArgumentException::class);
52
        Changes::fromArray([$invalidChange]);
53
    }
54
55
    public function testWithAddedChange() : void
56
    {
57
        $change = Change::added('added', true);
58
59
        self::assertSame(
60
            [$change],
61
            iterator_to_array(Changes::new()->withAddedChange($change))
62
        );
63
    }
64
}
65