1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Identity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Identity\FullNameEmbeddableInterface; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ImplementNotifyChangeTrackingPolicyInterface; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Traits\ImplementNotifyChangeTrackingPolicy; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class FullNameEmbeddableTest |
13
|
|
|
* |
14
|
|
|
* @package EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Identity |
15
|
|
|
* @SuppressWarnings(PHPMD.UnusedLocalVariable) |
16
|
|
|
*/ |
17
|
|
|
class FullNameEmbeddableTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @test |
21
|
|
|
* @small |
22
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Identity\FullNameEmbeddable::<public> |
23
|
|
|
*/ |
24
|
|
|
public function itCanGetAndSetAllTheThings(): void |
25
|
|
|
{ |
26
|
|
|
$expected = [ |
27
|
|
|
FullNameEmbeddableInterface::EMBEDDED_PROP_TITLE => 'Sir', |
28
|
|
|
FullNameEmbeddableInterface::EMBEDDED_PROP_FIRSTNAME => 'Roger', |
29
|
|
|
FullNameEmbeddableInterface::EMBEDDED_PROP_MIDDLENAMES => [ |
30
|
|
|
'Michael', |
31
|
|
|
'Stephen', |
32
|
|
|
"O'Neil", |
33
|
|
|
], |
34
|
|
|
FullNameEmbeddableInterface::EMBEDDED_PROP_LASTNAME => 'Marmaduke', |
35
|
|
|
FullNameEmbeddableInterface::EMBEDDED_PROP_SUFFIX => 'The Third', |
36
|
|
|
]; |
37
|
|
|
$embeddable = new FullNameEmbeddable(); |
38
|
|
|
$embeddable->setOwningEntity(new class() implements ImplementNotifyChangeTrackingPolicyInterface |
39
|
|
|
{ |
40
|
|
|
private static $metaData; |
41
|
|
|
|
42
|
|
|
public function __construct() |
43
|
|
|
{ |
44
|
|
|
self::$metaData = new ClassMetadata('anon'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
use ImplementNotifyChangeTrackingPolicy; |
48
|
|
|
}); |
49
|
|
|
$actual = []; |
50
|
|
|
foreach ($expected as $property => $value) { |
51
|
|
|
$setter = "set$property"; |
52
|
|
|
$getter = "get$property"; |
53
|
|
|
$embeddable->$setter($value); |
54
|
|
|
$actual[$property] = $embeddable->$getter(); |
55
|
|
|
} |
56
|
|
|
self::assertSame($expected, $actual); |
57
|
|
|
self::assertSame('Sir Roger Michael Stephen O\'Neil Marmaduke The Third', $embeddable->getFormatted()); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|