|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Traits\Financial; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\AbstractIntegrationTest; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Financial\HasMoneyEmbeddableInterface; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Financial\MoneyEmbeddableInterface; |
|
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial\MoneyEmbeddable; |
|
9
|
|
|
use Money\Currency; |
|
10
|
|
|
use Money\Money; |
|
11
|
|
|
|
|
12
|
|
|
class HasMoneyEmbeddableTraitIntegrationTest extends AbstractIntegrationTest |
|
13
|
|
|
{ |
|
14
|
|
|
public const WORK_DIR = AbstractIntegrationTest::VAR_PATH.'/'.self::TEST_TYPE.'/HasMoneyEmbeddableTraitTest'; |
|
15
|
|
|
|
|
16
|
|
|
private const TEST_ENTITY = self::TEST_PROJECT_ROOT_NAMESPACE.'\\Entities\\BankAccount'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var HasMoneyEmbeddableInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
private $entity; |
|
22
|
|
|
|
|
23
|
|
|
public function setup() |
|
24
|
|
|
{ |
|
25
|
|
|
parent::setup(); |
|
26
|
|
|
$this->getEntityGenerator()->generateEntity(self::TEST_ENTITY); |
|
27
|
|
|
$this->getEntityEmbeddableSetter() |
|
28
|
|
|
->setEntityHasEmbeddable(self::TEST_ENTITY, HasMoneyEmbeddableTrait::class); |
|
29
|
|
|
$this->setupCopiedWorkDir(); |
|
30
|
|
|
$entityFqn = $this->getCopiedFqn(self::TEST_ENTITY); |
|
31
|
|
|
$this->entity = new $entityFqn; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
|
37
|
|
|
* @throws \ReflectionException |
|
38
|
|
|
* @test |
|
39
|
|
|
* @medium |
|
40
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\Embeddable\EntityEmbeddableSetter |
|
41
|
|
|
*/ |
|
42
|
|
|
public function generatedCodePassesQa() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->assertTrue($this->qaGeneratedCode()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @test |
|
49
|
|
|
* @medium |
|
50
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Traits\Financial\HasMoneyEmbeddableTrait::getMoneyEmbeddable() |
|
51
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial\MoneyEmbeddable::getMoney() |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $expectedAmount |
|
54
|
|
|
*/ |
|
55
|
|
|
public function theEntityWithTheTraitCanGetTheMoneyObject( |
|
56
|
|
|
string $expectedAmount = MoneyEmbeddableInterface::DEFAULT_AMOUNT |
|
57
|
|
|
) { |
|
58
|
|
|
$money = $this->entity->getMoneyEmbeddable()->getMoney(); |
|
59
|
|
|
$expected = [ |
|
60
|
|
|
'amount' => $expectedAmount, |
|
61
|
|
|
'currencyCode' => MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE, |
|
62
|
|
|
]; |
|
63
|
|
|
$actual = [ |
|
64
|
|
|
'amount' => $money->getAmount(), |
|
65
|
|
|
'currencyCode' => $money->getCurrency()->getCode(), |
|
66
|
|
|
]; |
|
67
|
|
|
$this->assertSame($expected, $actual); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @test |
|
72
|
|
|
* @medium |
|
73
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial\MoneyEmbeddable::setMoney() |
|
74
|
|
|
*/ |
|
75
|
|
|
public function theEntityWithTheTraitCanSetTheMoneyObject() |
|
76
|
|
|
{ |
|
77
|
|
|
$money = new Money(100, new Currency(MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE)); |
|
78
|
|
|
$this->entity->getMoneyEmbeddable()->setMoney($money); |
|
79
|
|
|
|
|
80
|
|
|
$this->theEntityWithTheTraitCanGetTheMoneyObject('100'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @test |
|
85
|
|
|
* @medium |
|
86
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Traits\Financial\HasMoneyEmbeddableTrait::setMoneyEmbeddable() |
|
87
|
|
|
*/ |
|
88
|
|
|
public function theEntityWithTheTraitCanSetTheMoneyEmbeddable() |
|
89
|
|
|
{ |
|
90
|
|
|
$money = new Money(200, new Currency(MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE)); |
|
91
|
|
|
$moneyEmbeddable = new MoneyEmbeddable(); |
|
92
|
|
|
$moneyEmbeddable->setMoney($money); |
|
93
|
|
|
$this->entity->setMoneyEmbeddable($moneyEmbeddable); |
|
94
|
|
|
$this->theEntityWithTheTraitCanGetTheMoneyObject('200'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @test |
|
99
|
|
|
* @medium |
|
100
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial\MoneyEmbeddable::addMoney() |
|
101
|
|
|
*/ |
|
102
|
|
|
public function theEntityWithTheTraitCanAddAMoneyObjectToTheCurrentMoneyObject() |
|
103
|
|
|
{ |
|
104
|
|
|
$money = new Money(300, new Currency(MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE)); |
|
105
|
|
|
$this->entity->getMoneyEmbeddable()->addMoney($money); |
|
106
|
|
|
$this->theEntityWithTheTraitCanGetTheMoneyObject('300'); |
|
107
|
|
|
$money = new Money(100, new Currency(MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE)); |
|
108
|
|
|
$this->entity->getMoneyEmbeddable()->addMoney($money); |
|
109
|
|
|
$this->theEntityWithTheTraitCanGetTheMoneyObject('400'); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @test |
|
114
|
|
|
* @medium |
|
115
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial\MoneyEmbeddable::subtractMoney() |
|
116
|
|
|
*/ |
|
117
|
|
|
public function theEntityWithTheTraitCanSubtractAMoneyObjectToTheCurrentMoneyObject() |
|
118
|
|
|
{ |
|
119
|
|
|
$money = new Money(1, new Currency(MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE)); |
|
120
|
|
|
$this->entity->getMoneyEmbeddable()->subtractMoney($money); |
|
121
|
|
|
$this->theEntityWithTheTraitCanGetTheMoneyObject('-1'); |
|
122
|
|
|
$money = new Money(2, new Currency(MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE)); |
|
123
|
|
|
$this->entity->getMoneyEmbeddable()->subtractMoney($money); |
|
124
|
|
|
$this->theEntityWithTheTraitCanGetTheMoneyObject('-3'); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|