Completed
Pull Request — master (#923)
by Jeroen De
61:01
created
UseCases/SofortPaymentNotification/SofortPaymentNotificationUseCaseTest.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,6 @@
 block discarded – undo
15 15
 use WMDE\Fundraising\Frontend\DonationContext\Tests\Fixtures\FakeDonationRepository;
16 16
 use WMDE\Fundraising\Frontend\DonationContext\Tests\Fixtures\SucceedingDonationAuthorizer;
17 17
 use WMDE\Fundraising\Frontend\DonationContext\UseCases\SofortPaymentNotification\SofortPaymentNotificationUseCase;
18
-use WMDE\Fundraising\Frontend\PaymentContext\RequestModel\SofortNotificationRequest;
19 18
 use WMDE\Fundraising\Frontend\Tests\Fixtures\ThrowingEntityManager;
20 19
 
21 20
 /**
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace WMDE\Fundraising\Frontend\DonationContext\Tests\Integration\UseCases\SofortPaymentNotification;
6 6
 
@@ -25,23 +25,23 @@  discard block
 block discarded – undo
25 25
 
26 26
 	public function testWhenRepositoryThrowsException_errorResponseIsReturned(): void {
27 27
 		$useCase = new SofortPaymentNotificationUseCase(
28
-			new DoctrineDonationRepository( ThrowingEntityManager::newInstance( $this ) ),
28
+			new DoctrineDonationRepository(ThrowingEntityManager::newInstance($this)),
29 29
 			new SucceedingDonationAuthorizer(),
30 30
 			$this->getMailer()
31 31
 		);
32 32
 
33 33
 		$request = ValidSofortNotificationRequest::newInstantPayment();
34 34
 
35
-		$response = $useCase->handleNotification( $request );
36
-		$this->assertFalse( $response->notificationWasHandled() );
37
-		$this->assertTrue( $response->hasErrors() );
35
+		$response = $useCase->handleNotification($request);
36
+		$this->assertFalse($response->notificationWasHandled());
37
+		$this->assertTrue($response->hasErrors());
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * @return DonationConfirmationMailer|\PHPUnit_Framework_MockObject_MockObject
42 42
 	 */
43 43
 	private function getMailer(): DonationConfirmationMailer {
44
-		return $this->createMock( DonationConfirmationMailer::class );
44
+		return $this->createMock(DonationConfirmationMailer::class);
45 45
 	}
46 46
 
47 47
 	public function testWhenNotificationIsForNonExistingDonation_unhandledResponseIsReturned(): void {
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
 			$this->getMailer()
52 52
 		);
53 53
 
54
-		$request = ValidSofortNotificationRequest::newInstantPayment( 4711 );
54
+		$request = ValidSofortNotificationRequest::newInstantPayment(4711);
55 55
 
56
-		$this->assertFalse( $useCase->handleNotification( $request )->notificationWasHandled() );
56
+		$this->assertFalse($useCase->handleNotification($request)->notificationWasHandled());
57 57
 	}
58 58
 
