|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\PaymentContext\Tests\Integration\DataAccess; |
|
6
|
|
|
|
|
7
|
|
|
use WMDE\Fundraising\Frontend\PaymentContext\DataAccess\McpCreditCardService; |
|
8
|
|
|
use WMDE\Fundraising\Frontend\PaymentContext\Infrastructure\CreditCardExpiry; |
|
9
|
|
|
use WMDE\Fundraising\Frontend\PaymentContext\Infrastructure\CreditCardExpiryFetchingException; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @covers \WMDE\Fundraising\Frontend\PaymentContext\DataAccess\McpCreditCardService |
|
13
|
|
|
* |
|
14
|
|
|
* @licence GNU GPL v2+ |
|
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
16
|
|
|
*/ |
|
17
|
|
|
class McpCreditCardServiceTest extends \PHPUnit\Framework\TestCase { |
|
18
|
|
|
|
|
19
|
|
|
const ACCESS_KEY = 'pink fluffy unicorns'; |
|
20
|
|
|
const CUSTOMER_ID = '31333333333333333337'; |
|
21
|
|
|
|
|
22
|
|
|
const EXPIRY_MONTH = 5; |
|
23
|
|
|
const EXPIRY_YEAR = 2020; |
|
24
|
|
|
|
|
25
|
|
|
const VALID_RETURN_DATA = [ |
|
26
|
|
|
'expiryMonth' => self::EXPIRY_MONTH, |
|
27
|
|
|
'expiryYear' => self::EXPIRY_YEAR, |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
public function testMicroPaymentServiceGetsCalledWithAccessKeyAndCustomerId(): void { |
|
31
|
|
|
$microPaymentServiceMock = $this->getMicroPaymentServiceTestDouble(); |
|
32
|
|
|
|
|
33
|
|
|
$microPaymentServiceMock->expects( $this->once() ) |
|
|
|
|
|
|
34
|
|
|
->method( 'creditcardDataGet' ) |
|
35
|
|
|
->with( |
|
36
|
|
|
$this->equalTo( self::ACCESS_KEY ), |
|
37
|
|
|
$this->equalTo( true ), |
|
38
|
|
|
$this->equalTo( self::CUSTOMER_ID ) |
|
39
|
|
|
) |
|
40
|
|
|
->willReturn( self::VALID_RETURN_DATA ); |
|
41
|
|
|
|
|
42
|
|
|
$creditCardService = new McpCreditCardService( $microPaymentServiceMock, self::ACCESS_KEY, true ); |
|
|
|
|
|
|
43
|
|
|
$creditCardService->getExpirationDate( self::CUSTOMER_ID ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\IMcpCreditcardService_v1_5 |
|
48
|
|
|
*/ |
|
49
|
|
|
private function getMicroPaymentServiceTestDouble() { |
|
50
|
|
|
return $this->createMock( \IMcpCreditcardService_v1_5::class ); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testWhenValidDataIsReturned_creditCardExpiryIsCreated(): void { |
|
54
|
|
|
$microPaymentServiceStub = $this->getMicroPaymentServiceTestDouble(); |
|
55
|
|
|
|
|
56
|
|
|
$microPaymentServiceStub->expects( $this->any() ) |
|
|
|
|
|
|
57
|
|
|
->method( 'creditcardDataGet' ) |
|
58
|
|
|
->willReturn( self::VALID_RETURN_DATA ); |
|
59
|
|
|
|
|
60
|
|
|
$creditCardService = new McpCreditCardService( $microPaymentServiceStub, self::ACCESS_KEY, true ); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
$this->assertEquals( |
|
63
|
|
|
new CreditCardExpiry( self::EXPIRY_MONTH, self::EXPIRY_YEAR ), |
|
64
|
|
|
$creditCardService->getExpirationDate( self::CUSTOMER_ID ) |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @dataProvider invalidReturnDataProvider |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testWhenInvalidDataIsReturned_exceptionIsThrown( array $invalidReturnData ): void { |
|
72
|
|
|
$microPaymentServiceStub = $this->getMicroPaymentServiceTestDouble(); |
|
73
|
|
|
|
|
74
|
|
|
$microPaymentServiceStub->expects( $this->any() ) |
|
|
|
|
|
|
75
|
|
|
->method( 'creditcardDataGet' ) |
|
76
|
|
|
->willReturn( $invalidReturnData ); |
|
77
|
|
|
|
|
78
|
|
|
$creditCardService = new McpCreditCardService( $microPaymentServiceStub, self::ACCESS_KEY, true ); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
$this->expectException( CreditCardExpiryFetchingException::class ); |
|
81
|
|
|
$creditCardService->getExpirationDate( self::CUSTOMER_ID ); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function invalidReturnDataProvider(): array { |
|
85
|
|
|
return [ |
|
86
|
|
|
[ [ |
|
87
|
|
|
'expiryMonth' => 'potato', |
|
88
|
|
|
'expiryYear' => self::EXPIRY_YEAR, |
|
89
|
|
|
] ], |
|
90
|
|
|
[ [ |
|
91
|
|
|
'expiryMonth' => 0, |
|
92
|
|
|
'expiryYear' => self::EXPIRY_YEAR, |
|
93
|
|
|
] ], |
|
94
|
|
|
[ [ |
|
95
|
|
|
'expiryMonth' => 13, |
|
96
|
|
|
'expiryYear' => self::EXPIRY_YEAR, |
|
97
|
|
|
] ] |
|
98
|
|
|
]; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
} |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: