|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the daikon-cqrs/entity project. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Daikon\Tests\Entity; |
|
10
|
|
|
|
|
11
|
|
|
use Daikon\Entity\AttributeInterface; |
|
12
|
|
|
use Daikon\Entity\AttributeMap; |
|
13
|
|
|
use Daikon\Interop\InvalidArgumentException; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
final class AttributeMapTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
1 |
|
public function testConstructWithSelf(): void |
|
19
|
|
|
{ |
|
20
|
1 |
|
$attributeMock = $this->createMock(AttributeInterface::class); |
|
21
|
1 |
|
$attributeMock->expects($this->exactly(2))->method('getName')->willReturn('mock'); |
|
22
|
|
|
|
|
23
|
1 |
|
$attributeMap = new AttributeMap([$attributeMock]); |
|
24
|
1 |
|
$newMap = new AttributeMap($attributeMap); |
|
25
|
1 |
|
$this->assertCount(1, $newMap); |
|
26
|
1 |
|
$this->assertFalse($attributeMap === $newMap); |
|
27
|
1 |
|
} |
|
28
|
|
|
|
|
29
|
1 |
|
public function testConstructWithDuplicateKey(): void |
|
30
|
|
|
{ |
|
31
|
1 |
|
$this->expectException(InvalidArgumentException::class); |
|
32
|
1 |
|
$attributeMock = $this->createMock(AttributeInterface::class); |
|
33
|
1 |
|
$attributeMock->expects($this->exactly(2))->method('getName')->willReturn('mock'); |
|
34
|
1 |
|
new AttributeMap([$attributeMock, $attributeMock]); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
1 |
|
public function testPush(): void |
|
38
|
|
|
{ |
|
39
|
1 |
|
$emptyMap = new AttributeMap; |
|
40
|
|
|
/** @var AttributeInterface $attributeMock */ |
|
41
|
1 |
|
$attributeMock = $this->createMock(AttributeInterface::class); |
|
42
|
1 |
|
$attributeMap = $emptyMap->with('mock', $attributeMock); |
|
43
|
1 |
|
$this->assertCount(1, $attributeMap); |
|
44
|
1 |
|
$this->assertEquals($attributeMock, $attributeMap->get('mock')); |
|
45
|
1 |
|
$this->assertTrue($emptyMap->isEmpty()); |
|
46
|
1 |
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|