AddressChangeTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testWhenNewAddressChangeIsPersisted_uuidIsGeneratedAndStored() 0 10 1
A testWhenAddressIdentifierIsUpdated_dataIsProperlyAssigned() 0 8 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\AddressChange;
10
11
/**
12
 * @covers WMDE\Fundraising\Entities\AddressChange
13
 */
14
class AddressChangeTest 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 testWhenNewAddressChangeIsPersisted_uuidIsGeneratedAndStored() {
26
		$addressChange = AddressChange::newDonationAddressChange( AddressChange::ADDRESS_TYPE_PERSON, 1 );
27
		$this->entityManager->persist( $addressChange );
28
		$this->entityManager->flush();
29
30
		/** @var AddressChange $retrievedAddressChange */
31
		$retrievedAddressChange = $this->entityManager->getRepository( AddressChange::class )->findOneBy( [] );
32
33
		$this->assertSame( $addressChange->getCurrentIdentifier(), $retrievedAddressChange->getCurrentIdentifier() );
34
	}
35
36
	public function testWhenAddressIdentifierIsUpdated_dataIsProperlyAssigned() {
37
		$addressChange = AddressChange::newMembershipAddressChange( AddressChange::ADDRESS_TYPE_PERSON, 2 );
38
		$initialIdentifier = $addressChange->getCurrentIdentifier();
39
		$addressChange->updateAddressIdentifier();
40
41
		$this->assertSame( $initialIdentifier, $addressChange->getPreviousIdentifier() );
42
		$this->assertNotSame( $initialIdentifier, $addressChange->getCurrentIdentifier() );
43
	}
44
}
45