Passed
Push — develop ( 829d6c...4f91f4 )
by Remco
04:10
created

CreditCardTest::test_get_expiration_date()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Credit card test
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2018 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Payments
9
 */
10
11
namespace Pronamic\WordPress\Pay;
12
13
use DateTime;
14
use WP_UnitTestCase;
0 ignored issues
show
Bug introduced by
The type WP_UnitTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
/**
17
 * Payment test
18
 *
19
 * @author Remco Tolsma
20
 * @version 1.0
21
 */
22
class CreditCardTest extends WP_UnitTestCase {
23
	/**
24
	 * Test construct payment object.
25
	 */
26
	public function test_construct() {
27
		$credit_card = new CreditCard();
28
29
		$this->assertInstanceOf( __NAMESPACE__ . '\CreditCard', $credit_card );
30
	}
31
32
	/** 
33
	 * Test setting and getting the credit card number.
34
	 */
35
	public function test_set_and_get_number() {
36
		$credit_card = new CreditCard();
37
38
		$number = '5300000000000006';
39
40
		$credit_card->set_number( $number );
41
42
		$this->assertEquals( $number, $credit_card->get_number() );
43
	}
44
45
	/** 
46
	 * Test setting and getting the credit card expiration month.
47
	 */
48
	public function test_set_and_get_expiration_month() {
49
		$credit_card = new CreditCard();
50
51
		$month = 12;
52
53
		$credit_card->set_expiration_month( $month );
54
55
		$this->assertEquals( $month, $credit_card->get_expiration_month() );
56
	}
57
58
	/** 
59
	 * Test setting and getting the credit card expiration year.
60
	 */
61
	public function test_set_and_get_expiration_year() {
62
		$credit_card = new CreditCard();
63
64
		$year = date( 'Y' ) + 5;
65
66
		$credit_card->set_expiration_year( $year );
67
68
		$this->assertEquals( $year, $credit_card->get_expiration_year() );
69
	}
70
71
	/** 
72
	 * Test getting the expiration date.
73
	 *
74
	 * @dataProvider expiration_dates_provider
75
	 */
76
	public function test_get_expiration_date( $year, $month, $expected_date ) {
77
		$credit_card = new CreditCard();
78
79
		$credit_card->set_expiration_year( $year );
80
		$credit_card->set_expiration_month( $month );
81
82
		$date = $credit_card->get_expiration_date();
83
84
		$this->assertEquals( $expected_date, $date );
85
	}
86
87
	/**
88
	 * Expiration dates provider.
89
	 */
90
	public function expiration_dates_provider() {
91
		return array(
92
			array( '2018', '12', new DateTime( 'first day of December 2018' ) ),
93
			array( 2018, 12, new DateTime( 'first day of December 2018' ) ),
94
			array( '2018', null, null ),
95
			array( null, null, null ),
96
			array( false, false, null ),
97
		);
98
	}
99
100
	/** 
101
	 * Test setting and getting the credit card security code.
102
	 */
103
	public function test_set_and_get_security_code() {
104
		$credit_card = new CreditCard();
105
106
		$code = '123';
107
108
		$credit_card->set_security_code( $code );
0 ignored issues
show
Bug introduced by
$code of type string is incompatible with the type integer expected by parameter $security_code of Pronamic\WordPress\Pay\C...rd::set_security_code(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

108
		$credit_card->set_security_code( /** @scrutinizer ignore-type */ $code );
Loading history...
109
110
		$this->assertEquals( $code, $credit_card->get_security_code() );
111
	}
112
113
	/** 
114
	 * Test setting and getting the credit card name.
115
	 */
116
	public function test_set_and_get_name() {
117
		$credit_card = new CreditCard();
118
119
		$name = 'Pronamic';
120
121
		$credit_card->set_name( $name );
122
123
		$this->assertEquals( $name, $credit_card->get_name() );
124
	}
125
}
126