Passed
Pull Request — main (#8)
by Anatoly
11:42
created

ObjectCollectionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 17
dl 0
loc 45
c 1
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testContracts() 0 5 1
A testAdd() 0 15 1
A testUnexpectedObject() 0 9 1
1
<?php declare(strict_types=1);
2
3
namespace Sunrise\Hydrator\Tests;
4
5
/**
6
 * Import classes
7
 */
8
use PHPUnit\Framework\TestCase;
9
use Sunrise\Hydrator\ObjectCollection;
10
use Sunrise\Hydrator\ObjectCollectionInterface;
11
use InvalidArgumentException;
12
13
/**
14
 * ObjectCollectionTest
15
 */
16
class ObjectCollectionTest extends TestCase
17
{
18
19
    /**
20
     * @return void
21
     */
22
    public function testContracts() : void
23
    {
24
        $collection = new Fixtures\BarDtoCollection();
25
26
        $this->assertInstanceOf(ObjectCollectionInterface::class, $collection);
27
    }
28
29
    /**
30
     * @return void
31
     */
32
    public function testAdd() : void
33
    {
34
        $store = [
35
            new Fixtures\BarDto(),
36
            new Fixtures\BarDto(),
37
            new Fixtures\BarDto(),
38
        ];
39
40
        $collection = new Fixtures\BarDtoCollection();
41
42
        $collection->add(0, $store[0]);
43
        $collection->add(1, $store[1]);
44
        $collection->add(2, $store[2]);
45
46
        $this->assertSame($store, $collection->all());
47
    }
48
49
    /**
50
     * @return void
51
     */
52
    public function testUnexpectedObject() : void
53
    {
54
        $collection = new Fixtures\BarDtoCollection();
55
56
        $this->expectException(InvalidArgumentException::class);
57
        $this->expectExceptionMessage('The <' . Fixtures\BarDtoCollection::class . '> collection ' .
58
                                      'must contain the <' . Fixtures\BarDto::class . '> objects only.');
59
60
        $collection->add(0, new Fixtures\BazDto());
61
    }
62
}
63