|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Classes; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
class CreditCardTest extends TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
private $card; |
|
10
|
|
|
|
|
11
|
|
|
public function setUp() |
|
12
|
|
|
{ |
|
13
|
|
|
parent::setUp(); |
|
14
|
|
|
|
|
15
|
|
|
$this->card = new \Ipag\Classes\CreditCard(); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function testCreateAndSetCreditCardSuccessfully() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->card->setNumber('4111 1111 1111 1111') |
|
21
|
|
|
->setToken('ABDCD123456789') |
|
22
|
|
|
->setHolder('FULANO DA SILVA') |
|
23
|
|
|
->setExpiryMonth('05') |
|
24
|
|
|
->setExpiryYear('2022') |
|
25
|
|
|
->setCvc('123') |
|
26
|
|
|
->setSave(false); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertEquals($this->card->getToken(), 'ABDCD123456789'); |
|
29
|
|
|
$this->assertEquals($this->card->getNumber(), '4111111111111111'); |
|
30
|
|
|
$this->assertEquals($this->card->getHolder(), 'FULANO DA SILVA'); |
|
31
|
|
|
$this->assertEquals($this->card->getExpiryMonth(), '05'); |
|
32
|
|
|
$this->assertEquals($this->card->getExpiryYear(), '2022'); |
|
33
|
|
|
$this->assertEquals($this->card->getCvc(), '123'); |
|
34
|
|
|
$this->assertEquals($this->card->hasSave(), false); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testSetExpiryMonthThrowUnexpectedValueException() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->expectException(\UnexpectedValueException::class); |
|
40
|
|
|
$this->card->setExpiryMonth('100'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testSetExpiryYearThrowUnexpectedValueException() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->expectException(\UnexpectedValueException::class); |
|
46
|
|
|
$this->card->setExpiryYear('1'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testSetCvcShouldThrowUnexpectedValueException() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->expectException(\UnexpectedValueException::class); |
|
52
|
|
|
$this->card->setCvc('ABCD'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testIfCreditCardHasToken() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->card->setToken(null); |
|
58
|
|
|
$this->assertFalse($this->card->hasToken()); |
|
59
|
|
|
|
|
60
|
|
|
$this->card->setToken('ABCD123456789'); |
|
61
|
|
|
$this->assertTrue($this->card->hasToken()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testIfCreditCardHasCvc() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->card = new \Ipag\Classes\CreditCard(); |
|
67
|
|
|
$this->assertFalse($this->card->hasCvc()); |
|
68
|
|
|
|
|
69
|
|
|
$this->card->setCvc('123'); |
|
70
|
|
|
$this->assertTrue($this->card->hasCvc()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testHideSensitiveCreditCardData() |
|
74
|
|
|
{ |
|
75
|
|
|
$this->card->setNumber('4111 1111 1111 1111') |
|
76
|
|
|
->setCvc('123'); |
|
77
|
|
|
|
|
78
|
|
|
$this->card->hide(); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertEquals($this->card->getNumber(), '411111******1111'); |
|
81
|
|
|
$this->assertEquals($this->card->getCvc(), '***'); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|