| Conditions | 1 |
| Paths | 1 |
| Total Lines | 171 |
| Code Lines | 128 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 36 | public function testOrderStatusLogItemsWithMember() |
||
| 37 | { |
||
| 38 | // start a new order |
||
| 39 | $order = $this->objFromFixture(Order::class, "cart1"); |
||
| 40 | $member = $this->objFromFixture(Member::class, 'jeremyperemy'); |
||
| 41 | $order->MemberID = $member->ID; |
||
| 42 | |||
| 43 | $no_log_generated_with_order_status_cart = OrderStatusLog::get()->sort('ID')->last(); |
||
| 44 | $this->assertNull( |
||
| 45 | $no_log_generated_with_order_status_cart, |
||
| 46 | "no log generated with Status of 'Cart'" |
||
| 47 | ); |
||
| 48 | |||
| 49 | $order->Status = "Unpaid"; |
||
| 50 | $order->write(); |
||
| 51 | |||
| 52 | $no_log_generated_with_order_status_unpaid = OrderStatusLog::get()->sort('ID')->last(); |
||
| 53 | $this->assertNull( |
||
| 54 | $no_log_generated_with_order_status_unpaid, |
||
| 55 | "no log generated with Status of 'Unpaid'" |
||
| 56 | ); |
||
| 57 | |||
| 58 | $processor = OrderProcessor::create($order); |
||
| 59 | $response = $processor->makePayment("Manual", array()); |
||
|
|
|||
| 60 | $order->Status = "Paid"; |
||
| 61 | $order->write(); |
||
| 62 | |||
| 63 | $log_order_status_paid = OrderStatusLog::get()->sort('ID')->last(); |
||
| 64 | $this->assertNull( |
||
| 65 | $log_order_status_paid, |
||
| 66 | "no log generated with Status of 'Unpaid'" |
||
| 67 | ); |
||
| 68 | |||
| 69 | $order->Status = "Processing"; |
||
| 70 | $order->write(); |
||
| 71 | |||
| 72 | $log_order_status_processing = OrderStatusLog::get()->sort('ID')->last(); |
||
| 73 | $this->assertEquals(OrderStatusLog::get()->count(), '1', "One items in the OrderStatusLog"); |
||
| 74 | $this->assertNotNull( |
||
| 75 | $log_order_status_processing, |
||
| 76 | "a log when changing to 'Processing' status (and PaymentMethod is 'Manual')" |
||
| 77 | ); |
||
| 78 | $this->assertSame( |
||
| 79 | $log_order_status_processing->Order()->ID, |
||
| 80 | $order->ID, |
||
| 81 | "Log conatins an Order" |
||
| 82 | ); |
||
| 83 | |||
| 84 | $this->assertContains( |
||
| 85 | "Processing", |
||
| 86 | $log_order_status_processing->Note, |
||
| 87 | "Processing note is recorded" |
||
| 88 | ); |
||
| 89 | $this->assertContains( |
||
| 90 | 'changed to "Processing"', |
||
| 91 | $log_order_status_processing->Title, |
||
| 92 | 'Processing title is recorded' |
||
| 93 | ); |
||
| 94 | $this->assertEmailSent( |
||
| 95 | '[email protected]', |
||
| 96 | '[email protected]', |
||
| 97 | 'Silvershop - ' . $log_order_status_processing->Title |
||
| 98 | ); |
||
| 99 | $order->Status = "Sent"; |
||
| 100 | $order->write(); |
||
| 101 | |||
| 102 | $log_order_status_sent = OrderStatusLog::get()->sort('ID')->last(); |
||
| 103 | $this->assertEquals( |
||
| 104 | OrderStatusLog::get()->count(), |
||
| 105 | '2', |
||
| 106 | "Three items in the OrderStatusLog" |
||
| 107 | ); |
||
| 108 | $this->assertNotNull( |
||
| 109 | $log_order_status_sent, |
||
| 110 | "an log should be recorded when an order's status is changed to 'Sent' (and PaymentMethod is 'Manual')" |
||
| 111 | ); |
||
| 112 | $this->assertSame( |
||
| 113 | $log_order_status_sent->Order()->ID, |
||
| 114 | $order->ID, |
||
| 115 | "Log conatins an Order" |
||
| 116 | ); |
||
| 117 | $this->assertContains( |
||
| 118 | "sent", |
||
| 119 | $log_order_status_sent->Note, |
||
| 120 | "Sent note is recorded" |
||
| 121 | ); |
||
| 122 | $this->assertContains( |
||
| 123 | 'changed to "Sent"', |
||
| 124 | $log_order_status_sent->Title, |
||
| 125 | "Sent title is recorded" |
||
| 126 | ); |
||
| 127 | |||
| 128 | $this->assertEmailSent( |
||
| 129 | "[email protected]", |
||
| 130 | "[email protected]", |
||
| 131 | 'Silvershop - ' . $log_order_status_sent->Title |
||
| 132 | ); |
||
| 133 | |||
| 134 | $order->Status = "Complete"; |
||
| 135 | $order->write(); |
||
| 136 | $this->assertEquals( |
||
| 137 | OrderStatusLog::get()->count(), |
||
| 138 | '2', |
||
| 139 | "Additional item in the OrderStatusLog has not been created" |
||
| 140 | ); |
||
| 141 | |||
| 142 | $order->Status = "AdminCancelled"; |
||
| 143 | $order->write(); |
||
| 144 | |||
| 145 | $log_order_status_admin_cancelled = OrderStatusLog::get()->sort('ID')->last(); |
||
| 146 | $this->assertEquals( |
||
| 147 | OrderStatusLog::get()->count(), |
||
| 148 | '3', |
||
| 149 | "Three items in the OrderStatusLog" |
||
| 150 | ); |
||
| 151 | $this->assertNotNull( |
||
| 152 | $log_order_status_admin_cancelled, |
||
| 153 | "a log should be recorded with change to 'Admin Cancelled' status (and PaymentMethod is 'Manual')" |
||
| 154 | ); |
||
| 155 | $this->assertSame( |
||
| 156 | $log_order_status_admin_cancelled->Order()->ID, |
||
| 157 | $order->ID, |
||
| 158 | "Log conatins an Order" |
||
| 159 | ); |
||
| 160 | $this->assertContains( |
||
| 161 | "cancelled", |
||
| 162 | $log_order_status_admin_cancelled->Note, |
||
| 163 | "Admin Cancelled note is recorded" |
||
| 164 | ); |
||
| 165 | $this->assertContains( |
||
| 166 | 'changed to "Cancelled by admin"', |
||
| 167 | $log_order_status_admin_cancelled->Title, |
||
| 168 | "Admin Cancelled title is recorded" |
||
| 169 | ); |
||
| 170 | $this->assertEmailSent( |
||
| 171 | "[email protected]", |
||
| 172 | "[email protected]", |
||
| 173 | 'Silvershop - ' . $log_order_status_admin_cancelled->Title |
||
| 174 | ); |
||
| 175 | |||
| 176 | $order->Status = "MemberCancelled"; |
||
| 177 | $order->write(); |
||
| 178 | $log_order_status_member_cancelled = OrderStatusLog::get()->sort('ID')->last(); |
||
| 179 | $this->assertEquals( |
||
| 180 | OrderStatusLog::get()->count(), |
||
| 181 | '4', |
||
| 182 | "Four items in the OrderStatusLog" |
||
| 183 | ); |
||
| 184 | $this->assertNotNull( |
||
| 185 | $log_order_status_member_cancelled, |
||
| 186 | "a log should be recorded for change to 'Member Cancelled' status (and PaymentMethod is 'Manual')" |
||
| 187 | ); |
||
| 188 | $this->assertSame( |
||
| 189 | $log_order_status_member_cancelled->Order()->ID, |
||
| 190 | $order->ID, |
||
| 191 | "Log conatins an Order" |
||
| 192 | ); |
||
| 193 | $this->assertSame( |
||
| 194 | "Your cancellation of the order has been noted. Please contact us if you have any questions.", |
||
| 195 | $log_order_status_member_cancelled->Note, |
||
| 196 | "Member Cancelled note is recorded" |
||
| 197 | ); |
||
| 198 | $this->assertContains( |
||
| 199 | ' changed to "Cancelled by member"', |
||
| 200 | $log_order_status_member_cancelled->Title, |
||
| 201 | "Member Cancelled title is recorded" |
||
| 202 | ); |
||
| 203 | $this->assertEmailSent( |
||
| 204 | '[email protected]', |
||
| 205 | '[email protected]', |
||
| 206 | 'Silvershop - ' . $log_order_status_member_cancelled->Title |
||
| 207 | ); |
||
| 345 |