Completed
Pull Request — master (#15)
by Marco
02:37
created

ChangesTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testWithAddedChange() 0 7 1
A testFromArrayThowsExceptionWhenInvalidChangePassed() 0 4 1
A testFromArray() 0 7 1
A invalidChangeProvider() 0 12 1
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