1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\C\Entity\Embeddable\Traits\Attribute; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\DataTransferObjects\AbstractEntityUpdateDto; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Attribute\WeightEmbeddableInterface; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Attribute\WeightEmbeddable; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractLargeTest; |
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @large |
14
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Traits\Attribute\HasWeightEmbeddableTrait |
15
|
|
|
*/ |
16
|
|
|
class HasWeightEmbeddableTraitLargeTest extends AbstractLargeTest |
17
|
|
|
{ |
18
|
|
|
public const WORK_DIR = self::VAR_PATH . '/' . self::TEST_TYPE_LARGE . '/HasWeightEmbeddableTraitLargeTest'; |
19
|
|
|
private const TEST_ENTITY = self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_ALL_EMBEDDABLES; |
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $entityFqn; |
24
|
|
|
|
25
|
|
|
public function setUp() |
26
|
|
|
{ |
27
|
|
|
parent::setUp(); |
28
|
|
|
$this->generateTestCode(); |
29
|
|
|
$this->setupCopiedWorkDirAndCreateDatabase(); |
30
|
|
|
$this->entityFqn = $this->getCopiedFqn(self::TEST_ENTITY); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
36
|
|
|
* @throws \ReflectionException |
37
|
|
|
*/ |
38
|
|
|
public function itCanBeSavedAndReloadedWithTheCorrectValues() |
39
|
|
|
{ |
40
|
|
|
$entity = $this->createTestEntity(); |
41
|
|
|
$entity->update(new class($this->getCopiedFqn(self::TEST_ENTITY), $entity->getId()) |
42
|
|
|
extends AbstractEntityUpdateDto |
43
|
|
|
{ |
44
|
|
|
public function getWeightEmbeddable(): WeightEmbeddableInterface |
45
|
|
|
{ |
46
|
|
|
return new WeightEmbeddable( |
47
|
|
|
WeightEmbeddableInterface::UNIT_GRAM, |
48
|
|
|
100 |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
}); |
52
|
|
|
$this->getEntitySaver()->save($entity); |
53
|
|
|
$loaded = |
54
|
|
|
$this->getRepositoryFactory()->getRepository($this->getCopiedFqn(self::TEST_ENTITY))->findAll()[0]; |
55
|
|
|
$loadedWeightEmbeddable = $loaded->getWeightEmbeddable(); |
56
|
|
|
self::assertSame(WeightEmbeddableInterface::UNIT_GRAM, $loadedWeightEmbeddable->getUnit()); |
57
|
|
|
self::assertSame(100.0, $loadedWeightEmbeddable->getValue()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return EntityInterface |
62
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
63
|
|
|
* @throws \ReflectionException |
64
|
|
|
*/ |
65
|
|
|
private function createTestEntity(): EntityInterface |
66
|
|
|
{ |
67
|
|
|
return $this->createEntity($this->getCopiedFqn(self::TEST_ENTITY)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |