Passed
Pull Request — master (#149)
by
unknown
12:13
created

MembershipAddressChangeTest   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 testWhenMembershipApplicationIsCreated_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\MembershipApplication;
10
11
/**
12
 * @covers WMDE\Fundraising\Entities\AddressChange
13
 */
14
class MembershipAddressChangeTest 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 testWhenMembershipApplicationIsCreated_addressChangeUuidIsStored(): void {
26
		$application = new MembershipApplication();
27
28
		$oldId = $application->getAddressChange()->getCurrentIdentifier();
29
		$this->entityManager->persist( $application );
30
		$this->entityManager->flush();
31
32
		/** @var MembershipApplication $persistedApplication */
33
		$persistedApplication = $this->entityManager->find( MembershipApplication::class, 1 );
34
		$this->assertSame(
35
			$oldId,
36
			$persistedApplication->getAddressChange()->getCurrentIdentifier()
37
		);
38
	}
39
40
	public function testWhenAddressIsUpdated_addressChangeUuidIsUpdated(): void {
41
		$application = new MembershipApplication();
42
43
		$oldId = $application->getAddressChange()->getCurrentIdentifier();
44
45
		$this->entityManager->persist( $application );
46
		$this->entityManager->flush();
47
48
		/** @var MembershipApplication $persistedApplication */
49
		$persistedApplication = $this->entityManager->find( MembershipApplication::class, 1 );
50
51
		$this->assertNull( $persistedApplication->getAddressChange()->getPreviousIdentifier() );
52
53
		$persistedApplication->getAddressChange()->updateAddressIdentifier();
54
55
		$this->assertNotSame( $oldId, $persistedApplication->getAddressChange()->getCurrentIdentifier() );
56
		$this->assertSame( $oldId, $persistedApplication->getAddressChange()->getPreviousIdentifier() );
57
	}
58
}
59