Passed
Pull Request — main (#1)
by Anatoly
02:42
created

HydrableObjectCollectionTest::testAdd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 15
rs 9.9666
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\HydrableObjectCollection;
10
use Sunrise\Hydrator\HydrableObjectCollectionInterface;
11
use InvalidArgumentException;
12
13
/**
14
 * HydrableObjectCollectionTest
15
 */
16
class HydrableObjectCollectionTest extends TestCase
17
{
18
19
    /**
20
     * @return void
21
     */
22
    public function testContracts() : void
23
    {
24
        $collection = new HydrableObjectCollection();
25
26
        $this->assertInstanceOf(HydrableObjectCollectionInterface::class, $collection);
27
    }
28
29
    /**
30
     * @return void
31
     */
32
    public function testAdd() : void
33
    {
34
        $store = [
35
            new Fixture\BarDto(),
36
            new Fixture\BarDto(),
37
            new Fixture\BarDto(),
38
        ];
39
40
        $collection = new HydrableObjectCollection();
41
42
        $collection->add($store[0]);
43
        $collection->add($store[1]);
44
        $collection->add($store[2]);
45
46
        $this->assertSame($store, $collection->getIterator()->getArrayCopy());
47
    }
48
49
    /**
50
     * @return void
51
     */
52
    public function testUnexpectedObject() : void
53
    {
54
        $collection = new Fixture\BarDtoCollection();
55
56
        $this->expectException(InvalidArgumentException::class);
57
        $this->expectExceptionMessage('The <' . Fixture\BarDtoCollection::class . '> collection ' .
58
                                      'must contain only the <' . Fixture\BarDto::class . '> objects.');
59
60
        $collection->add(new Fixture\BazDto());
61
    }
62
}
63