|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\AddressChangeContext\Tests\Unit\Domain\Model; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManager; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use WMDE\Fundraising\AddressChange\Domain\Model\AddressChange; |
|
10
|
|
|
use WMDE\Fundraising\AddressChangeContext\Tests\Data\ValidAddress; |
|
11
|
|
|
use WMDE\Fundraising\AddressChangeContext\Tests\TestEnvironment; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @covers \WMDE\Fundraising\AddressChange\Domain\Model\AddressChange |
|
15
|
|
|
*/ |
|
16
|
|
|
class AddressChangeTest extends TestCase { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var EntityManager |
|
20
|
|
|
*/ |
|
21
|
|
|
private $entityManager; |
|
22
|
|
|
|
|
23
|
|
|
public function setUp(): void { |
|
24
|
|
|
$this->entityManager = TestEnvironment::newInstance()->getFactory()->getEntityManager(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testWhenNewAddressChangeIsPersisted_uuidIsGenerated() { |
|
28
|
|
|
$addressChange = AddressChange::createNewPersonAddressChange(); |
|
29
|
|
|
$this->assertNotEmpty( $addressChange->getCurrentIdentifier() ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testWhenAddressIdentifierIsUpdated_dataIsProperlyAssigned() { |
|
33
|
|
|
$addressChange = AddressChange::createNewPersonAddressChange(); |
|
34
|
|
|
$initialIdentifier = $addressChange->getCurrentIdentifier(); |
|
35
|
|
|
$address = ValidAddress::newValidPersonalAddress(); |
|
36
|
|
|
$addressChange->performAddressChange( $address ); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertSame( $initialIdentifier, $addressChange->getPreviousIdentifier() ); |
|
39
|
|
|
$this->assertNotSame( $initialIdentifier, $addressChange->getCurrentIdentifier() ); |
|
40
|
|
|
$this->assertSame( $address, $addressChange->getAddress() ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testAddressChangeCannotBePerformedTwice() { |
|
44
|
|
|
$addressChange = AddressChange::createNewPersonAddressChange(); |
|
45
|
|
|
$addressChange->performAddressChange( ValidAddress::newValidCompanyAddress() ); |
|
46
|
|
|
|
|
47
|
|
|
$this->expectException( \LogicException::class ); |
|
48
|
|
|
|
|
49
|
|
|
$addressChange->performAddressChange( ValidAddress::newValidPersonalAddress() ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testNewAddressChangeIsNotExported() { |
|
53
|
|
|
$addressChange = AddressChange::createNewPersonAddressChange(); |
|
54
|
|
|
$this->assertFalse( $addressChange->isExported() ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testAddressChangeCanBeMarkedAsExported() { |
|
58
|
|
|
$addressChange = AddressChange::createNewPersonAddressChange(); |
|
59
|
|
|
$addressChange->markAsExported(); |
|
60
|
|
|
$this->assertTrue( $addressChange->isExported() ); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testAddressChangeCannotBeExportedTwice() { |
|
64
|
|
|
$addressChange = AddressChange::createNewPersonAddressChange(); |
|
65
|
|
|
$addressChange->markAsExported(); |
|
66
|
|
|
|
|
67
|
|
|
$this->expectException( \LogicException::class ); |
|
68
|
|
|
|
|
69
|
|
|
$addressChange->markAsExported(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testWhenAddressChangeIsPerformed_exportStateIsReset() { |
|
73
|
|
|
$addressChange = AddressChange::createNewPersonAddressChange(); |
|
74
|
|
|
$addressChange->markAsExported(); |
|
75
|
|
|
$addressChange->performAddressChange( ValidAddress::newValidCompanyAddress() ); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertFalse( $addressChange->isExported() ); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testConstructorsAcceptValidUuids() { |
|
81
|
|
|
$uuid = '72dfed91-fa40-4af0-9e80-c6010ab29cd1'; |
|
82
|
|
|
$personAddressChange = AddressChange::createNewPersonAddressChange( $uuid ); |
|
83
|
|
|
$companyAddressChange = AddressChange::createNewCompanyAddressChange( $uuid ); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertSame( $uuid, $personAddressChange->getCurrentIdentifier() ); |
|
86
|
|
|
$this->assertSame( $uuid, $companyAddressChange->getCurrentIdentifier() ); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @dataProvider invalidUUIDProvider |
|
91
|
|
|
*/ |
|
92
|
|
|
public function testPersonalAddressChangeThrowsExceptionsWhenUUIDIsInvalid( string $invalidUUID ) { |
|
93
|
|
|
$this->expectException( \InvalidArgumentException::class ); |
|
94
|
|
|
AddressChange::createNewPersonAddressChange( $invalidUUID ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @dataProvider invalidUUIDProvider |
|
99
|
|
|
*/ |
|
100
|
|
|
public function testCompanyAddressChangeThrowsExceptionsWhenUUIDIsInvalid( string $invalidUUID ) { |
|
101
|
|
|
$this->expectException( \InvalidArgumentException::class ); |
|
102
|
|
|
AddressChange::createNewCompanyAddressChange( $invalidUUID ); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function invalidUUIDProvider(): \Generator { |
|
106
|
|
|
yield [ '' ]; |
|
107
|
|
|
yield [ 'just a string' ]; |
|
108
|
|
|
yield [ '1111222233334444-1111222233334444-1111222233334444-1111222233334444-1111222233334444' ]; |
|
109
|
|
|
yield [ 'e-f-f-e-d' ]; |
|
110
|
|
|
yield [ 'This-is-not-a-UUID' ]; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|