Completed
Pull Request — master (#10)
by Gabriel
60:20
created

AddressChangeBuilderTest::generate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\AddressChangeContext\Tests\Unit\Domain\Model;
6
7
use PHPUnit\Framework\TestCase;
8
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChangeId;
9
use WMDE\Fundraising\AddressChangeContext\Domain\Model\UuidGenerator;
10
use WMDE\Fundraising\AddressChangeContext\Domain\Model\Address;
11
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChange;
12
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChangeBuilder;
13
14
class AddressChangeBuilderTest extends TestCase implements UuidGenerator {
15
16
	public function testGivenParametersForCreateTheyArePassedToAddressChange(): void {
17
		$identifier = AddressChangeId::fromString( '77c12190-d97a-4564-9d88-160be51dd134' );
18
		$address = Address::newCompanyAddress( 'Bank of Duckburg', 'At the end of the road', '1234', 'Duckburg', 'DE' );
19
		$addressChange = AddressChangeBuilder::create( $identifier, $address )->forPerson()->forDonation( 1 )->build();
20
21
		$this->assertSame( $identifier, $addressChange->getCurrentIdentifier() );
22
		$this->assertSame( $address, $addressChange->getAddress() );
23
	}
24
25
	public function testBuildPersonalAddressChangeForDonation(): void {
26
		$addressChange = AddressChangeBuilder::create()->forPerson()->forDonation( 1 )->build();
27
28
		$this->assertTrue( $addressChange->isPersonalAddress() );
29
		$this->assertSame( 1, $addressChange->getExternalId() );
30
		$this->assertSame( AddressChange::EXTERNAL_ID_TYPE_DONATION, $addressChange->getExternalIdType() );
31
	}
32
33
	public function testBuildCompanyAddressChangeForDonation(): void {
34
		$addressChange = AddressChangeBuilder::create()->forCompany()->forDonation( 1 )->build();
35
36
		$this->assertTrue( $addressChange->isCompanyAddress() );
37
	}
38
39
	public function testBuildPersonalAddressChangeForMembership(): void {
40
		$addressChange = AddressChangeBuilder::create()->forPerson()->forMembership( 3 )->build();
41
42
		$this->assertSame( 3, $addressChange->getExternalId() );
43
		$this->assertSame( AddressChange::EXTERNAL_ID_TYPE_MEMBERSHIP, $addressChange->getExternalIdType() );
44
	}
45
46
	public function testPersonCannotBeChangedToCompany(): void {
47
		$this->expectException( \RuntimeException::class );
48
49
		AddressChangeBuilder::create()->forPerson()->forCompany();
50
	}
51
52
	public function testCompanyCannotBeChangedToPerson(): void {
53
		$this->expectException( \RuntimeException::class );
54
55
		AddressChangeBuilder::create()->forCompany()->forPerson();
56
	}
57
58
	public function testDonationCannotBeChangedToMembership(): void {
59
		$this->expectException( \RuntimeException::class );
60
61
		AddressChangeBuilder::create()->forDonation( 1 )->forMembership( 1 );
62
	}
63
64
	public function testMembershipCannotBeChangedToDonation(): void {
65
		$this->expectException( \RuntimeException::class );
66
67
		AddressChangeBuilder::create()->forMembership( 1 )->forDonation( 1 );
68
	}
69
70
	public function testAddressAndReferenceTypeHaveToBeSpecified(): void {
71
		$this->expectException( \RuntimeException::class );
72
73
		AddressChangeBuilder::create()->build();
74
	}
75
76
	public function testUuidGeneratorCanBeSwitchedOut(): void {
77
		AddressChangeBuilder::setUuidGenerator( $this );
78
		$addressChange = $addressChange = AddressChangeBuilder::create()->forPerson()->forDonation( 1 )->build();
0 ignored issues
show
Unused Code introduced by
The assignment to $addressChange is dead and can be removed.
Loading history...
79
80
		$this->assertSame( 'c956688a-89e8-41b7-b93e-7e4cf3d6c826', (string) $addressChange->getCurrentIdentifier() );
81
	}
82
83
	public function generate(): string {
84
		return 'c956688a-89e8-41b7-b93e-7e4cf3d6c826';
85
	}
86
87
88
}
89