Completed
Push — master ( 0e04ed...9b5d60 )
by Antony
9s
created

testOrderStatusLogItemsWithMember()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 173
Code Lines 129

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 173
rs 8.2857
cc 1
eloc 129
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @link OrderStatusLog
4
 * @package shop_statuschangeemail
5
 * @subpackage tests
6
 */
7
class OrderStatusLogTest extends SapphireTest
8
{
9
    protected static $fixture_file = array(
10
        'silvershop/tests/fixtures/Orders.yml',
11
        'silvershop/tests/fixtures/ShopMembers.yml',
12
        'silvershop/tests/fixtures/Pages.yml'
13
    );
14
15
    public function setUp()
16
    {
17
        parent::setUp();
18
        ShopTest::setConfiguration();
19
        Order::config()->log_status = array('Processing', 'Sent', 'AdminCancelled', 'MemberCancelled');
20
21
    }
22
23
    public function testOrderStatusLogItemsWithMember()
24
    {
25
        // start a new order
26
        $order = $this->objFromFixture("Order", "cart1");
27
        $member = $this->objFromFixture('Member', 'jeremyperemy');
28
        $order->MemberID = $member->ID;
29
30
        $no_log_generated_with_order_status_cart = OrderStatusLog::get()->sort('ID')->last();
31
        $this->assertNull(
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
            $no_log_generated_with_order_status_cart,
33
            "no log generated with Status of 'Cart'"
34
        );
35
 
36
        $order->Status = "Unpaid";
37
        $order->write();
38
39
        $no_log_generated_with_order_status_unpaid = OrderStatusLog::get()->sort('ID')->last();
40
        $this->assertNull(
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
            $no_log_generated_with_order_status_unpaid,
42
            "no log generated with Status of 'Unpaid'"
43
        );
44
45
        $processor = OrderProcessor::create($order);
0 ignored issues
show
Compatibility introduced by
$order of type object<DataObject> is not a sub-type of object<Order>. It seems like you assume a child class of the class DataObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
46
        $response = $processor->makePayment("Manual", array());
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
        $order->Status = "Paid";
48
        $order->write();
49
50
        $log_order_status_paid = OrderStatusLog::get()->sort('ID')->last();
51
        $this->assertNull(
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
            $log_order_status_paid,
53
            "no log generated with Status of 'Unpaid'"
54
        );
55
56
        $order->Status = "Processing";
57
        $order->write();
58
59
        $log_order_status_processing = OrderStatusLog::get()->sort('ID')->last();
60
        $this->assertEquals(OrderStatusLog::get()->count(), '1', "One items in the OrderStatusLog");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
        $this->assertNotNull(
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
            $log_order_status_processing,
63
            "a log when changing to 'Processing' status (and PaymentMethod is 'Manual')"
64
        );
65
        $this->assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
            $log_order_status_processing->Order()->ID,
67
            $order->ID,
68
            "Log conatins an Order"
69
        );
70
71
        $this->assertContains(
72
            "Processing",
73
            $log_order_status_processing->Note,
74
            "Processing note is recorded"
75
        );
76
        $this->assertContains(
77
            'changed to "Processing"',
78
            $log_order_status_processing->Title,
79
            'Processing title is recorded'
80
        );
81
        $this->assertEmailSent(
82
            '[email protected]',
83
            '[email protected]',
84
            _t('ShopEmail.StatusChangeSubject') . $log_order_status_processing->Title
85
        );
86
        $order->Status = "Sent";
87
        $order->write();
88
89
        $log_order_status_sent = OrderStatusLog::get()->sort('ID')->last();
90
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
            OrderStatusLog::get()->count(),
92
            '2',
93
            "Three items in the OrderStatusLog"
94
        );
95
        $this->assertNotNull(
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
96
            $log_order_status_sent,
97
            "an log should be recorded when an order's status is changed to 'Sent' (and PaymentMethod is 'Manual')"
98
        );
99
        $this->assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
            $log_order_status_sent->Order()->ID,
101
            $order->ID,
102
            "Log conatins an Order"
103
        );
104
        $this->assertContains(
105
            "sent",
106
            $log_order_status_sent->Note,
107
            "Sent note is recorded"
108
        );
109
        $this->assertContains(
110
            'changed to "Sent"',
111
            $log_order_status_sent->Title,
112
            "Sent title is recorded"
113
        );
114
115
        $this->assertEmailSent(
116
            "[email protected]",
117
            "[email protected]",
118
            _t('ShopEmail.StatusChangeSubject') . $log_order_status_sent->Title
119
        );
120
121
        $order->Status = "Complete";
122
        $order->write();
123
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
124
            OrderStatusLog::get()->count(),
125
            '2',
126
            "Additional item in the OrderStatusLog has not been created"
127
        );
128
129
        $order->Status = "AdminCancelled";
130
        $order->write();
131
        
