AddressChangeBuilderTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 30
c 1
b 0
f 0
dl 0
loc 72
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testBuildPersonalAddressChangeForDonation() 0 6 1
A testMembershipCannotBeChangedToDonation() 0 4 1
A testGivenParametersForCreateTheyArePassedToAddressChange() 0 7 1
A testDonationCannotBeChangedToMembership() 0 4 1
A testPersonCannotBeChangedToCompany() 0 4 1
A testAddressAndReferenceTypeHaveToBeSpecified() 0 4 1
A generate() 0 2 1
A testBuildPersonalAddressChangeForMembership() 0 5 1
A testBuildCompanyAddressChangeForDonation() 0 4 1
A testCompanyCannotBeChangedToPerson() 0 4 1
A testUuidGeneratorCanBeSwitchedOut() 0 5 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\AddressChangeContext\Tests\Unit\Domain\Model;
6
7
use PHPUnit\Framework\Attributes\CoversClass;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\Attributes\CoversClass was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use PHPUnit\Framework\TestCase;
9
use WMDE\Fundraising\AddressChangeContext\Domain\Model\Address;
10
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChange;
11
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChangeBuilder;
12
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChangeId;
13
use WMDE\Fundraising\AddressChangeContext\Domain\Model\UuidGenerator;
14
15
#[CoversClass( AddressChangeBuilder::class )]
16
class AddressChangeBuilderTest extends TestCase implements UuidGenerator {
17
18
	public function testGivenParametersForCreateTheyArePassedToAddressChange(): void {
19
		$identifier = AddressChangeId::fromString( '77c12190-d97a-4564-9d88-160be51dd134' );
20
		$address = Address::newCompanyAddress( 'Bank of Duckburg', 'At the end of the road', '1234', 'Duckburg', 'DE' );
21
		$addressChange = AddressChangeBuilder::create( $identifier, $address )->forPerson()->forDonation( 1 )->build();
22
23
		$this->assertSame( $identifier, $addressChange->getCurrentIdentifier() );
24
		$this->assertSame( $address, $addressChange->getAddress() );
25
	}
26
27
	public function testBuildPersonalAddressChangeForDonation(): void {
28
		$addressChange = AddressChangeBuilder::create()->forPerson()->forDonation( 1 )->build();
29
30
		$this->assertTrue( $addressChange->isPersonalAddress() );
31
		$this->assertSame( 1, $addressChange->getExternalId() );
32
		$this->assertSame( AddressChange::EXTERNAL_ID_TYPE_DONATION, $addressChange->getExternalIdType() );
33
	}
34
35
	public function testBuildCompanyAddressChangeForDonation(): void {
36
		$addressChange = AddressChangeBuilder::create()->forCompany()->forDonation( 1 )->build();
37
38
		$this->assertTrue( $addressChange->isCompanyAddress() );
39
	}
40
41
	public function testBuildPersonalAddressChangeForMembership(): void {
42
		$addressChange = AddressChangeBuilder::create()->forPerson()->forMembership( 3 )->build();
43
44
		$this->assertSame( 3, $addressChange->getExternalId() );
45
		$this->assertSame( AddressChange::EXTERNAL_ID_TYPE_MEMBERSHIP, $addressChange->getExternalIdType() );
46
	}
47
48
	public function testPersonCannotBeChangedToCompany(): void {
49
		$this->expectException( \RuntimeException::class );
50
51
		AddressChangeBuilder::create()->forPerson()->forCompany();
52
	}
53
54
	public function testCompanyCannotBeChangedToPerson(): void {
55
		$this->expectException( \RuntimeException::class );
56
57
		AddressChangeBuilder::create()->forCompany()->forPerson();
58
	}
59
60
	public function testDonationCannotBeChangedToMembership(): void {
61
		$this->expectException( \RuntimeException::class );
62
63
		AddressChangeBuilder::create()->forDonation( 1 )->forMembership( 1 );
64
	}
65
66
	public function testMembershipCannotBeChangedToDonation(): void {
67
		$this->expectException( \RuntimeException::class );
68
69
		AddressChangeBuilder::create()->forMembership( 1 )->forDonation( 1 );
70
	}
71
72
	public function testAddressAndReferenceTypeHaveToBeSpecified(): void {
73
		$this->expectException( \RuntimeException::class );
74
75
		AddressChangeBuilder::create()->build();
76
	}
77
78
	public function testUuidGeneratorCanBeSwitchedOut(): void {
79
		AddressChangeBuilder::setUuidGenerator( $this );
80
		$addressChange = AddressChangeBuilder::create()->forPerson()->forDonation( 1 )->build();
81
82
		$this->assertSame( 'c956688a-89e8-41b7-b93e-7e4cf3d6c826', (string)$addressChange->getCurrentIdentifier() );
83
	}
84
85
	public function generate(): string {
86
		return 'c956688a-89e8-41b7-b93e-7e4cf3d6c826';
87
	}
88
89
}
90