59 59
 	public function testWhenAuthorizationFails_unhandledResponseIsReturned(): void {
60 60
 		$fakeRepository = new FakeDonationRepository();
61
-		$fakeRepository->storeDonation( ValidDonation::newIncompleteSofortDonation() );
61
+		$fakeRepository->storeDonation(ValidDonation::newIncompleteSofortDonation());
62 62
 
63 63
 		$useCase = new SofortPaymentNotificationUseCase(
64 64
 			$fakeRepository,
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
68 68
 
69 69
 		$request = ValidSofortNotificationRequest::newInstantPayment();
70 70
 
71
-		$this->assertFalse( $useCase->handleNotification( $request )->notificationWasHandled() );
71
+		$this->assertFalse($useCase->handleNotification($request)->notificationWasHandled());
72 72
 	}
73 73
 
74 74
 	public function testWhenAuthorizationSucceeds_successResponseIsReturned(): void {
75 75
 		$fakeRepository = new FakeDonationRepository();
76
-		$fakeRepository->storeDonation( ValidDonation::newIncompleteSofortDonation() );
76
+		$fakeRepository->storeDonation(ValidDonation::newIncompleteSofortDonation());
77 77
 
78 78
 		$useCase = new SofortPaymentNotificationUseCase(
79 79
 			$fakeRepository,
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 
84 84
 		$request = ValidSofortNotificationRequest::newInstantPayment();
85 85
 
86
-		$this->assertTrue( $useCase->handleNotification( $request )->notificationWasHandled() );
86
+		$this->assertTrue($useCase->handleNotification($request)->notificationWasHandled());
87 87
 	}
88 88
 
89 89
 	public function testWhenAuthorizationSucceeds_donationIsStored(): void {
90
-		$repositorySpy = new DonationRepositorySpy( ValidDonation::newIncompleteSofortDonation() );
90
+		$repositorySpy = new DonationRepositorySpy(ValidDonation::newIncompleteSofortDonation());
91 91
 
92 92
 		$useCase = new SofortPaymentNotificationUseCase(
93 93
 			$repositorySpy,
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
 
98 98
 		$request = ValidSofortNotificationRequest::newInstantPayment();
99 99
 
100
-		$this->assertTrue( $useCase->handleNotification( $request )->notificationWasHandled() );
101
-		$this->assertCount( 1, $repositorySpy->getStoreDonationCalls() );
100
+		$this->assertTrue($useCase->handleNotification($request)->notificationWasHandled());
101
+		$this->assertCount(1, $repositorySpy->getStoreDonationCalls());
102 102
 	}
103 103
 
104 104
 	public function testWhenAuthorizationSucceeds_donationIsStillPromised(): void {
105 105
 		$donation = ValidDonation::newIncompleteSofortDonation();
106
-		$repository = new FakeDonationRepository( $donation );
106
+		$repository = new FakeDonationRepository($donation);
107 107
 
108 108
 		$useCase = new SofortPaymentNotificationUseCase(
109 109
 			$repository,
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
 
114 114
 		$request = ValidSofortNotificationRequest::newInstantPayment();
115 115
 
116
-		$this->assertTrue( $useCase->handleNotification( $request )->notificationWasHandled() );
117
-		$this->assertSame( Donation::STATUS_PROMISE, $repository->getDonationById( $donation->getId() )->getStatus() );
116
+		$this->assertTrue($useCase->handleNotification($request)->notificationWasHandled());
117
+		$this->assertSame(Donation::STATUS_PROMISE, $repository->getDonationById($donation->getId())->getStatus());
118 118
 	}
119 119
 
120 120
 	public function testWhenPaymentTypeIsNonSofort_unhandledResponseIsReturned(): void {
121 121
 		$fakeRepository = new FakeDonationRepository();
122
-		$fakeRepository->storeDonation( ValidDonation::newDirectDebitDonation() );
122
+		$fakeRepository->storeDonation(ValidDonation::newDirectDebitDonation());
123 123
 
124 124
 		$useCase = new SofortPaymentNotificationUseCase(
125 125
 			$fakeRepository,
@@ -129,19 +129,19 @@  discard block
 block discarded – undo
129 129
 
130 130
 		$request = ValidSofortNotificationRequest::newInstantPayment();
131 131
 
132
-		$this->assertFalse( $useCase->handleNotification( $request )->notificationWasHandled() );
132
+		$this->assertFalse($useCase->handleNotification($request)->notificationWasHandled());
133 133
 	}
134 134
 
135 135
 	public function testWhenAuthorizationSucceeds_confirmationMailIsSent(): void {
136 136
 		$donation = ValidDonation::newIncompleteSofortDonation();
137 137
 		$fakeRepository = new FakeDonationRepository();
138
-		$fakeRepository->storeDonation( $donation );
138
+		$fakeRepository->storeDonation($donation);
139 139
 
140 140
 		$mailer = $this->getMailer();
141 141
 		$mailer
142
-			->expects( $this->once() )
143
-			->method( 'sendConfirmationMailFor' )
144
-			->with( $donation );
142
+			->expects($this->once())
143
+			->method('sendConfirmationMailFor')
144
+			->with($donation);
145 145
 
146 146
 		$useCase = new SofortPaymentNotificationUseCase(
147 147
 			$fakeRepository,
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
 			$mailer
150 150
 		);
151 151
 
152
-		$request = ValidSofortNotificationRequest::newInstantPayment( 1 );
153
-		$this->assertTrue( $useCase->handleNotification( $request )->notificationWasHandled() );
152
+		$request = ValidSofortNotificationRequest::newInstantPayment(1);
153
+		$this->assertTrue($useCase->handleNotification($request)->notificationWasHandled());
154 154
 
155 155
 	}
156 156
 
157 157
 	public function testWhenSendingConfirmationMailFails_handlerReturnsTrue(): void {
158 158
 		$fakeRepository = new FakeDonationRepository();
159
-		$fakeRepository->storeDonation( ValidDonation::newIncompleteSofortDonation() );
159
+		$fakeRepository->storeDonation(ValidDonation::newIncompleteSofortDonation());
160 160
 
161 161
 		$useCase = new SofortPaymentNotificationUseCase(
162 162
 			$fakeRepository,
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 
167 167
 		$request = ValidSofortNotificationRequest::newInstantPayment();
168 168
 
169
-		$this->assertTrue( $useCase->handleNotification( $request )->notificationWasHandled() );
169
+		$this->assertTrue($useCase->handleNotification($request)->notificationWasHandled());
170 170
 	}
171 171
 
172 172
 	/**
@@ -175,9 +175,9 @@  discard block
 block discarded – undo
175 175
 	private function newThrowingMailer() {
176 176
 		$mailer = $this->getMailer();
177 177
 
178
-		$mailer->expects( $this->once() )
179
-			->method( 'sendConfirmationMailFor' )
180
-			->willThrowException( new \RuntimeException( 'Oh noes!' ) );
178
+		$mailer->expects($this->once())
179
+			->method('sendConfirmationMailFor')
180
+			->willThrowException(new \RuntimeException('Oh noes!'));
181 181
 
182 182
 		return $mailer;
183 183
 	}
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	public function testGivenSetConfirmedAtForBookedDonation_unhandledResponseIsReturned(): void {
186 186
 
187 187
 		$fakeRepository = new FakeDonationRepository();
188
-		$fakeRepository->storeDonation( ValidDonation::newCompletedSofortDonation() );
188
+		$fakeRepository->storeDonation(ValidDonation::newCompletedSofortDonation());
189 189
 
190 190
 		$useCase = new SofortPaymentNotificationUseCase(
191 191
 			$fakeRepository,
@@ -195,10 +195,10 @@  discard block
 block discarded – undo
195 195
 
196 196
 		$request = ValidSofortNotificationRequest::newInstantPayment();
197 197
 
198
-		$response = $useCase->handleNotification( $request );
199
-		$this->assertFalse( $response->notificationWasHandled() );
200
-		$this->assertFalse( $response->hasErrors() );
201
-		$this->assertSame( 'Duplicate notification', $response->getContext()['message'] );
198
+		$response = $useCase->handleNotification($request);
199
+		$this->assertFalse($response->notificationWasHandled());
200
+		$this->assertFalse($response->hasErrors());
201
+		$this->assertSame('Duplicate notification', $response->getContext()['message']);
202 202
 	}
203 203
 
204 204
 }
Please login to merge, or discard this patch.
src/UseCases/SofortPaymentNotification/SofortPaymentNotificationUseCase.php 2 patches
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace WMDE\Fundraising\Frontend\DonationContext\UseCases\SofortPaymentNotification;
6 6
 
@@ -22,77 +22,77 @@  discard block
 block discarded – undo
22 22
 	private $authorizationService;
23 23
 	private $mailer;
24 24
 
25
-	public function __construct( DonationRepository $repository, DonationAuthorizer $authorizationService,
26
-								 DonationConfirmationMailer $mailer ) {
25
+	public function __construct(DonationRepository $repository, DonationAuthorizer $authorizationService,
26
+								 DonationConfirmationMailer $mailer) {
27 27
 		$this->repository = $repository;
28 28
 		$this->authorizationService = $authorizationService;
29 29
 		$this->mailer = $mailer;
30 30
 	}
31 31
 
32
-	public function handleNotification( SofortNotificationRequest $request ): SofortNotificationResponse {
32
+	public function handleNotification(SofortNotificationRequest $request): SofortNotificationResponse {
33 33
 		try {
34
-			$donation = $this->repository->getDonationById( $request->getDonationId() );
35
-		} catch ( GetDonationException $ex ) {
36
-			return $this->createFailureResponse( $ex );
34
+			$donation = $this->repository->getDonationById($request->getDonationId());
35
+		} catch (GetDonationException $ex) {
36
+			return $this->createFailureResponse($ex);
37 37
 		}
38 38
 
39
-		if ( $donation === null ) {
40
-			return $this->createFailureResponse( new RuntimeException( 'Donation not found' ) );
39
+		if ($donation === null) {
40
+			return $this->createFailureResponse(new RuntimeException('Donation not found'));
41 41
 		}
42 42
 
43
-		return $this->handleRequestForDonation( $request, $donation );
43
+		return $this->handleRequestForDonation($request, $donation);
44 44
 	}
45 45
 
46
-	private function handleRequestForDonation( SofortNotificationRequest $request, Donation $donation ): SofortNotificationResponse {
46
+	private function handleRequestForDonation(SofortNotificationRequest $request, Donation $donation): SofortNotificationResponse {
47 47
 		$paymentMethod = $donation->getPayment()->getPaymentMethod();
48 48
 
49
-		if ( !( $paymentMethod instanceof SofortPayment ) ) {
50
-			return $this->createUnhandledResponse( 'Trying to handle notification for non-sofort donation' );
49
+		if (!($paymentMethod instanceof SofortPayment)) {
50
+			return $this->createUnhandledResponse('Trying to handle notification for non-sofort donation');
51 51
 		}
52 52
 
53
-		if ( !$this->authorizationService->systemCanModifyDonation( $donation->getId() ) ) {
54
-			return $this->createUnhandledResponse( 'Wrong access code for donation' );
53
+		if (!$this->authorizationService->systemCanModifyDonation($donation->getId())) {
54
+			return $this->createUnhandledResponse('Wrong access code for donation');
55 55
 		}
56 56
 
57
-		if ( $paymentMethod->isConfirmedPayment() ) {
58
-			return $this->createUnhandledResponse( 'Duplicate notification' );
57
+		if ($paymentMethod->isConfirmedPayment()) {
58
+			return $this->createUnhandledResponse('Duplicate notification');
59 59
 		}
60 60
 
61
-		$paymentMethod->setConfirmedAt( $request->getTime() );
61
+		$paymentMethod->setConfirmedAt($request->getTime());
62 62
 
63 63
 		try {
64
-			$this->repository->storeDonation( $donation );
64
+			$this->repository->storeDonation($donation);
65 65
 		}
66
-		catch ( StoreDonationException $ex ) {
67
-			return $this->createFailureResponse( $ex );
66
+		catch (StoreDonationException $ex) {
67
+			return $this->createFailureResponse($ex);
68 68
 		}
69 69
 
70
-		$this->sendConfirmationEmailFor( $donation );
70
+		$this->sendConfirmationEmailFor($donation);
71 71
 
72 72
 		return SofortNotificationResponse::newSuccessResponse();
73 73
 	}
74 74
 
75
-	private function createUnhandledResponse( string $reason ): SofortNotificationResponse {
76
-		return SofortNotificationResponse::newUnhandledResponse( [
75
+	private function createUnhandledResponse(string $reason): SofortNotificationResponse {
76
+		return SofortNotificationResponse::newUnhandledResponse([
77 77
 			'message' => $reason
78
-		] );
78
+		]);
79 79
 	}
80 80
 
81
-	private function sendConfirmationEmailFor( Donation $donation ): void {
82
-		if ( $donation->getDonor() !== null ) {
81
+	private function sendConfirmationEmailFor(Donation $donation): void {
82
+		if ($donation->getDonor() !== null) {
83 83
 			try {
84
-				$this->mailer->sendConfirmationMailFor( $donation );
85
-			} catch ( RuntimeException $ex ) {
84
+				$this->mailer->sendConfirmationMailFor($donation);
85
+			} catch (RuntimeException $ex) {
86 86
 				// no need to re-throw or return false, this is not a fatal error, only a minor inconvenience
87 87
 			}
88 88
 		}
89 89
 	}
90 90
 
91
-	private function createFailureResponse( RuntimeException $ex ): SofortNotificationResponse {
92
-		return SofortNotificationResponse::newFailureResponse( [
91
+	private function createFailureResponse(RuntimeException $ex): SofortNotificationResponse {
92
+		return SofortNotificationResponse::newFailureResponse([
93 93
 			'message' => $ex->getMessage(),
94 94
 			'stackTrace' => $ex->getTraceAsString()
95
-		] );
95
+		]);
96 96
 	}
97 97
 
98 98
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,8 +62,7 @@
 block discarded – undo
62 62
 
63 63
 		try {
64 64
 			$this->repository->storeDonation( $donation );
65
-		}
66
-		catch ( StoreDonationException $ex ) {
65
+		} catch ( StoreDonationException $ex ) {
67 66
 			return $this->createFailureResponse( $ex );
68 67
 		}
69 68
 
Please login to merge, or discard this patch.
contexts/PaymentContext/src/RequestModel/SofortNotificationRequest.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace WMDE\Fundraising\Frontend\PaymentContext\RequestModel;
6 6
 
@@ -21,20 +21,20 @@  discard block
 block discarded – undo
21 21
 	 */
22 22
 	private $time;
23 23
 
24
-	public function getDonationId(): ?int {
24
+	public function getDonationId(): ? int {
25 25
 		return $this->donationId;
26 26
 	}
27 27
 
28
-	public function setDonationId( int $donationId ): self {
28
+	public function setDonationId(int $donationId): self {
29 29
 		$this->donationId = $donationId;
30 30
 		return $this;
31 31
 	}
32 32
 
33
-	public function getTransactionId(): ?string {
33
+	public function getTransactionId(): ? string {
34 34
 		return $this->transactionId;
35 35
 	}
36 36
 
37
-	public function setTransactionId( string $transactionId ): self {
37
+	public function setTransactionId(string $transactionId): self {
38 38
 		$this->transactionId = $transactionId;
39 39
 		return $this;
40 40
 	}
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 		return $this->time;
44 44
 	}
45 45
 
46
-	public function setTime( DateTime $time ): self {
46
+	public function setTime(DateTime $time): self {
47 47
 		$this->time = $time;
48 48
 		return $this;
49 49
 	}
Please login to merge, or discard this patch.
app/RouteHandlers/SofortNotificationHandler.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace WMDE\Fundraising\Frontend\App\RouteHandlers;
6 6
 
@@ -22,61 +22,61 @@  discard block
 block discarded – undo
22 22
 	 */
23 23
 	private $request;
24 24
 
25
-	public function __construct( FunFunFactory $ffFactory ) {
25
+	public function __construct(FunFunFactory $ffFactory) {
26 26
 		$this->ffFactory = $ffFactory;
27 27
 	}
28 28
 
29
-	public function handle( Request $request ): Response {
29
+	public function handle(Request $request): Response {
30 30
 		$this->request = $request;
31 31
 
32 32
 		$useCaseRequest = $this->newUseCaseRequest();
33 33
 
34
-		if ( $useCaseRequest === null ) {
35
-			$this->logWebRequest( [ 'message' => 'Bad notification time' ], LogLevel::ERROR );
36
-			return new Response( 'Bad request', Response::HTTP_BAD_REQUEST );
34
+		if ($useCaseRequest === null) {
35
+			$this->logWebRequest(['message' => 'Bad notification time'], LogLevel::ERROR);
36
+			return new Response('Bad request', Response::HTTP_BAD_REQUEST);
37 37
 		}
38 38
 
39
-		$response = $this->newUseCase()->handleNotification( $useCaseRequest );
39
+		$response = $this->newUseCase()->handleNotification($useCaseRequest);
40 40
 
41
-		$this->logResponseIfNeeded( $response );
41
+		$this->logResponseIfNeeded($response);
42 42
 
43
-		if ( $response->hasErrors() ) {
44
-			return new Response( 'Error', Response::HTTP_INTERNAL_SERVER_ERROR );
43
+		if ($response->hasErrors()) {
44
+			return new Response('Error', Response::HTTP_INTERNAL_SERVER_ERROR);
45 45
 		}
46 46
 
47
-		if ( $response->notificationWasHandled() ) {
48
-			return new Response( 'Ok', Response::HTTP_OK );
47
+		if ($response->notificationWasHandled()) {
48
+			return new Response('Ok', Response::HTTP_OK);
49 49
 		}
50 50
 
51
-		return new Response( 'Bad request', Response::HTTP_BAD_REQUEST );
51
+		return new Response('Bad request', Response::HTTP_BAD_REQUEST);
52 52
 	}
53 53
 
54 54
 	private function newUseCase(): SofortPaymentNotificationUseCase {
55
-		return $this->ffFactory->newHandleSofortPaymentNotificationUseCase( $this->request->query->get( 'updateToken' ) );
55
+		return $this->ffFactory->newHandleSofortPaymentNotificationUseCase($this->request->query->get('updateToken'));
56 56
 	}
57 57
 
58
-	private function newUseCaseRequest(): ?SofortNotificationRequest {
58
+	private function newUseCaseRequest(): ? SofortNotificationRequest {
59 59
 		$time = $this->getTimeFromRequest();
60 60
 
61
-		if ( $time === false ) {
61
+		if ($time === false) {
62 62
 			return null;
63 63
 		}
64 64
 
65 65
 		$useCaseRequest = new SofortNotificationRequest();
66 66
 
67
-		$useCaseRequest->setTime( $time );
68
-		$useCaseRequest->setDonationId( $this->request->query->getInt( 'id' ) );
69
-		$useCaseRequest->setTransactionId( $this->request->request->get( 'transaction', '' ) );
67
+		$useCaseRequest->setTime($time);
68
+		$useCaseRequest->setDonationId($this->request->query->getInt('id'));
69
+		$useCaseRequest->setTransactionId($this->request->request->get('transaction', ''));
70 70
 
71 71
 		return $useCaseRequest;
72 72
 	}
73 73
 
74 74
 	private function getTimeFromRequest() {
75
-		return DateTime::createFromFormat( DateTime::ATOM, $this->request->request->get( 'time', '' ) );
75
+		return DateTime::createFromFormat(DateTime::ATOM, $this->request->request->get('time', ''));
76 76
 	}
77 77
 
78
-	private function logResponseIfNeeded( SofortNotificationResponse $response ) {
79
-		if ( $response->notificationWasHandled() ) {
78
+	private function logResponseIfNeeded(SofortNotificationResponse $response) {
79
+		if ($response->notificationWasHandled()) {
80 80
 			return;
81 81
 		}
82 82
 
@@ -86,13 +86,13 @@  discard block
 block discarded – undo
86 86
 		);
87 87
 	}
88 88
 
89
-	private function logWebRequest( array $context, string $logLevel ) {
89
+	private function logWebRequest(array $context, string $logLevel) {
90 90
 		$message = $context['message'] ?? 'Sofort request not handled';
91
-		unset( $context['message'] );
91
+		unset($context['message']);
92 92
 
93 93
 		$context['post_vars'] = $this->request->request->all();
94 94
 		$context['query_vars'] = $this->request->query->all();
95
-		$this->ffFactory->getSofortLogger()->log( $logLevel, $message, $context );
95
+		$this->ffFactory->getSofortLogger()->log($logLevel, $message, $context);
96 96
 	}
97 97
 
98 98
 }
Please login to merge, or discard this patch.
tests/EdgeToEdge/Routes/SofortPaymentNotificationRouteTest.php 1 patch
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace WMDE\Fundraising\Frontend\Tests\EdgeToEdge\Routes;
6 6
 
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
 	private const VALID_TRANSACTION_TIME = '2010-04-14T19:01:08+02:00';
25 25
 
26 26
 	public function testGivenWrongPaymentType_applicationRefuses(): void {
27
-		$this->newEnvironment( function ( Client $client, FunFunFactory $factory ) {
27
+		$this->newEnvironment(function(Client $client, FunFunFactory $factory) {
28 28
 			$donation = ValidDonation::newIncompletePayPalDonation();
29
-			$factory->getDonationRepository()->storeDonation( $donation );
29
+			$factory->getDonationRepository()->storeDonation($donation);
30 30
 
31 31
 			$client->request(
32 32
 				Request::METHOD_POST,
@@ -37,33 +37,33 @@  discard block
 block discarded – undo
37 37
 				]
38 38
 			);
39 39
 
40
-			$this->assertIsBadRequestResponse( $client->getResponse() );
40
+			$this->assertIsBadRequestResponse($client->getResponse());
41 41
 		} );
42 42
 	}
43 43
 
44
-	private function newEnvironment( callable $onEnvironmentCreated ): void {
44
+	private function newEnvironment(callable $onEnvironmentCreated): void {
45 45
 		$this->createEnvironment(
46 46
 			[],
47
-			function ( Client $client, FunFunFactory $factory ) use ( $onEnvironmentCreated ) {
48
-				$factory->setTokenGenerator( new FixedTokenGenerator(
47
+			function(Client $client, FunFunFactory $factory) use ($onEnvironmentCreated) {
48
+				$factory->setTokenGenerator(new FixedTokenGenerator(
49 49
 					self::VALID_TOKEN,
50
-					new DateTime( '2039-12-31 23:59:59Z' )
51
-				) );
50
+					new DateTime('2039-12-31 23:59:59Z')
51
+				));
52 52
 
53
-				$onEnvironmentCreated( $client, $factory );
53
+				$onEnvironmentCreated($client, $factory);
54 54
 			}
55 55
 		);
56 56
 	}
57 57
 
58
-	private function assertIsBadRequestResponse( Response $response ): void {
59
-		$this->assertSame( 'Bad request', $response->getContent() );
60
-		$this->assertSame( Response::HTTP_BAD_REQUEST, $response->getStatusCode() );
58
+	private function assertIsBadRequestResponse(Response $response): void {
59
+		$this->assertSame('Bad request', $response->getContent());
60
+		$this->assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
61 61
 	}
62 62
 
63 63
 	public function testGivenWrongToken_applicationRefuses(): void {
64
-		$this->newEnvironment( function ( Client $client, FunFunFactory $factory ) {
64
+		$this->newEnvironment(function(Client $client, FunFunFactory $factory) {
65 65
 			$donation = ValidDonation::newIncompleteSofortDonation();
66
-			$factory->getDonationRepository()->storeDonation( $donation );
66
+			$factory->getDonationRepository()->storeDonation($donation);
67 67
 
68 68
 			$client->request(
69 69
 				Request::METHOD_POST,
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 				]
75 75
 			);
76 76
 
77
-			$this->assertIsBadRequestResponse( $client->getResponse() );
77
+			$this->assertIsBadRequestResponse($client->getResponse());
78 78
 		} );
79 79
 	}
80 80
 
81 81
 	public function testGivenBadTimeFormat_applicationRefuses(): void {
82
-		$this->newEnvironment( function ( Client $client, FunFunFactory $factory ) {
82
+		$this->newEnvironment(function(Client $client, FunFunFactory $factory) {
83 83
 			$donation = ValidDonation::newIncompleteSofortDonation();
84
-			$factory->getDonationRepository()->storeDonation( $donation );
84
+			$factory->getDonationRepository()->storeDonation($donation);
85 85
 
86 86
 			$client->request(
87 87
 				Request::METHOD_POST,
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 				]
93 93
 			);
94 94
 
95
-			$this->assertIsBadRequestResponse( $client->getResponse() );
95
+			$this->assertIsBadRequestResponse($client->getResponse());
96 96
 		} );
97 97
 	}
98 98
 
99 99
 	public function testGivenValidRequest_applicationIndicatesSuccess(): void {
100
-		$this->newEnvironment( function ( Client $client, FunFunFactory $factory ) {
100
+		$this->newEnvironment(function(Client $client, FunFunFactory $factory) {
101 101
 			$donation = ValidDonation::newIncompleteSofortDonation();
102
-			$factory->getDonationRepository()->storeDonation( $donation );
102
+			$factory->getDonationRepository()->storeDonation($donation);
103 103
 
104 104
 			$client->request(
105 105
 				Request::METHOD_POST,
@@ -110,22 +110,22 @@  discard block
 block discarded – undo
110 110
 				]
111 111
 			);
112 112
 
113
-			$this->assertSame( 'Ok', $client->getResponse()->getContent() );
114
-			$this->assertSame( Response::HTTP_OK, $client->getResponse()->getStatusCode() );
113
+			$this->assertSame('Ok', $client->getResponse()->getContent());
114
+			$this->assertSame(Response::HTTP_OK, $client->getResponse()->getStatusCode());
115 115
 
116
-			$donation = $factory->getDonationRepository()->getDonationById( $donation->getId() );
116
+			$donation = $factory->getDonationRepository()->getDonationById($donation->getId());
117 117
 
118
-			$this->assertEquals( new DateTime( self::VALID_TRANSACTION_TIME ), $donation->getPaymentMethod()->getConfirmedAt() );
118
+			$this->assertEquals(new DateTime(self::VALID_TRANSACTION_TIME), $donation->getPaymentMethod()->getConfirmedAt());
119 119
 		} );
120 120
 	}
121 121
 
122 122
 	public function testGivenAlreadyConfirmedPayment_requestDataIsLogged(): void {
123
-		$this->newEnvironment( function ( Client $client, FunFunFactory $factory ) {
123
+		$this->newEnvironment(function(Client $client, FunFunFactory $factory) {
124 124
 			$logger = new LoggerSpy();
125
-			$factory->setSofortLogger( $logger );
125
+			$factory->setSofortLogger($logger);
126 126
 
127 127
 			$donation = ValidDonation::newCompletedSofortDonation();
128
-			$factory->getDonationRepository()->storeDonation( $donation );
128
+			$factory->getDonationRepository()->storeDonation($donation);
129 129
 
130 130
 			$client->request(
131 131
 				Request::METHOD_POST,
@@ -136,21 +136,21 @@  discard block
 block discarded – undo
136 136
 				]
137 137
 			);
138 138
 
139
-			$this->assertIsBadRequestResponse( $client->getResponse() );
140
-			$this->assertErrorCauseIsLogged( $logger, 'Duplicate notification' );
141
-			$this->assertRequestVarsAreLogged( $logger );
142
-			$this->assertLogLevel( $logger, LogLevel::INFO );
139
+			$this->assertIsBadRequestResponse($client->getResponse());
140
+			$this->assertErrorCauseIsLogged($logger, 'Duplicate notification');
141
+			$this->assertRequestVarsAreLogged($logger);
142
+			$this->assertLogLevel($logger, LogLevel::INFO);
143 143
 		} );
144 144
 	}
145 145
 
146
-	private function assertErrorCauseIsLogged( LoggerSpy $logger, string $expectedMessage ): void {
146
+	private function assertErrorCauseIsLogged(LoggerSpy $logger, string $expectedMessage): void {
147 147
 		$this->assertSame(
148
-			[ $expectedMessage ],
148
+			[$expectedMessage],
149 149
 			$logger->getLogCalls()->getMessages()
150 150
 		);
151 151
 	}
152 152
 
153
-	private function assertRequestVarsAreLogged( LoggerSpy $logger ): void {
153
+	private function assertRequestVarsAreLogged(LoggerSpy $logger): void {
154 154
 		$this->assertSame(
155 155
 			self::VALID_TRANSACTION_ID,
156 156
 			$logger->getLogCalls()->getFirstCall()->getContext()['post_vars']['transaction']
@@ -162,46 +162,46 @@  discard block
 block discarded – undo
162 162
 		);
163 163
 	}
164 164
 
165
-	private function assertLogLevel( LoggerSpy $logger, string $expectedLevel ): void {
166
-		$this->assertSame( $expectedLevel, $logger->getLogCalls()->getFirstCall()->getLevel() );
165
+	private function assertLogLevel(LoggerSpy $logger, string $expectedLevel): void {
166
+		$this->assertSame($expectedLevel, $logger->getLogCalls()->getFirstCall()->getLevel());
167 167
 	}
168 168
 
169 169
 	public function testGivenUnknownDonation_requestDataIsLogged(): void {
170
-		$this->newEnvironment( function ( Client $client, FunFunFactory $factory ) {
170
+		$this->newEnvironment(function(Client $client, FunFunFactory $factory) {
171 171
 			$logger = new LoggerSpy();
172
-			$factory->setSofortLogger( $logger );
172
+			$factory->setSofortLogger($logger);
173 173
 
174 174
 			$donation = ValidDonation::newCompletedSofortDonation();
175
-			$factory->getDonationRepository()->storeDonation( $donation );
175
+			$factory->getDonationRepository()->storeDonation($donation);
176 176
 
177 177
 			$client->request(
178 178
 				Request::METHOD_POST,
179
-				'/sofort-payment-notification?id=' . ( $donation->getId() + 1 ) . '&updateToken=' . self::VALID_TOKEN,
179
+				'/sofort-payment-notification?id=' . ($donation->getId() + 1) . '&updateToken=' . self::VALID_TOKEN,
180 180
 				[
181 181
 					'transaction' => self::VALID_TRANSACTION_ID,
182 182
 					'time' => self::VALID_TRANSACTION_TIME
183 183
 				]
184 184
 			);
185 185
 
186
-			$this->assertIsErrorResponse( $client->getResponse() );
187
-			$this->assertErrorCauseIsLogged( $logger, 'Donation not found' );
188
-			$this->assertRequestVarsAreLogged( $logger );
189
-			$this->assertLogLevel( $logger, LogLevel::ERROR );
186
+			$this->assertIsErrorResponse($client->getResponse());
187
+			$this->assertErrorCauseIsLogged($logger, 'Donation not found');
188
+			$this->assertRequestVarsAreLogged($logger);
189
+			$this->assertLogLevel($logger, LogLevel::ERROR);
190 190
 		} );
191 191
 	}
192 192
 
193
-	private function assertIsErrorResponse( Response $response ): void {
194
-		$this->assertSame( 'Error', $response->getContent() );
195
-		$this->assertSame( Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode() );
193
+	private function assertIsErrorResponse(Response $response): void {
194
+		$this->assertSame('Error', $response->getContent());
195
+		$this->assertSame(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode());
196 196
 	}
197 197
 
198 198
 	public function testGivenBadTime_requestDataIsLogged(): void {
199
-		$this->newEnvironment( function ( Client $client, FunFunFactory $factory ) {
199
+		$this->newEnvironment(function(Client $client, FunFunFactory $factory) {
200 200
 			$logger = new LoggerSpy();
201
-			$factory->setSofortLogger( $logger );
201
+			$factory->setSofortLogger($logger);
202 202
 
203 203
 			$donation = ValidDonation::newCompletedSofortDonation();
204
-			$factory->getDonationRepository()->storeDonation( $donation );
204
+			$factory->getDonationRepository()->storeDonation($donation);
205 205
 
206 206
 			$client->request(
207 207
 				Request::METHOD_POST,
@@ -212,10 +212,10 @@  discard block
 block discarded – undo
212 212
 				]
213 213
 			);
214 214
 
215
-			$this->assertIsBadRequestResponse( $client->getResponse() );
216
-			$this->assertErrorCauseIsLogged( $logger, 'Bad notification time' );
217
-			$this->assertRequestVarsAreLogged( $logger );
218
-			$this->assertLogLevel( $logger, LogLevel::ERROR );
215
+			$this->assertIsBadRequestResponse($client->getResponse());
216
+			$this->assertErrorCauseIsLogged($logger, 'Bad notification time');
217
+			$this->assertRequestVarsAreLogged($logger);
218
+			$this->assertLogLevel($logger, LogLevel::ERROR);
219 219
 		} );
220 220
 	}
221 221
 
Please login to merge, or discard this patch.