|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\MembershipContext\Tests\Integration\UseCases\HandleSubscriptionPaymentNotification; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Log\NullLogger; |
|
8
|
|
|
use WMDE\Fundraising\Frontend\Infrastructure\TemplateBasedMailer; |
|
9
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationRepository; |
|
10
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Fixtures\FailingAuthorizer; |
|
11
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Fixtures\FakeApplicationRepository; |
|
12
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Fixtures\SucceedingAuthorizer; |
|
13
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\HandleSubscriptionSignupNotification\HandleSubscriptionSignupNotificationUseCase; |
|
14
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Data\ValidMembershipApplication; |
|
15
|
|
|
use WMDE\Fundraising\Frontend\PaymentContext\Tests\Data\ValidSubscriptionSignupRequest; |
|
16
|
|
|
use WMDE\Fundraising\Frontend\Tests\Fixtures\TemplateBasedMailerSpy; |
|
17
|
|
|
use WMDE\Fundraising\Frontend\Tests\Fixtures\ThrowingEntityManager; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @covers WMDE\Fundraising\Frontend\MembershipContext\UseCases\HandleSubscriptionSignupNotification\HandleSubscriptionSignupNotificationUseCase |
|
21
|
|
|
* |
|
22
|
|
|
* @licence GNU GPL v2+ |
|
23
|
|
|
* @author Kai Nissen < [email protected] > |
|
24
|
|
|
*/ |
|
25
|
|
|
class HandleSubscriptionSignupNotificationUseCaseTest extends \PHPUnit\Framework\TestCase { |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var TemplateBasedMailerSpy |
|
29
|
|
|
*/ |
|
30
|
|
|
private $mailerSpy; |
|
31
|
|
|
|
|
32
|
|
|
public function setUp() { |
|
33
|
|
|
$this->mailerSpy = new TemplateBasedMailerSpy( $this ); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testWhenPaymentMethodIsNotPayPal_requestIsNotHandled() { |
|
37
|
|
|
$fakeRepository = new FakeApplicationRepository(); |
|
38
|
|
|
$fakeRepository->storeApplication( ValidMembershipApplication::newDomainEntity() ); |
|
39
|
|
|
|
|
40
|
|
|
$useCase = new HandleSubscriptionSignupNotificationUseCase( |
|
41
|
|
|
$fakeRepository, |
|
42
|
|
|
new SucceedingAuthorizer(), |
|
43
|
|
|
$this->getMailer(), |
|
|
|
|
|
|
44
|
|
|
new NullLogger() |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$request = ValidSubscriptionSignupRequest::newValidRequest(); |
|
48
|
|
|
$response = $useCase->handleNotification( $request ); |
|
49
|
|
|
$this->assertFalse( $response->notificationWasHandled() ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testWhenMembershipApplicationDoesNotExist_requestIsNotHandled() { |
|
53
|
|
|
$fakeRepository = new FakeApplicationRepository(); |
|
54
|
|
|
$fakeRepository->storeApplication( ValidMembershipApplication::newDomainEntity() ); |
|
55
|
|
|
|
|
56
|
|
|
$useCase = new HandleSubscriptionSignupNotificationUseCase( |
|
57
|
|
|
$fakeRepository, |
|
58
|
|
|
new SucceedingAuthorizer(), |
|
59
|
|
|
$this->getMailer(), |
|
|
|
|
|
|
60
|
|
|
new NullLogger() |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
$request = ValidSubscriptionSignupRequest::newValidRequest(); |
|
64
|
|
|
$request->setApplicationId( 667 ); |
|
65
|
|
|
$response = $useCase->handleNotification( $request ); |
|
66
|
|
|
$this->assertFalse( $response->notificationWasHandled() ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testWhenRepositoryThrowsException_responseContainsErrors() { |
|
70
|
|
|
$useCase = new HandleSubscriptionSignupNotificationUseCase( |
|
71
|
|
|
new DoctrineApplicationRepository( ThrowingEntityManager::newInstance( $this ) ), |
|
72
|
|
|
new SucceedingAuthorizer(), |
|
73
|
|
|
$this->getMailer(), |
|
|
|
|
|
|
74
|
|
|
new NullLogger() |
|
75
|
|
|
); |
|
76
|
|
|
$request = ValidSubscriptionSignupRequest::newValidRequest(); |
|
77
|
|
|
$response = $useCase->handleNotification( $request ); |
|
78
|
|
|
$this->assertFalse( $response->notificationWasHandled() ); |
|
79
|
|
|
$this->assertTrue( $response->hasErrors() ); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testWhenAuthorizationFails_requestIsNotHandled() { |
|
83
|
|
|
$fakeRepository = new FakeApplicationRepository(); |
|
84
|
|
|
$fakeRepository->storeApplication( ValidMembershipApplication::newDomainEntityUsingPayPal() ); |
|
85
|
|
|
|
|
86
|
|
|
$useCase = new HandleSubscriptionSignupNotificationUseCase( |
|
87
|
|
|
$fakeRepository, |
|
88
|
|
|
new FailingAuthorizer(), |
|
89
|
|
|
$this->getMailer(), |
|
|
|
|
|
|
90
|
|
|
new NullLogger() |
|
91
|
|
|
); |
|
92
|
|
|
|
|
93
|
|
|
$request = ValidSubscriptionSignupRequest::newValidRequest(); |
|
94
|
|
|
$response = $useCase->handleNotification( $request ); |
|
95
|
|
|
$this->assertFalse( $response->notificationWasHandled() ); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function testWhenStatusIsNotAllowedForConfirming_requestIsNotHandled() { |
|
99
|
|
|
$fakeRepository = new FakeApplicationRepository(); |
|
100
|
|
|
|
|
101
|
|
|
$application = ValidMembershipApplication::newDomainEntityUsingPayPal(); |
|
102
|
|
|
$application->confirm(); |
|
103
|
|
|
$fakeRepository->storeApplication( $application ); |
|
104
|
|
|
|
|
105
|
|
|
$useCase = new HandleSubscriptionSignupNotificationUseCase( |
|
106
|
|
|
$fakeRepository, |
|
107
|
|
|
new SucceedingAuthorizer(), |
|
108
|
|
|
$this->getMailer(), |
|
|
|
|
|
|
109
|
|
|
new NullLogger() |
|
110
|
|
|
); |
|
111
|
|
|
|
|
112
|
|
|
$request = ValidSubscriptionSignupRequest::newValidRequest(); |
|
113
|
|
|
$response = $useCase->handleNotification( $request ); |
|
114
|
|
|
$this->assertFalse( $response->notificationWasHandled() ); |
|
115
|
|
|
$this->assertTrue( $response->hasErrors() ); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function testWhenValidRequestIsSent_itIsHandled() { |
|
119
|
|
|
$fakeRepository = new FakeApplicationRepository(); |
|
120
|
|
|
|
|
121
|
|
|
$application = ValidMembershipApplication::newDomainEntityUsingPayPal(); |
|
122
|
|
|
$fakeRepository->storeApplication( $application ); |
|
123
|
|
|
|
|
124
|
|
|
$useCase = new HandleSubscriptionSignupNotificationUseCase( |
|
125
|
|
|
$fakeRepository, |
|
126
|
|
|
new SucceedingAuthorizer(), |
|
127
|
|
|
$this->getMailer(), |
|
|
|
|
|
|
128
|
|
|
new NullLogger() |
|
129
|
|
|
); |
|
130
|
|
|
|
|
131
|
|
|
$request = ValidSubscriptionSignupRequest::newValidRequest(); |
|
132
|
|
|
$response = $useCase->handleNotification( $request ); |
|
133
|
|
|
$this->assertTrue( $response->notificationWasHandled() ); |
|
134
|
|
|
$this->assertFalse( $response->hasErrors() ); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function testWhenApplicationIsConfirmed_mailIsSent() { |
|
138
|
|
|
$fakeRepository = new FakeApplicationRepository(); |
|
139
|
|
|
|
|
140
|
|
|
$application = ValidMembershipApplication::newDomainEntityUsingPayPal(); |
|
141
|
|
|
$fakeRepository->storeApplication( $application ); |
|
142
|
|
|
|
|
143
|
|
|
$useCase = new HandleSubscriptionSignupNotificationUseCase( |
|
144
|
|
|
$fakeRepository, |
|
145
|
|
|
new SucceedingAuthorizer(), |
|
146
|
|
|
$this->mailerSpy, |
|
147
|
|
|
new NullLogger() |
|
148
|
|
|
); |
|
149
|
|
|
|
|
150
|
|
|
$request = ValidSubscriptionSignupRequest::newValidRequest(); |
|
151
|
|
|
$useCase->handleNotification( $request ); |
|
152
|
|
|
$this->mailerSpy->assertCalledOnce(); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @return TemplateBasedMailer|\PHPUnit_Framework_MockObject_MockObject |
|
157
|
|
|
*/ |
|
158
|
|
|
private function getMailer(): TemplateBasedMailer { |
|
159
|
|
|
return $this->getMockBuilder( TemplateBasedMailer::class )->disableOriginalConstructor()->getMock(); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
} |
|
163
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.