@@ -1,6 +1,6 @@ discard block |
||
| 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\Unit\Infrastructure; |
| 6 | 6 | |
@@ -27,20 +27,20 @@ discard block |
||
| 27 | 27 | new LoggerSpy() |
| 28 | 28 | ); |
| 29 | 29 | |
| 30 | - $this->expectException( GetDonationException::class ); |
|
| 31 | - $loggingRepo->getDonationById( 1337 ); |
|
| 30 | + $this->expectException(GetDonationException::class); |
|
| 31 | + $loggingRepo->getDonationById(1337); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | private function newThrowingRepository(): DonationRepository { |
| 35 | - $repository = $this->createMock( DonationRepository::class ); |
|
| 35 | + $repository = $this->createMock(DonationRepository::class); |
|
| 36 | 36 | |
| 37 | - $repository->expects( $this->any() ) |
|
| 38 | - ->method( 'getDonationById' ) |
|
| 39 | - ->willThrowException( new GetDonationException() ); |
|
| 37 | + $repository->expects($this->any()) |
|
| 38 | + ->method('getDonationById') |
|
| 39 | + ->willThrowException(new GetDonationException()); |
|
| 40 | 40 | |
| 41 | - $repository->expects( $this->any() ) |
|
| 42 | - ->method( 'storeDonation' ) |
|
| 43 | - ->willThrowException( new StoreDonationException() ); |
|
| 41 | + $repository->expects($this->any()) |
|
| 42 | + ->method('storeDonation') |
|
| 43 | + ->willThrowException(new StoreDonationException()); |
|
| 44 | 44 | |
| 45 | 45 | return $repository; |
| 46 | 46 | } |
@@ -54,35 +54,35 @@ discard block |
||
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | 56 | try { |
| 57 | - $loggingRepo->getDonationById( 1337 ); |
|
| 57 | + $loggingRepo->getDonationById(1337); |
|
| 58 | 58 | } |
| 59 | - catch ( GetDonationException $ex ) { |
|
| 59 | + catch (GetDonationException $ex) { |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $this->assertExceptionLoggedAsCritical( GetDonationException::class, $logger ); |
|
| 62 | + $this->assertExceptionLoggedAsCritical(GetDonationException::class, $logger); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - private function assertExceptionLoggedAsCritical( string $expectedExceptionType, LoggerSpy $logger ) { |
|
| 66 | - $this->assertCount( 1, $logger->getLogCalls(), 'There should be exactly one log call' ); |
|
| 65 | + private function assertExceptionLoggedAsCritical(string $expectedExceptionType, LoggerSpy $logger) { |
|
| 66 | + $this->assertCount(1, $logger->getLogCalls(), 'There should be exactly one log call'); |
|
| 67 | 67 | |
| 68 | 68 | $logCall = $logger->getLogCalls()->getFirstCall(); |
| 69 | 69 | |
| 70 | - $this->assertSame( LogLevel::CRITICAL, $logCall->getLevel() ); |
|
| 71 | - $this->assertArrayHasKey( 'exception', $logCall->getContext(), 'the log context should contain an exception element' ); |
|
| 72 | - $this->assertInstanceOf( $expectedExceptionType, $logCall->getContext()['exception'] ); |
|
| 70 | + $this->assertSame(LogLevel::CRITICAL, $logCall->getLevel()); |
|
| 71 | + $this->assertArrayHasKey('exception', $logCall->getContext(), 'the log context should contain an exception element'); |
|
| 72 | + $this->assertInstanceOf($expectedExceptionType, $logCall->getContext()['exception']); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | public function testWhenGetDonationByIdDoesNotThrow_returnValueIsReturnedWithoutLogging() { |
| 76 | 76 | $logger = new LoggerSpy(); |
| 77 | 77 | $donation = ValidDonation::newDirectDebitDonation(); |
| 78 | - $donation->assignId( 1337 ); |
|
| 78 | + $donation->assignId(1337); |
|
| 79 | 79 | |
| 80 | 80 | $loggingRepo = new LoggingDonationRepository( |
| 81 | - new FakeDonationRepository( $donation ), |
|
| 81 | + new FakeDonationRepository($donation), |
|
| 82 | 82 | $logger |
| 83 | 83 | ); |
| 84 | 84 | |
| 85 | - $this->assertEquals( $donation, $loggingRepo->getDonationById( 1337 ) ); |
|
| 85 | + $this->assertEquals($donation, $loggingRepo->getDonationById(1337)); |
|
| 86 | 86 | $logger->assertNoLoggingCallsWhereMade(); |
| 87 | 87 | } |
| 88 | 88 | |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | new LoggerSpy() |
| 93 | 93 | ); |
| 94 | 94 | |
| 95 | - $this->expectException( StoreDonationException::class ); |
|
| 96 | - $loggingRepo->storeDonation( ValidDonation::newDirectDebitDonation() ); |
|
| 95 | + $this->expectException(StoreDonationException::class); |
|
| 96 | + $loggingRepo->storeDonation(ValidDonation::newDirectDebitDonation()); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | public function testWhenStoreDonationThrowException_itIsNotFullyCaught() { |
@@ -105,12 +105,12 @@ discard block |
||
| 105 | 105 | ); |
| 106 | 106 | |
| 107 | 107 | try { |
| 108 | - $loggingRepo->storeDonation( ValidDonation::newDirectDebitDonation() ); |
|
| 108 | + $loggingRepo->storeDonation(ValidDonation::newDirectDebitDonation()); |
|
| 109 | 109 | } |
| 110 | - catch ( StoreDonationException $ex ) { |
|
| 110 | + catch (StoreDonationException $ex) { |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - $this->assertExceptionLoggedAsCritical( StoreDonationException::class, $logger ); |
|
| 113 | + $this->assertExceptionLoggedAsCritical(StoreDonationException::class, $logger); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 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 | |
@@ -34,16 +34,16 @@ discard block |
||
| 34 | 34 | const FAILING_VERIFICATION_RESPONSE = 'FAIL'; |
| 35 | 35 | |
| 36 | 36 | public function testGivenValidRequest_applicationIndicatesSuccess() { |
| 37 | - $this->createEnvironment( [], function ( Client $client, FunFunFactory $factory ) { |
|
| 38 | - $factory->setTokenGenerator( new FixedTokenGenerator( |
|
| 37 | + $this->createEnvironment([], function(Client $client, FunFunFactory $factory) { |
|
| 38 | + $factory->setTokenGenerator(new FixedTokenGenerator( |
|
| 39 | 39 | self::UPDATE_TOKEN, |
| 40 | - \DateTime::createFromFormat( 'Y-m-d H:i:s', '2039-12-31 23:59:59' ) |
|
| 41 | - ) ); |
|
| 40 | + \DateTime::createFromFormat('Y-m-d H:i:s', '2039-12-31 23:59:59') |
|
| 41 | + )); |
|
| 42 | 42 | |
| 43 | - $factory->getDonationRepository()->storeDonation( ValidDonation::newIncompletePayPalDonation() ); |
|
| 43 | + $factory->getDonationRepository()->storeDonation(ValidDonation::newIncompletePayPalDonation()); |
|
| 44 | 44 | |
| 45 | 45 | $factory->setPayPalPaymentNotificationVerifier( |
| 46 | - $this->newNonNetworkUsingNotificationVerifier( $this->newHttpParamsForPayment() ) |
|
| 46 | + $this->newNonNetworkUsingNotificationVerifier($this->newHttpParamsForPayment()) |
|
| 47 | 47 | ); |
| 48 | 48 | |
| 49 | 49 | $client->request( |
@@ -52,14 +52,14 @@ discard block |
||
| 52 | 52 | $this->newHttpParamsForPayment() |
| 53 | 53 | ); |
| 54 | 54 | |
| 55 | - $this->assertSame( 200, $client->getResponse()->getStatusCode() ); |
|
| 56 | - $this->assertPayPalDataGotPersisted( $factory->getDonationRepository(), $this->newHttpParamsForPayment() ); |
|
| 55 | + $this->assertSame(200, $client->getResponse()->getStatusCode()); |
|
| 56 | + $this->assertPayPalDataGotPersisted($factory->getDonationRepository(), $this->newHttpParamsForPayment()); |
|
| 57 | 57 | } ); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - private function newNonNetworkUsingNotificationVerifier( array $requestParams ) { |
|
| 60 | + private function newNonNetworkUsingNotificationVerifier(array $requestParams) { |
|
| 61 | 61 | return new PayPalPaymentNotificationVerifier( |
| 62 | - $this->newGuzzleClientMock( self::VALID_VERIFICATION_RESPONSE, $requestParams ), |
|
| 62 | + $this->newGuzzleClientMock(self::VALID_VERIFICATION_RESPONSE, $requestParams), |
|
| 63 | 63 | self::BASE_URL, |
| 64 | 64 | self::EMAIL_ADDRESS |
| 65 | 65 | ); |
@@ -67,72 +67,72 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | private function newFailingNotifierMock() { |
| 69 | 69 | return new PayPalPaymentNotificationVerifier( |
| 70 | - $this->newGuzzleClientMock( self::FAILING_VERIFICATION_RESPONSE, $this->newHttpParamsForPayment() ), |
|
| 70 | + $this->newGuzzleClientMock(self::FAILING_VERIFICATION_RESPONSE, $this->newHttpParamsForPayment()), |
|
| 71 | 71 | self::BASE_URL, |
| 72 | 72 | self::EMAIL_ADDRESS |
| 73 | 73 | ); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - private function newGuzzleClientMock( string $responseBody, array $requestParams ): GuzzleClient { |
|
| 77 | - $body = $this->getMockBuilder( Stream::class ) |
|
| 76 | + private function newGuzzleClientMock(string $responseBody, array $requestParams): GuzzleClient { |
|
| 77 | + $body = $this->getMockBuilder(Stream::class) |
|
| 78 | 78 | ->disableOriginalConstructor() |
| 79 | - ->setMethods( [ 'getContents' ] ) |
|
| 79 | + ->setMethods(['getContents']) |
|
| 80 | 80 | ->getMock(); |
| 81 | 81 | |
| 82 | - $body->expects( $this->any() ) |
|
| 83 | - ->method( 'getContents' ) |
|
| 84 | - ->willReturn( $responseBody ); |
|
| 82 | + $body->expects($this->any()) |
|
| 83 | + ->method('getContents') |
|
| 84 | + ->willReturn($responseBody); |
|
| 85 | 85 | |
| 86 | - $response = $this->getMockBuilder( Response::class ) |
|
| 86 | + $response = $this->getMockBuilder(Response::class) |
|
| 87 | 87 | ->disableOriginalConstructor() |
| 88 | - ->setMethods( [ 'getBody' ] ) |
|
| 88 | + ->setMethods(['getBody']) |
|
| 89 | 89 | ->getMock(); |
| 90 | 90 | |
| 91 | - $response->expects( $this->any() ) |
|
| 92 | - ->method( 'getBody' ) |
|
| 93 | - ->willReturn( $body ); |
|
| 91 | + $response->expects($this->any()) |
|
| 92 | + ->method('getBody') |
|
| 93 | + ->willReturn($body); |
|
| 94 | 94 | |
| 95 | - $client = $this->getMockBuilder( GuzzleClient::class ) |
|
| 95 | + $client = $this->getMockBuilder(GuzzleClient::class) |
|
| 96 | 96 | ->disableOriginalConstructor() |
| 97 | - ->setMethods( [ 'post' ] ) |
|
| 97 | + ->setMethods(['post']) |
|
| 98 | 98 | ->getMock(); |
| 99 | 99 | |
| 100 | - $client->expects( $this->any() ) |
|
| 101 | - ->method( 'post' ) |
|
| 100 | + $client->expects($this->any()) |
|
| 101 | + ->method('post') |
|
| 102 | 102 | ->with( |
| 103 | 103 | self::BASE_URL, |
| 104 | - [ 'form_params' => array_merge( $requestParams, [ 'cmd' => '_notify-validate' ] ) ] |
|
| 104 | + ['form_params' => array_merge($requestParams, ['cmd' => '_notify-validate'])] |
|
| 105 | 105 | ) |
| 106 | - ->willReturn( $response ); |
|
| 106 | + ->willReturn($response); |
|
| 107 | 107 | |
| 108 | 108 | return $client; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - private function assertPayPalDataGotPersisted( DonationRepository $donationRepo, array $request ) { |
|
| 112 | - $donation = $donationRepo->getDonationById( self::DONATION_ID ); |
|
| 111 | + private function assertPayPalDataGotPersisted(DonationRepository $donationRepo, array $request) { |
|
| 112 | + $donation = $donationRepo->getDonationById(self::DONATION_ID); |
|
| 113 | 113 | |
| 114 | 114 | /** @var PayPalPayment $paymentMethod */ |
| 115 | 115 | $paymentMethod = $donation->getPayment()->getPaymentMethod(); |
| 116 | 116 | $pplData = $paymentMethod->getPayPalData(); |
| 117 | 117 | |
| 118 | - $this->assertSame( $request['payer_id'], $pplData->getPayerId() ); |
|
| 119 | - $this->assertSame( $request['subscr_id'], $pplData->getSubscriberId() ); |
|
| 120 | - $this->assertSame( $request['payer_status'], $pplData->getPayerStatus() ); |
|
| 121 | - $this->assertSame( $request['first_name'], $pplData->getFirstName() ); |
|
| 122 | - $this->assertSame( $request['last_name'], $pplData->getLastName() ); |
|
| 123 | - $this->assertSame( $request['address_name'], $pplData->getAddressName() ); |
|
| 124 | - $this->assertSame( $request['address_status'], $pplData->getAddressStatus() ); |
|
| 125 | - $this->assertSame( $request['mc_currency'], $pplData->getCurrencyCode() ); |
|
| 126 | - $this->assertSame( $request['mc_fee'], $pplData->getFee()->getEuroString() ); |
|
| 127 | - $this->assertSame( $request['mc_gross'], $pplData->getAmount()->getEuroString() ); |
|
| 128 | - $this->assertSame( $request['settle_amount'], $pplData->getSettleAmount()->getEuroString() ); |
|
| 129 | - |
|
| 130 | - $this->assertSame( $request['txn_id'], $pplData->getPaymentId() ); |
|
| 131 | - $this->assertSame( $request['payment_type'], $pplData->getPaymentType() ); |
|
| 132 | - $this->assertSame( $request['payment_status'] . '/' . $request['txn_type'], $pplData->getPaymentStatus() ); |
|
| 133 | - $this->assertSame( $request['payer_id'], $pplData->getPayerId() ); |
|
| 134 | - $this->assertSame( $request['payment_date'], $pplData->getPaymentTimestamp() ); |
|
| 135 | - $this->assertSame( $request['subscr_id'], $pplData->getSubscriberId() ); |
|
| 118 | + $this->assertSame($request['payer_id'], $pplData->getPayerId()); |
|
| 119 | + $this->assertSame($request['subscr_id'], $pplData->getSubscriberId()); |
|
| 120 | + $this->assertSame($request['payer_status'], $pplData->getPayerStatus()); |
|
| 121 | + $this->assertSame($request['first_name'], $pplData->getFirstName()); |
|
| 122 | + $this->assertSame($request['last_name'], $pplData->getLastName()); |
|
| 123 | + $this->assertSame($request['address_name'], $pplData->getAddressName()); |
|
| 124 | + $this->assertSame($request['address_status'], $pplData->getAddressStatus()); |
|
| 125 | + $this->assertSame($request['mc_currency'], $pplData->getCurrencyCode()); |
|
| 126 | + $this->assertSame($request['mc_fee'], $pplData->getFee()->getEuroString()); |
|
| 127 | + $this->assertSame($request['mc_gross'], $pplData->getAmount()->getEuroString()); |
|
| 128 | + $this->assertSame($request['settle_amount'], $pplData->getSettleAmount()->getEuroString()); |
|
| 129 | + |
|
| 130 | + $this->assertSame($request['txn_id'], $pplData->getPaymentId()); |
|
| 131 | + $this->assertSame($request['payment_type'], $pplData->getPaymentType()); |
|
| 132 | + $this->assertSame($request['payment_status'] . '/' . $request['txn_type'], $pplData->getPaymentStatus()); |
|
| 133 | + $this->assertSame($request['payer_id'], $pplData->getPayerId()); |
|
| 134 | + $this->assertSame($request['payment_date'], $pplData->getPaymentTimestamp()); |
|
| 135 | + $this->assertSame($request['subscr_id'], $pplData->getSubscriberId()); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | private function newHttpParamsForPayment(): array { |
@@ -161,9 +161,9 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | public function testGivenInvalidReceiverEmail_applicationReturnsError() { |
| 164 | - $this->createEnvironment( [], function ( Client $client, FunFunFactory $factory ) { |
|
| 164 | + $this->createEnvironment([], function(Client $client, FunFunFactory $factory) { |
|
| 165 | 165 | $factory->setPayPalPaymentNotificationVerifier( |
| 166 | - $this->newNonNetworkUsingNotificationVerifier( $this->newHttpParamsForPayment() ) |
|
| 166 | + $this->newNonNetworkUsingNotificationVerifier($this->newHttpParamsForPayment()) |
|
| 167 | 167 | ); |
| 168 | 168 | |
| 169 | 169 | $client->request( |
@@ -175,15 +175,15 @@ discard block |
||
| 175 | 175 | ] |
| 176 | 176 | ); |
| 177 | 177 | |
| 178 | - $this->assertSame( 'Payment receiver address does not match', $client->getResponse()->getContent() ); |
|
| 179 | - $this->assertSame( 403, $client->getResponse()->getStatusCode() ); |
|
| 178 | + $this->assertSame('Payment receiver address does not match', $client->getResponse()->getContent()); |
|
| 179 | + $this->assertSame(403, $client->getResponse()->getStatusCode()); |
|
| 180 | 180 | } ); |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | public function testGivenUnsupportedPaymentStatus_applicationReturnsOK() { |
| 184 | - $this->createEnvironment( [], function ( Client $client, FunFunFactory $factory ) { |
|
| 184 | + $this->createEnvironment([], function(Client $client, FunFunFactory $factory) { |
|
| 185 | 185 | $factory->setPayPalPaymentNotificationVerifier( |
| 186 | - $this->newNonNetworkUsingNotificationVerifier( $this->newPendingPaymentParams() ) |
|
| 186 | + $this->newNonNetworkUsingNotificationVerifier($this->newPendingPaymentParams()) |
|
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | 189 | $client->request( |
@@ -192,19 +192,19 @@ discard block |
||
| 192 | 192 | $this->newPendingPaymentParams() |
| 193 | 193 | ); |
| 194 | 194 | |
| 195 | - $this->assertSame( '', $client->getResponse()->getContent() ); |
|
| 196 | - $this->assertSame( 200, $client->getResponse()->getStatusCode() ); |
|
| 195 | + $this->assertSame('', $client->getResponse()->getContent()); |
|
| 196 | + $this->assertSame(200, $client->getResponse()->getStatusCode()); |
|
| 197 | 197 | } ); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | public function testGivenUnsupportedPaymentStatus_requestDataIsLogged() { |
| 201 | - $this->createEnvironment( [], function ( Client $client, FunFunFactory $factory ) { |
|
| 201 | + $this->createEnvironment([], function(Client $client, FunFunFactory $factory) { |
|
| 202 | 202 | $factory->setPayPalPaymentNotificationVerifier( |
| 203 | - $this->newNonNetworkUsingNotificationVerifier( $this->newPendingPaymentParams() ) |
|
| 203 | + $this->newNonNetworkUsingNotificationVerifier($this->newPendingPaymentParams()) |
|
| 204 | 204 | ); |
| 205 | 205 | |
| 206 | 206 | $logger = new LoggerSpy(); |
| 207 | - $factory->setPaypalLogger( $logger ); |
|
| 207 | + $factory->setPaypalLogger($logger); |
|
| 208 | 208 | |
| 209 | 209 | $client->request( |
| 210 | 210 | 'POST', |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | ); |
| 214 | 214 | |
| 215 | 215 | $this->assertSame( |
| 216 | - [ 'Unhandled PayPal instant payment notification' ], |
|
| 216 | + ['Unhandled PayPal instant payment notification'], |
|
| 217 | 217 | $logger->getLogCalls()->getMessages() |
| 218 | 218 | ); |
| 219 | 219 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | public function testGivenFailingVerification_applicationReturnsError() { |
| 228 | - $this->createEnvironment( [], function ( Client $client, FunFunFactory $factory ) { |
|
| 228 | + $this->createEnvironment([], function(Client $client, FunFunFactory $factory) { |
|
| 229 | 229 | $factory->setPayPalPaymentNotificationVerifier( |
| 230 | 230 | $this->newFailingNotifierMock() |
| 231 | 231 | ); |
@@ -236,15 +236,15 @@ discard block |
||
| 236 | 236 | $this->newHttpParamsForPayment() |
| 237 | 237 | ); |
| 238 | 238 | |
| 239 | - $this->assertSame( 'An error occurred while trying to confirm the sent data', $client->getResponse()->getContent() ); |
|
| 240 | - $this->assertSame( 403, $client->getResponse()->getStatusCode() ); |
|
| 239 | + $this->assertSame('An error occurred while trying to confirm the sent data', $client->getResponse()->getContent()); |
|
| 240 | + $this->assertSame(403, $client->getResponse()->getStatusCode()); |
|
| 241 | 241 | } ); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | public function testGivenUnsupportedCurrency_applicationReturnsError() { |
| 245 | - $this->createEnvironment( [], function ( Client $client, FunFunFactory $factory ) { |
|
| 245 | + $this->createEnvironment([], function(Client $client, FunFunFactory $factory) { |
|
| 246 | 246 | $factory->setPayPalPaymentNotificationVerifier( |
| 247 | - $this->newNonNetworkUsingNotificationVerifier( $this->newHttpParamsForPayment() ) |
|
| 247 | + $this->newNonNetworkUsingNotificationVerifier($this->newHttpParamsForPayment()) |
|
| 248 | 248 | ); |
| 249 | 249 | |
| 250 | 250 | $requestData = $this->newHttpParamsForPayment(); |
@@ -255,18 +255,18 @@ discard block |
||
| 255 | 255 | $requestData |
| 256 | 256 | ); |
| 257 | 257 | |
| 258 | - $this->assertSame( 'Unsupported currency', $client->getResponse()->getContent() ); |
|
| 259 | - $this->assertSame( 406, $client->getResponse()->getStatusCode() ); |
|
| 258 | + $this->assertSame('Unsupported currency', $client->getResponse()->getContent()); |
|
| 259 | + $this->assertSame(406, $client->getResponse()->getStatusCode()); |
|
| 260 | 260 | } ); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | public function testGivenTransactionTypeForSubscriptionChanges_requestDataIsLogged() { |
| 264 | - $this->createEnvironment( [], function ( Client $client, FunFunFactory $factory ) { |
|
| 264 | + $this->createEnvironment([], function(Client $client, FunFunFactory $factory) { |
|
| 265 | 265 | $factory->setPayPalPaymentNotificationVerifier( |
| 266 | - $this->newNonNetworkUsingNotificationVerifier( $this->newSubscriptionModificationParams() ) |
|
| 266 | + $this->newNonNetworkUsingNotificationVerifier($this->newSubscriptionModificationParams()) |
|
| 267 | 267 | ); |
| 268 | 268 | $logger = new LoggerSpy(); |
| 269 | - $factory->setPaypalLogger( $logger ); |
|
| 269 | + $factory->setPaypalLogger($logger); |
|
| 270 | 270 | |
| 271 | 271 | $client->request( |
| 272 | 272 | 'POST', |
@@ -274,10 +274,10 @@ discard block |
||
| 274 | 274 | $this->newSubscriptionModificationParams() |
| 275 | 275 | ); |
| 276 | 276 | |
| 277 | - $this->assertSame( 200, $client->getResponse()->getStatusCode() ); |
|
| 277 | + $this->assertSame(200, $client->getResponse()->getStatusCode()); |
|
| 278 | 278 | |
| 279 | 279 | $this->assertSame( |
| 280 | - [ 'Unhandled PayPal subscription notification' ], |
|
| 280 | + ['Unhandled PayPal subscription notification'], |
|
| 281 | 281 | $logger->getLogCalls()->getMessages() |
| 282 | 282 | ); |
| 283 | 283 | |
@@ -339,11 +339,11 @@ discard block |
||
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | public function testGivenNegativeTransactionFee_exceptionIsThrown() { |
| 342 | - $this->createEnvironment( [], function ( Client $client, FunFunFactory $factory ) { |
|
| 343 | - $factory->setPayPalPaymentNotificationVerifier( $this->newSucceedingNotificationVerifier() ); |
|
| 342 | + $this->createEnvironment([], function(Client $client, FunFunFactory $factory) { |
|
| 343 | + $factory->setPayPalPaymentNotificationVerifier($this->newSucceedingNotificationVerifier()); |
|
| 344 | 344 | |
| 345 | 345 | $logger = new LoggerSpy(); |
| 346 | - $factory->setPaypalLogger( $logger ); |
|
| 346 | + $factory->setPaypalLogger($logger); |
|
| 347 | 347 | |
| 348 | 348 | $client->request( |
| 349 | 349 | 'POST', |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | ); |
| 353 | 353 | |
| 354 | 354 | $this->assertSame( |
| 355 | - [ 'Unhandled PayPal instant payment notification' ], |
|
| 355 | + ['Unhandled PayPal instant payment notification'], |
|
| 356 | 356 | $logger->getLogCalls()->getMessages() |
| 357 | 357 | ); |
| 358 | 358 | } ); |
@@ -366,9 +366,9 @@ discard block |
||
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | private function newSucceedingNotificationVerifier(): PaymentNotificationVerifier { |
| 369 | - $verifier = $this->createMock( PaymentNotificationVerifier::class ); |
|
| 369 | + $verifier = $this->createMock(PaymentNotificationVerifier::class); |
|
| 370 | 370 | |
| 371 | - $verifier->expects( $this->any() )->method( 'verify' )->willReturn( true ); |
|
| 371 | + $verifier->expects($this->any())->method('verify')->willReturn(true); |
|
| 372 | 372 | |
| 373 | 373 | return $verifier; |
| 374 | 374 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare( strict_types = 1 ); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace WMDE\Fundraising\Frontend\Tests\Unit\Infrastructure; |
| 6 | 6 | |
@@ -24,20 +24,20 @@ discard block |
||
| 24 | 24 | new LoggerSpy() |
| 25 | 25 | ); |
| 26 | 26 | |
| 27 | - $this->expectException( PayPalPaymentNotificationVerifierException::class ); |
|
| 28 | - $loggingVerifier->verify( [] ); |
|
| 27 | + $this->expectException(PayPalPaymentNotificationVerifierException::class); |
|
| 28 | + $loggingVerifier->verify([]); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - private function newThrowingVerifier( PayPalPaymentNotificationVerifierException $exception = null ): PayPalPaymentNotificationVerifier { |
|
| 32 | - $verifier = $this->getMockBuilder( PayPalPaymentNotificationVerifier::class )->disableOriginalConstructor()->getMock(); |
|
| 31 | + private function newThrowingVerifier(PayPalPaymentNotificationVerifierException $exception = null): PayPalPaymentNotificationVerifier { |
|
| 32 | + $verifier = $this->getMockBuilder(PayPalPaymentNotificationVerifier::class)->disableOriginalConstructor()->getMock(); |
|
| 33 | 33 | |
| 34 | - if ( is_null( $exception ) ) { |
|
| 35 | - $exception = new PayPalPaymentNotificationVerifierException( 'reticulation of splines failed' ); |
|
| 34 | + if (is_null($exception)) { |
|
| 35 | + $exception = new PayPalPaymentNotificationVerifierException('reticulation of splines failed'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - $verifier->expects( $this->any() ) |
|
| 39 | - ->method( 'verify' ) |
|
| 40 | - ->willThrowException( $exception ); |
|
| 38 | + $verifier->expects($this->any()) |
|
| 39 | + ->method('verify') |
|
| 40 | + ->willThrowException($exception); |
|
| 41 | 41 | |
| 42 | 42 | return $verifier; |
| 43 | 43 | } |
@@ -51,22 +51,22 @@ discard block |
||
| 51 | 51 | ); |
| 52 | 52 | |
| 53 | 53 | try { |
| 54 | - $loggingVerifier->verify( [] ); |
|
| 54 | + $loggingVerifier->verify([]); |
|
| 55 | 55 | } |
| 56 | - catch ( PayPalPaymentNotificationVerifierException $ex ) { |
|
| 56 | + catch (PayPalPaymentNotificationVerifierException $ex) { |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - $this->assertExceptionLoggedAsCritical( PayPalPaymentNotificationVerifierException::class, $logger ); |
|
| 59 | + $this->assertExceptionLoggedAsCritical(PayPalPaymentNotificationVerifierException::class, $logger); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - private function assertExceptionLoggedAsCritical( string $expectedExceptionType, LoggerSpy $logger ) { |
|
| 63 | - $this->assertNotEmpty( $logger->getLogCalls(), 'There should be at least one log call' ); |
|
| 62 | + private function assertExceptionLoggedAsCritical(string $expectedExceptionType, LoggerSpy $logger) { |
|
| 63 | + $this->assertNotEmpty($logger->getLogCalls(), 'There should be at least one log call'); |
|
| 64 | 64 | |
| 65 | 65 | $logCall = $logger->getLogCalls()->getFirstCall(); |
| 66 | 66 | |
| 67 | - $this->assertSame( LogLevel::CRITICAL, $logCall->getLevel() ); |
|
| 68 | - $this->assertArrayHasKey( 'exception', $logCall->getContext(), 'the log context should contain an exception element' ); |
|
| 69 | - $this->assertInstanceOf( $expectedExceptionType, $logCall->getContext()['exception'] ); |
|
| 67 | + $this->assertSame(LogLevel::CRITICAL, $logCall->getLevel()); |
|
| 68 | + $this->assertArrayHasKey('exception', $logCall->getContext(), 'the log context should contain an exception element'); |
|
| 69 | + $this->assertInstanceOf($expectedExceptionType, $logCall->getContext()['exception']); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | public function testGivenAnExceptionForUnsupportedPaymentMethod_itIsLoggedAsInfo() { |
@@ -77,27 +77,27 @@ discard block |
||
| 77 | 77 | PayPalPaymentNotificationVerifierException::ERROR_UNSUPPORTED_STATUS |
| 78 | 78 | ); |
| 79 | 79 | $loggingVerifier = new LoggingPaymentNotificationVerifier( |
| 80 | - $this->newThrowingVerifier( $statusException ), |
|
| 80 | + $this->newThrowingVerifier($statusException), |
|
| 81 | 81 | $logger |
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | 84 | try { |
| 85 | - $loggingVerifier->verify( [ 'payment_status' => 'Unknown' ] ); |
|
| 85 | + $loggingVerifier->verify(['payment_status' => 'Unknown']); |
|
| 86 | 86 | } |
| 87 | - catch ( PayPalPaymentNotificationVerifierException $ex ) { |
|
| 87 | + catch (PayPalPaymentNotificationVerifierException $ex) { |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $this->assertUnsupportedMethodWasLogged( 'Unknown', $logger ); |
|
| 90 | + $this->assertUnsupportedMethodWasLogged('Unknown', $logger); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - private function assertUnsupportedMethodWasLogged( string $expectedMethodName, LoggerSpy $logger ) { |
|
| 94 | - $this->assertNotEmpty( $logger->getLogCalls(), 'There should be at least one log call' ); |
|
| 93 | + private function assertUnsupportedMethodWasLogged(string $expectedMethodName, LoggerSpy $logger) { |
|
| 94 | + $this->assertNotEmpty($logger->getLogCalls(), 'There should be at least one log call'); |
|
| 95 | 95 | |
| 96 | 96 | $logCall = $logger->getLogCalls()->getFirstCall(); |
| 97 | 97 | |
| 98 | - $this->assertSame( LogLevel::INFO, $logCall->getLevel() ); |
|
| 99 | - $this->assertArrayHasKey( 'payment_status', $logCall->getContext(), 'the log context should contain a payment_status element' ); |
|
| 100 | - $this->assertSame( $expectedMethodName, $logCall->getContext()['payment_status'] ); |
|
| 98 | + $this->assertSame(LogLevel::INFO, $logCall->getLevel()); |
|
| 99 | + $this->assertArrayHasKey('payment_status', $logCall->getContext(), 'the log context should contain a payment_status element'); |
|
| 100 | + $this->assertSame($expectedMethodName, $logCall->getContext()['payment_status']); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | public function testWhenVerifierThrowsException_requestIsLoggedAsDebugInfo() { |
@@ -109,22 +109,22 @@ discard block |
||
| 109 | 109 | ); |
| 110 | 110 | |
| 111 | 111 | try { |
| 112 | - $loggingVerifier->verify( [ 'item_name' => 'Welcome to Wikipedia' ] ); |
|
| 112 | + $loggingVerifier->verify(['item_name' => 'Welcome to Wikipedia']); |
|
| 113 | 113 | } |
| 114 | - catch ( PayPalPaymentNotificationVerifierException $ex ) { |
|
| 114 | + catch (PayPalPaymentNotificationVerifierException $ex) { |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - $this->assertRequestLoggedAsDebugInfo( $logger ); |
|
| 117 | + $this->assertRequestLoggedAsDebugInfo($logger); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - private function assertRequestLoggedAsDebugInfo( LoggerSpy $logger ) { |
|
| 121 | - $this->assertGreaterThan( 1, count( $logger->getLogCalls() ), 'There should be at least two log calls' ); |
|
| 120 | + private function assertRequestLoggedAsDebugInfo(LoggerSpy $logger) { |
|
| 121 | + $this->assertGreaterThan(1, count($logger->getLogCalls()), 'There should be at least two log calls'); |
|
| 122 | 122 | |
| 123 | 123 | $logCall = $logger->getLogCalls()->getIterator()[1]; |
| 124 | 124 | |
| 125 | - $this->assertSame( LogLevel::DEBUG, $logCall->getLevel() ); |
|
| 125 | + $this->assertSame(LogLevel::DEBUG, $logCall->getLevel()); |
|
| 126 | 126 | $this->assertSame( |
| 127 | - [ 'item_name' => 'Welcome to Wikipedia' ], |
|
| 127 | + ['item_name' => 'Welcome to Wikipedia'], |
|
| 128 | 128 | $logCall->getContext(), |
| 129 | 129 | 'the third log argument should contain the request' |
| 130 | 130 | ); |
@@ -132,14 +132,14 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | public function testWhenVerifierSucceeds_nothingIsLogged() { |
| 134 | 134 | $logger = new LoggerSpy(); |
| 135 | - $verifierMock = $this->getMockBuilder( PayPalPaymentNotificationVerifier::class )->disableOriginalConstructor()->getMock(); |
|
| 135 | + $verifierMock = $this->getMockBuilder(PayPalPaymentNotificationVerifier::class)->disableOriginalConstructor()->getMock(); |
|
| 136 | 136 | $verifier = new LoggingPaymentNotificationVerifier( |
| 137 | 137 | $verifierMock, |
| 138 | 138 | $logger |
| 139 | 139 | ); |
| 140 | - $verifier->verify( [] ); |
|
| 140 | + $verifier->verify([]); |
|
| 141 | 141 | |
| 142 | - $this->assertEmpty( $logger->getLogCalls(), 'No log calls should be made' ); |
|
| 142 | + $this->assertEmpty($logger->getLogCalls(), 'No log calls should be made'); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | } |