|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Store\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManager; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use WMDE\Fundraising\Entities\Donation; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @covers WMDE\Fundraising\Entities\AddressChange |
|
13
|
|
|
*/ |
|
14
|
|
|
class DonationAddressChangeTest extends TestCase { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var EntityManager |
|
18
|
|
|
*/ |
|
19
|
|
|
private $entityManager; |
|
20
|
|
|
|
|
21
|
|
|
public function setUp(): void { |
|
22
|
|
|
$this->entityManager = TestEnvironment::newDefault()->getFactory()->getEntityManager(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testWhenDonationIsCreated_addressChangeUuidIsStored(): void { |
|
26
|
|
|
$donation = new Donation(); |
|
27
|
|
|
|
|
28
|
|
|
$oldId = $donation->getAddressChange()->getCurrentIdentifier(); |
|
29
|
|
|
$this->entityManager->persist( $donation ); |
|
30
|
|
|
$this->entityManager->flush(); |
|
31
|
|
|
|
|
32
|
|
|
/** @var Donation $persistedDonation */ |
|
33
|
|
|
$persistedDonation = $this->entityManager->find( Donation::class, 1 ); |
|
34
|
|
|
$this->assertSame( |
|
35
|
|
|
$oldId, |
|
36
|
|
|
$persistedDonation->getAddressChange()->getCurrentIdentifier() |
|
37
|
|
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testWhenAddressIsUpdated_addressChangeUuidIsUpdated(): void { |
|
41
|
|
|
$donation = new Donation(); |
|
42
|
|
|
|
|
43
|
|
|
$oldId = $donation->getAddressChange()->getCurrentIdentifier(); |
|
44
|
|
|
|
|
45
|
|
|
$this->entityManager->persist( $donation ); |
|
46
|
|
|
$this->entityManager->flush(); |
|
47
|
|
|
|
|
48
|
|
|
/** @var Donation $persistedDonation */ |
|
49
|
|
|
$persistedDonation = $this->entityManager->find( Donation::class, 1 ); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertNull( $persistedDonation->getAddressChange()->getPreviousIdentifier() ); |
|
52
|
|
|
|
|
53
|
|
|
$persistedDonation->getAddressChange()->updateAddressIdentifier(); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertNotSame( $oldId, $persistedDonation->getAddressChange()->getCurrentIdentifier() ); |
|
56
|
|
|
$this->assertSame( $oldId, $persistedDonation->getAddressChange()->getPreviousIdentifier() ); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|