Passed
Pull Request — master (#149)
by
unknown
03:33 queued 01:20
created

testWhenNewAddressChangeIsPersisted_uuidIsGeneratedAndStored()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
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\AddressChange;
10
use WMDE\Fundraising\Entities\Donation;
11
use WMDE\Fundraising\Entities\MembershipApplication;
12
13
/**
14
 * @covers WMDE\Fundraising\Entities\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::newDefault()->getFactory()->getEntityManager();
25
	}
26
27
	public function testWhenNewAddressChangeIsPersisted_uuidIsGeneratedAndStored() {
28
		$addressChange = new AddressChange();
29
		$this->entityManager->persist( $addressChange );
30
		$this->entityManager->flush();
31
32
		/** @var AddressChange $retrievedAddressChange */
33
		$retrievedAddressChange = $this->entityManager->getRepository( AddressChange::class )->findOneBy( [] );
34
35
		$this->assertSame( $addressChange->getCurrentIdentifier(), $retrievedAddressChange->getCurrentIdentifier() );
36
	}
37
38
	public function testWhenAddressIdentifierIsUpdated_dataIsProperlyAssigned() {
39
		$addressChange = new AddressChange();
40
		$initialIdentifier = $addressChange->getCurrentIdentifier();
41
		$addressChange->updateAddressIdentifier();
42
43
		$this->assertSame( $initialIdentifier, $addressChange->getPreviousIdentifier() );
44
		$this->assertNotSame( $initialIdentifier, $addressChange->getCurrentIdentifier() );
45
	}
46
47
	public function testWhenMembershipApplicationIsCreated_addressChangeUuidIsStored(): void {
48
		$application = new MembershipApplication();
49
50
		$oldId = $application->getAddressChange()->getCurrentIdentifier();
51
		$this->entityManager->persist( $application );
52
		$this->entityManager->flush();
53
54
		/** @var MembershipApplication $persistedApplication */
55
		$persistedApplication = $this->entityManager->find( MembershipApplication::class, 1 );
56
		$this->assertSame(
57
			$oldId,
58
			$persistedApplication->getAddressChange()->getCurrentIdentifier()
59
		);
60
	}
61
62
	public function testWhenDonationIsCreated_addressChangeUuidIsStored(): void {
63
		$donation = new Donation();
64
65
		$oldId = $donation->getAddressChange()->getCurrentIdentifier();
66
		$this->entityManager->persist( $donation );
67
		$this->entityManager->flush();
68
69
		/** @var Donation $persistedDonation */
70
		$persistedDonation = $this->entityManager->find( Donation::class, 1 );
71
		$this->assertSame(
72
			$oldId,
73
			$persistedDonation->getAddressChange()->getCurrentIdentifier()
74
		);
75
	}
76
77
	public function testWhenAddressIsUpdated_addressChangeUuidIsUpdated(): void {
78
		$application = new MembershipApplication();
79
80
		$oldId = $application->getAddressChange()->getCurrentIdentifier();
81
82
		$this->entityManager->persist( $application );
83
		$this->entityManager->flush();
84
85
		/** @var MembershipApplication $persistedApplication */
86
		$persistedApplication = $this->entityManager->find( MembershipApplication::class, 1 );
87
88
		$this->assertNull( $persistedApplication->getAddressChange()->getPreviousIdentifier() );
89
90
		$persistedApplication->getAddressChange()->updateAddressIdentifier();
91
92
		$this->assertNotSame( $oldId, $persistedApplication->getAddressChange()->getCurrentIdentifier() );
93
		$this->assertSame( $oldId, $persistedApplication->getAddressChange()->getPreviousIdentifier() );
94
	}
95
}
96