132
        $log_order_status_admin_cancelled = OrderStatusLog::get()->sort('ID')->last();
133
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
134
            OrderStatusLog::get()->count(),
135
            '3',
136
            "Three items in the OrderStatusLog"
137
        );
138
        $this->assertNotNull(
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
139
            $log_order_status_admin_cancelled,
140
            "a log should be recorded with change to 'Admin Cancelled' status (and PaymentMethod is 'Manual')"
141
        );
142
        $this->assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
143
            $log_order_status_admin_cancelled->Order()->ID,
144
            $order->ID,
145
            "Log conatins an Order"
146
        );
147
        $this->assertContains(
148
            "cancelled",
149
            $log_order_status_admin_cancelled->Note,
150
            "Admin Cancelled note is recorded"
151
        );
152
        $this->assertContains(
153
            'changed to "Cancelled by admin"',
154
            $log_order_status_admin_cancelled->Title,
155
            "Admin Cancelled title is recorded"
156
        );
157
        $this->assertEmailSent(
158
            "[email protected]",
159
            "[email protected]",
160
            _t('ShopEmail.StatusChangeSubject') . $log_order_status_admin_cancelled->Title
161
        );
162
163
        $order->Status = "MemberCancelled";
164
        $order->write();
165
        $log_order_status_member_cancelled = OrderStatusLog::get()->sort('ID')->last();
166
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
167
            OrderStatusLog::get()->count(),
168
            '4',
169
            "Four items in the OrderStatusLog"
170
        );
171
        $this->assertNotNull(
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
172
            $log_order_status_member_cancelled,
173
            "a log should be recorded for change to 'Member Cancelled' status (and PaymentMethod is 'Manual')"
174
        );
175
        $this->assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
176
            $log_order_status_member_cancelled->Order()->ID,
177
            $order->ID,
178
            "Log conatins an Order"
179
        );
180
        $this->assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
181
            "Your cancellation of the order has been noted.  Please contact us if you have any questions.",
182
            $log_order_status_member_cancelled->Note,
183
            "Member Cancelled note is recorded"
184
        );
185
        $this->assertContains(
186
            ' changed to "Cancelled by member"',
187
            $log_order_status_member_cancelled->Title,
188
            "Member Cancelled title is recorded"
189
        );
190
        $this->assertEmailSent(
191
            '[email protected]',
192
            '[email protected]',
193
            _t('ShopEmail.StatusChangeSubject') . $log_order_status_member_cancelled->Title
194
        );
195
    }
196
197
    public function testOrderPlacedByGuest()
198
    {
199
        // start a new order
200
        $order = $this->objFromFixture("Order", "cart1");
201
        $order->FirstName = "Edmund";
202
        $order->Surname = "Hillary";
203
        $order->Email = "[email protected]";
204
        $order->Status = "Unpaid";
205
        $order->write();
206
207
        $no_log_generated_with_order_status_unpaid = OrderStatusLog::get()->sort('ID')->last();
208
        $this->assertNull(
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
209
            $no_log_generated_with_order_status_unpaid,
210
            "no log generated with Status of 'Unpaid'"
211
        );
212
213
        $processor_guest = OrderProcessor::create($order);
0 ignored issues
show
Compatibility introduced by
$order of type object<DataObject> is not a sub-type of object<Order>. It seems like you assume a child class of the class DataObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
214
        $response = $processor_guest->makePayment("Manual", array());
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
215
        $order->Status = "Paid";
216
        $order->write();
217
218
        $log_order_status_paid = OrderStatusLog::get()->sort('ID')->last();
219
        $this->assertNull(
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
220
            $log_order_status_paid,
221
            "no log generated with Status of 'Unpaid'"
222
        );
223
224
        $order->Status = "Processing";
225
        $order->write();
226
227
        $log_order_status_processing = OrderStatusLog::get()->sort('ID')->last();
228
        $this->assertEquals(OrderStatusLog::get()->count(), '1', "One items in the OrderStatusLog");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
229
        $this->assertNotNull(
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
230
            $log_order_status_processing,
231
            "a log when changing to 'Processing' status (and PaymentMethod is 'Manual')"
232
        );
233
        $this->assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<OrderStatusLogTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
234
            $log_order_status_processing->Order()->ID,
235
            $order->ID,
236
            "Log conatins an Order"
237
        );
238
239
        $this->assertContains(
240
            "Processing",
241
            $log_order_status_processing->Note,
242
            "Processing note is recorded"
243
        );
244
        $this->assertContains(
245
            ' changed to "Processing"',
246
            $log_order_status_processing->Title,
247
            "Processing title is recorded"
248
        );
249
        $this->assertEmailSent(
250
            "[email protected]",
251
            "[email protected]",
252
            _t('ShopEmail.StatusChangeSubject') . $log_order_status_processing->Title
253
        );
254
    }
255
}
256