|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\AddressChangeContext\Tests\Unit\UseCases; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
|
|
|
|
|
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use WMDE\Fundraising\AddressChangeContext\Domain\AddressChangeRepository; |
|
10
|
|
|
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChange; |
|
11
|
|
|
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChangeId; |
|
12
|
|
|
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressType; |
|
13
|
|
|
use WMDE\Fundraising\AddressChangeContext\UseCases\ChangeAddress\ChangeAddressRequest; |
|
14
|
|
|
use WMDE\Fundraising\AddressChangeContext\UseCases\ChangeAddress\ChangeAddressResponse; |
|
15
|
|
|
use WMDE\Fundraising\AddressChangeContext\UseCases\ChangeAddress\ChangeAddressUseCase; |
|
16
|
|
|
|
|
17
|
|
|
#[CoversClass( ChangeAddressUseCase::class )] |
|
18
|
|
|
#[CoversClass( ChangeAddressResponse::class )] |
|
19
|
|
|
class ChangeAddressUseCaseTest extends TestCase { |
|
20
|
|
|
|
|
21
|
|
|
private const VALID_SAMPLE_UUID = 'd8441c6e-1f7a-4710-97d3-0e2126c86d40'; |
|
22
|
|
|
private const DUMMY_DONATION_ID = 0; |
|
23
|
|
|
|
|
24
|
|
|
public function testGivenValidAddressChangeRequest_successResponseIsReturned(): void { |
|
25
|
|
|
$mockAddressChangeRepository = $this->createMock( AddressChangeRepository::class ); |
|
26
|
|
|
$mockAddressChangeRepository->method( 'getAddressChangeByUuid' )->willReturn( |
|
27
|
|
|
$this->createAddressChange() |
|
28
|
|
|
); |
|
29
|
|
|
$useCase = new ChangeAddressUseCase( $mockAddressChangeRepository ); |
|
30
|
|
|
$response = $useCase->changeAddress( $this->newChangeAddressRequest() ); |
|
31
|
|
|
$this->assertTrue( $response->isSuccess() ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testGivenInvalidAddressChangeRequest_errorResponseIsReturned(): void { |
|
35
|
|
|
$mockAddressChangeRepository = $this->createMock( AddressChangeRepository::class ); |
|
36
|
|
|
$mockAddressChangeRepository->method( 'getAddressChangeByUuid' )->willReturn( |
|
37
|
|
|
$this->createAddressChange() |
|
38
|
|
|
); |
|
39
|
|
|
$useCase = new ChangeAddressUseCase( $mockAddressChangeRepository ); |
|
40
|
|
|
$response = $useCase->changeAddress( $this->newMissingDataChangeAddressRequest() ); |
|
41
|
|
|
$this->assertFalse( $response->isSuccess() ); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testGivenAddressChangeRequestIdentifierCannotBeFound_errorResponseIsReturned(): void { |
|
45
|
|
|
$mockAddressChangeRepository = $this->createMock( AddressChangeRepository::class ); |
|
46
|
|
|
$mockAddressChangeRepository->method( 'getAddressChangeByUuid' )->willReturn( |
|
47
|
|
|
null |
|
48
|
|
|
); |
|
49
|
|
|
$useCase = new ChangeAddressUseCase( $mockAddressChangeRepository ); |
|
50
|
|
|
$response = $useCase->changeAddress( $this->newChangeAddressRequest() ); |
|
51
|
|
|
$this->assertFalse( $response->isSuccess() ); |
|
52
|
|
|
$this->assertEquals( [ ChangeAddressResponse::ERROR_ADDRESS_NOT_FOUND ], $response->getErrors() ); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testGivenValidOptOutOnlyChangeRequest_successResponseIsReturned(): void { |
|
56
|
|
|
$mockAddressChangeRepository = $this->createMock( AddressChangeRepository::class ); |
|
57
|
|
|
$mockAddressChangeRepository->method( 'getAddressChangeByUuid' )->willReturn( |
|
58
|
|
|
$this->createAddressChange() |
|
59
|
|
|
); |
|
60
|
|
|
$useCase = new ChangeAddressUseCase( $mockAddressChangeRepository ); |
|
61
|
|
|
$response = $useCase->changeAddress( $this->newOptOutOnlyRequest() ); |
|
62
|
|
|
$this->assertTrue( $response->isSuccess() ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testGivenEmptyAddressChangeRequest_errorResponseIsReturned(): void { |
|
66
|
|
|
$mockAddressChangeRepository = $this->createMock( AddressChangeRepository::class ); |
|
67
|
|
|
$mockAddressChangeRepository->method( 'getAddressChangeByUuid' )->willReturn( |
|
68
|
|
|
$this->createAddressChange() |
|
69
|
|
|
); |
|
70
|
|
|
$useCase = new ChangeAddressUseCase( $mockAddressChangeRepository ); |
|
71
|
|
|
$response = $useCase->changeAddress( $this->newEmptyChangeAddressRequest() ); |
|
72
|
|
|
$this->assertFalse( $response->isSuccess() ); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
private function newChangeAddressRequest(): ChangeAddressRequest { |
|
76
|
|
|
return ChangeAddressRequest::newPersonalChangeAddressRequest( |
|
77
|
|
|
salutation: 'Herr', |
|
78
|
|
|
title: 'Prof. Dr.', |
|
79
|
|
|
firstName: 'Test Name', |
|
80
|
|
|
lastName: 'Test Last Name', |
|
81
|
|
|
address: 'Test', |
|
82
|
|
|
postcode: '12345', |
|
83
|
|
|
city: 'Test City', |
|
84
|
|
|
country: 'Test Country', |
|
85
|
|
|
identifier: self::VALID_SAMPLE_UUID, |
|
86
|
|
|
donationReceipt: true, |
|
87
|
|
|
isOptOutOnly: false, |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
private function newMissingDataChangeAddressRequest(): ChangeAddressRequest { |
|
92
|
|
|
return ChangeAddressRequest::newPersonalChangeAddressRequest( |
|
93
|
|
|
salutation: 'Herr', |
|
94
|
|
|
title: 'Prof. Dr.', |
|
95
|
|
|
firstName: 'Test Name', |
|
96
|
|
|
lastName: 'Test Last Name', |
|
97
|
|
|
address: 'Test', |
|
98
|
|
|
postcode: '12345', |
|
99
|
|
|
city: '', |
|
100
|
|
|
country: 'Test Country', |
|
101
|
|
|
identifier: self::VALID_SAMPLE_UUID, |
|
102
|
|
|
donationReceipt: false, |
|
103
|
|
|
isOptOutOnly: false, |
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
private function newEmptyChangeAddressRequest(): ChangeAddressRequest { |
|
108
|
|
|
return ChangeAddressRequest::newPersonalChangeAddressRequest( |
|
109
|
|
|
salutation: '', |
|
110
|
|
|
title: '', |
|
111
|
|
|
firstName: '', |
|
112
|
|
|
lastName: '', |
|
113
|
|
|
address: '', |
|
114
|
|
|
postcode: '', |
|
115
|
|
|
city: '', |
|
116
|
|
|
country: '', |
|
117
|
|
|
identifier: self::VALID_SAMPLE_UUID, |
|
118
|
|
|
donationReceipt: true, |
|
119
|
|
|
isOptOutOnly: false, |
|
120
|
|
|
); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
private function newOptOutOnlyRequest(): ChangeAddressRequest { |
|
124
|
|
|
return ChangeAddressRequest::newPersonalChangeAddressRequest( |
|
125
|
|
|
salutation: '', |
|
126
|
|
|
title: '', |
|
127
|
|
|
firstName: '', |
|
128
|
|
|
lastName: '', |
|
129
|
|
|
address: '', |
|
130
|
|
|
postcode: '', |
|
131
|
|
|
city: '', |
|
132
|
|
|
country: '', |
|
133
|
|
|
identifier: self::VALID_SAMPLE_UUID, |
|
134
|
|
|
donationReceipt: true, |
|
135
|
|
|
isOptOutOnly: true, |
|
136
|
|
|
); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
private function createAddressChange(): AddressChange { |
|
140
|
|
|
return new AddressChange( |
|
141
|
|
|
AddressType::Person, |
|
142
|
|
|
AddressChange::EXTERNAL_ID_TYPE_DONATION, |
|
143
|
|
|
self::DUMMY_DONATION_ID, |
|
144
|
|
|
AddressChangeId::fromString( self::VALID_SAMPLE_UUID ) |
|
145
|
|
|
); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths