Passed
Pull Request — master (#149)
by
unknown
05:10
created

DonationAddressChangeTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testWhenDonationIsCreated_addressChangeUuidIsStored() 0 14 1
A testWhenAddressIsUpdated_addressChangeUuidIsUpdated() 0 18 1
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