Passed
Push — develop ( 19a8b8...726e4d )
by Luís
29s
created

SubscriptionTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 111
Duplicated Lines 64.86 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 6
dl 72
loc 111
rs 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace PHPSC\PagSeguro\Purchases\Subscriptions;
3
4
use DateTime;
5
use PHPSC\PagSeguro\Purchases\Details;
6
use PHPSC\PagSeguro\Customer\Address;
7
use PHPSC\PagSeguro\Customer\Customer;
8
use PHPSC\PagSeguro\Customer\Phone;
9
10
/**
11
 * @author Renato Moura <[email protected]>
12
 */
13
class SubscriptionTest extends \PHPUnit_Framework_TestCase
14
{
15
    protected function setUp()
16
    {
17
        $this->dDate = new DateTime('2011-11-23T13:40:00.000-02:00');
18
        $this->eventDate = new DateTime('2011-11-25T20:04:00.000-02:00');
19
        $this->detailsAddress = new Address('SP', 'SAO PAULO', '01421000', 'J Paulista', 'ALAMEDAITU', '78', 'ap.2601');
20
        $this->customer = new Customer('[email protected]', 'Comprador', new Phone('11', '30389678'), $this->detailsAddress);
21
    }
22
23
    public function testConstructShouldReturnOfGetters()
24
    {
25
        $details = new Details('C89', 'R12', '', $this->dDate, $this->eventDate, $this->customer);
26
        $subscription = new Subscription('FooBar', $details, 'TRACKER-AAAA', '');
27
28
        $this->assertEquals('FooBar', $subscription->getName());
29
        $this->assertEquals($details, $subscription->getDetails());
30
        $this->assertEquals('TRACKER-AAAA', $subscription->getTracker());
31
32
        $this->assertFalse($subscription->isAutomatic());
33
        $this->assertFalse($subscription->isManual());
34
        $this->assertFalse($subscription->isInitiated());
35
        $this->assertFalse($subscription->isPending());
36
        $this->assertFalse($subscription->isActive());
37
        $this->assertFalse($subscription->isCancelledByAcquirer());
38
        $this->assertFalse($subscription->isCancelledByReceiver());
39
        $this->assertFalse($subscription->isCancelledByCustomer());
40
        $this->assertFalse($subscription->isExpired());
41
    }
42
43
    public function testIsAutomaticShouldReturnTrue()
44
    {
45
        $details = new Details('C89', 'R12', '', $this->dDate, $this->eventDate, $this->customer);
46
        $subscription = new Subscription('FooBar', $details, 'TRACKER-AAAA', 'auto');
47
48
        $this->assertTrue($subscription->isAutomatic());
49
        $this->assertFalse($subscription->isManual());
50
    }
51
52
    public function testIsManualShouldReturnTrue()
53
    {
54
        $details = new Details('C89', 'R12', '', $this->dDate, $this->eventDate, $this->customer);
55
        $subscription = new Subscription('FooBar', $details, 'TRACKER-AAAA', 'manual');
56
57
        $this->assertTrue($subscription->isManual());
58
        $this->assertFalse($subscription->isAutomatic());
59
    }
60
61
    public function testIsInitiatedShouldReturnTrue()
62
    {
63
        $details = new Details('C89', 'R12', 'INITIATED', $this->dDate, $this->eventDate, $this->customer);
64
65
        $subscription = new Subscription('FooBar', $details, 'TRACKER-AAAA', 'manual');
66
67
        $this->assertTrue($subscription->isInitiated());
68
    }
69
70
    public function testIsPendingShouldReturnTrue()
71
    {
72
        $details = new Details('C89', 'R12', 'PENDING', $this->dDate, $this->eventDate, $this->customer);
73
74
        $subscription = new Subscription('FooBar', $details, 'TRACKER-AAAA', 'manual');
75
76
        $this->assertTrue($subscription->isPending());
77
    }
78
79
    public function testIsActiveShouldReturnTrue()
80
    {
81
        $details = new Details('C89', 'R12', 'ACTIVE', $this->dDate, $this->eventDate, $this->customer);
82
83
        $subscription = new Subscription('FooBar', $details, 'TRACKER-AAAA', 'manual');
84
85
        $this->assertTrue($subscription->isActive());
86
    }
87
88
    public function testIsCancelledByAcquirerShouldReturnTrue()
89
    {
90
        $details = new Details('C89', 'R12', 'CANCELLED', $this->dDate, $this->eventDate, $this->customer);
91
92
        $subscription = new Subscription('FooBar', $details, 'TRACKER-AAAA', 'manual');
93
94
        $this->assertTrue($subscription->isCancelledByAcquirer());
95
    }
96
97
    public function testIsCancelledByReceiverShouldReturnTrue()
98
    {
99
        $details = new Details('C89', 'R12', 'CANCELLED_BY_RECEIVER', $this->dDate, $this->eventDate, $this->customer);
100
101
        $subscription = new Subscription('FooBar', $details, 'TRACKER-AAAA', 'manual');
102
103
        $this->assertTrue($subscription->isCancelledByReceiver());
104
    }
105
106
    public function testIsCancelledByCustomerShouldReturnTrue()
107
    {
108
        $details = new Details('C89', 'R12', 'CANCELLED_BY_SENDER', $this->dDate, $this->eventDate, $this->customer);
109
110
        $subscription = new Subscription('FooBar', $details, 'TRACKER-AAAA', 'manual');
111
112
        $this->assertTrue($subscription->isCancelledByCustomer());
113
    }
114
115
    public function testIsExpiredShouldReturnTrue()
116
    {
117
        $details = new Details('C89', 'R12', 'EXPIRED', $this->dDate, $this->eventDate, $this->customer);
118
119
        $subscription = new Subscription('FooBar', $details, 'TRACKER-AAAA', 'manual');
120
121
        $this->assertTrue($subscription->isExpired());
122
    }
123
}
124