Complex classes like OrderSpec often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use OrderSpec, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 35 | final class OrderSpec extends ObjectBehavior  | 
            ||
| 36 | { | 
            ||
| 37 | function it_implements_an_order_interface(): void  | 
            ||
| 38 |     { | 
            ||
| 39 | $this->shouldImplement(OrderInterface::class);  | 
            ||
| 40 | }  | 
            ||
| 41 | |||
| 42 | function it_extends_an_order(): void  | 
            ||
| 43 |     { | 
            ||
| 44 | $this->shouldHaveType(BaseOrder::class);  | 
            ||
| 45 | }  | 
            ||
| 46 | |||
| 47 | function it_does_not_have_a_customer_defined_by_default(): void  | 
            ||
| 48 |     { | 
            ||
| 49 | $this->getCustomer()->shouldReturn(null);  | 
            ||
| 50 | }  | 
            ||
| 51 | |||
| 52 | function its_allows_defining_customer(CustomerInterface $customer): void  | 
            ||
| 53 |     { | 
            ||
| 54 | $this->setCustomer($customer);  | 
            ||
| 55 | $this->getCustomer()->shouldReturn($customer);  | 
            ||
| 56 | }  | 
            ||
| 57 | |||
| 58 | function its_channel_is_mutable(ChannelInterface $channel): void  | 
            ||
| 59 |     { | 
            ||
| 60 | $this->setChannel($channel);  | 
            ||
| 61 | $this->getChannel()->shouldReturn($channel);  | 
            ||
| 62 | }  | 
            ||
| 63 | |||
| 64 | function it_does_not_have_shipping_address_by_default(): void  | 
            ||
| 65 |     { | 
            ||
| 66 | $this->getShippingAddress()->shouldReturn(null);  | 
            ||
| 67 | }  | 
            ||
| 68 | |||
| 69 | function it_allows_defining_shipping_address(AddressInterface $address): void  | 
            ||
| 70 |     { | 
            ||
| 71 | $this->setShippingAddress($address);  | 
            ||
| 72 | $this->getShippingAddress()->shouldReturn($address);  | 
            ||
| 73 | }  | 
            ||
| 74 | |||
| 75 | function it_does_not_have_billing_address_by_default(): void  | 
            ||
| 76 |     { | 
            ||
| 77 | $this->getBillingAddress()->shouldReturn(null);  | 
            ||
| 78 | }  | 
            ||
| 79 | |||
| 80 | function it_allows_defining_billing_address(AddressInterface $address): void  | 
            ||
| 81 |     { | 
            ||
| 82 | $this->setBillingAddress($address);  | 
            ||
| 83 | $this->getBillingAddress()->shouldReturn($address);  | 
            ||
| 84 | }  | 
            ||
| 85 | |||
| 86 | function its_checkout_state_is_mutable(): void  | 
            ||
| 87 |     { | 
            ||
| 88 | $this->setCheckoutState(OrderCheckoutStates::STATE_CART);  | 
            ||
| 89 | $this->getCheckoutState()->shouldReturn(OrderCheckoutStates::STATE_CART);  | 
            ||
| 90 | }  | 
            ||
| 91 | |||
| 92 | function its_payment_state_is_mutable(): void  | 
            ||
| 93 |     { | 
            ||
| 94 | $this->setPaymentState(PaymentInterface::STATE_COMPLETED);  | 
            ||
| 95 | $this->getPaymentState()->shouldReturn(PaymentInterface::STATE_COMPLETED);  | 
            ||
| 96 | }  | 
            ||
| 97 | |||
| 98 | function it_initializes_item_units_collection_by_default(): void  | 
            ||
| 99 |     { | 
            ||
| 100 | $this->getItemUnits()->shouldHaveType(Collection::class);  | 
            ||
| 101 | }  | 
            ||
| 102 | |||
| 103 | function it_initializes_shipments_collection_by_default(): void  | 
            ||
| 104 |     { | 
            ||
| 105 | $this->getShipments()->shouldHaveType(Collection::class);  | 
            ||
| 106 | }  | 
            ||
| 107 | |||
| 108 | function it_adds_shipment_properly(ShipmentInterface $shipment): void  | 
            ||
| 109 |     { | 
            ||
| 110 | $this->shouldNotHaveShipment($shipment);  | 
            ||
| 111 | |||
| 112 | $shipment->setOrder($this)->shouldBeCalled();  | 
            ||
| 113 | $this->addShipment($shipment);  | 
            ||
| 114 | |||
| 115 | $this->shouldHaveShipment($shipment);  | 
            ||
| 116 | }  | 
            ||
| 117 | |||
| 118 | function it_removes_a_shipment_properly(ShipmentInterface $shipment): void  | 
            ||
| 119 |     { | 
            ||
| 120 | $shipment->setOrder($this)->shouldBeCalled();  | 
            ||
| 121 | $this->addShipment($shipment);  | 
            ||
| 122 | |||
| 123 | $this->shouldHaveShipment($shipment);  | 
            ||
| 124 | |||
| 125 | $shipment->setOrder(null)->shouldBeCalled();  | 
            ||
| 126 | $this->removeShipment($shipment);  | 
            ||
| 127 | |||
| 128 | $this->shouldNotHaveShipment($shipment);  | 
            ||
| 129 | }  | 
            ||
| 130 | |||
| 131 | function it_removes_shipments(ShipmentInterface $shipment): void  | 
            ||
| 132 |     { | 
            ||
| 133 | $this->addShipment($shipment);  | 
            ||
| 134 | $this->hasShipment($shipment)->shouldReturn(true);  | 
            ||
| 135 | |||
| 136 | $this->removeShipments();  | 
            ||
| 137 | |||
| 138 | $this->hasShipment($shipment)->shouldReturn(false);  | 
            ||
| 139 | }  | 
            ||
| 140 | |||
| 141 | function it_returns_shipping_adjustments(  | 
            ||
| 142 | AdjustmentInterface $shippingAdjustment,  | 
            ||
| 143 | AdjustmentInterface $taxAdjustment  | 
            ||
| 144 |     ): void { | 
            ||
| 145 | $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT);  | 
            ||
| 146 | $shippingAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 147 | $shippingAdjustment->isNeutral()->willReturn(true);  | 
            ||
| 148 | |||
| 149 | $taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT);  | 
            ||
| 150 | $taxAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 151 | $taxAdjustment->isNeutral()->willReturn(true);  | 
            ||
| 152 | |||
| 153 | $this->addAdjustment($shippingAdjustment);  | 
            ||
| 154 | $this->addAdjustment($taxAdjustment);  | 
            ||
| 155 | |||
| 156 | $this->getAdjustments()->count()->shouldReturn(2);  | 
            ||
| 157 | |||
| 158 | $shippingAdjustments = $this->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT);  | 
            ||
| 159 | $shippingAdjustments->count()->shouldReturn(1);  | 
            ||
| 160 | $shippingAdjustments->first()->shouldReturn($shippingAdjustment);  | 
            ||
| 161 | }  | 
            ||
| 162 | |||
| 163 | function it_removes_shipping_adjustments(  | 
            ||
| 164 | AdjustmentInterface $shippingAdjustment,  | 
            ||
| 165 | AdjustmentInterface $taxAdjustment  | 
            ||
| 166 |     ): void { | 
            ||
| 167 | $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT);  | 
            ||
| 168 | $shippingAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 169 | $shippingAdjustment->isNeutral()->willReturn(true);  | 
            ||
| 170 | |||
| 171 | $taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT);  | 
            ||
| 172 | $taxAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 173 | $taxAdjustment->isNeutral()->willReturn(true);  | 
            ||
| 174 | |||
| 175 | $this->addAdjustment($shippingAdjustment);  | 
            ||
| 176 | $this->addAdjustment($taxAdjustment);  | 
            ||
| 177 | |||
| 178 | $this->getAdjustments()->count()->shouldReturn(2);  | 
            ||
| 179 | |||
| 180 | $shippingAdjustment->isLocked()->willReturn(false);  | 
            ||
| 181 | $shippingAdjustment->setAdjustable(null)->shouldBeCalled();  | 
            ||
| 182 | $this->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT);  | 
            ||
| 183 | |||
| 184 | $this->getAdjustments()->count()->shouldReturn(1);  | 
            ||
| 185 | $this->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->count()->shouldReturn(0);  | 
            ||
| 186 | }  | 
            ||
| 187 | |||
| 188 | function it_returns_tax_adjustments(  | 
            ||
| 189 | AdjustmentInterface $shippingAdjustment,  | 
            ||
| 190 | AdjustmentInterface $taxAdjustment  | 
            ||
| 191 |     ): void { | 
            ||
| 192 | $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT);  | 
            ||
| 193 | $shippingAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 194 | $shippingAdjustment->isNeutral()->willReturn(true);  | 
            ||
| 195 | |||
| 196 | $taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT);  | 
            ||
| 197 | $taxAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 198 | $taxAdjustment->isNeutral()->willReturn(true);  | 
            ||
| 199 | |||
| 200 | $this->addAdjustment($shippingAdjustment);  | 
            ||
| 201 | $this->addAdjustment($taxAdjustment);  | 
            ||
| 202 | |||
| 203 | $this->getAdjustments()->count()->shouldReturn(2);  | 
            ||
| 204 | |||
| 205 | $taxAdjustments = $this->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);  | 
            ||
| 206 | $taxAdjustments->count()->shouldReturn(1);  | 
            ||
| 207 | $taxAdjustments->first()->shouldReturn($taxAdjustment);  | 
            ||
| 208 | }  | 
            ||
| 209 | |||
| 210 | function it_removes_tax_adjustments(  | 
            ||
| 211 | AdjustmentInterface $shippingAdjustment,  | 
            ||
| 212 | AdjustmentInterface $taxAdjustment  | 
            ||
| 213 |     ): void { | 
            ||
| 214 | $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT);  | 
            ||
| 215 | $shippingAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 216 | $shippingAdjustment->isNeutral()->willReturn(true);  | 
            ||
| 217 | |||
| 218 | $taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT);  | 
            ||
| 219 | $taxAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 220 | $taxAdjustment->isNeutral()->willReturn(true);  | 
            ||
| 221 | |||
| 222 | $this->addAdjustment($shippingAdjustment);  | 
            ||
| 223 | $this->addAdjustment($taxAdjustment);  | 
            ||
| 224 | |||
| 225 | $this->getAdjustments()->count()->shouldReturn(2);  | 
            ||
| 226 | |||
| 227 | $taxAdjustment->isLocked()->willReturn(false);  | 
            ||
| 228 | $taxAdjustment->setAdjustable(null)->shouldBeCalled();  | 
            ||
| 229 | $this->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);  | 
            ||
| 230 | |||
| 231 | $this->getAdjustments()->count()->shouldReturn(1);  | 
            ||
| 232 | $this->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->count()->shouldReturn(0);  | 
            ||
| 233 | }  | 
            ||
| 234 | |||
| 235 | function it_does_not_have_a_currency_code_defined_by_default(): void  | 
            ||
| 236 |     { | 
            ||
| 237 | $this->getCurrencyCode()->shouldReturn(null);  | 
            ||
| 238 | }  | 
            ||
| 239 | |||
| 240 | function it_allows_defining_a_currency_code(): void  | 
            ||
| 241 |     { | 
            ||
| 242 |         $this->setCurrencyCode('PLN'); | 
            ||
| 243 |         $this->getCurrencyCode()->shouldReturn('PLN'); | 
            ||
| 244 | }  | 
            ||
| 245 | |||
| 246 | function it_has_no_default_locale_code(): void  | 
            ||
| 247 |     { | 
            ||
| 248 | $this->getLocaleCode()->shouldReturn(null);  | 
            ||
| 249 | }  | 
            ||
| 250 | |||
| 251 | function its_locale_code_is_mutable(): void  | 
            ||
| 252 |     { | 
            ||
| 253 |         $this->setLocaleCode('en'); | 
            ||
| 254 |         $this->getLocaleCode()->shouldReturn('en'); | 
            ||
| 255 | }  | 
            ||
| 256 | |||
| 257 | function it_has_a_cart_shipping_state_by_default(): void  | 
            ||
| 258 |     { | 
            ||
| 259 | $this->getShippingState()->shouldReturn(OrderShippingStates::STATE_CART);  | 
            ||
| 260 | }  | 
            ||
| 261 | |||
| 262 | function its_shipping_state_is_mutable(): void  | 
            ||
| 263 |     { | 
            ||
| 264 | $this->setShippingState(OrderShippingStates::STATE_SHIPPED);  | 
            ||
| 265 | $this->getShippingState()->shouldReturn(OrderShippingStates::STATE_SHIPPED);  | 
            ||
| 266 | }  | 
            ||
| 267 | |||
| 268 | function it_adds_and_removes_payments(PaymentInterface $payment): void  | 
            ||
| 269 |     { | 
            ||
| 270 | $payment->getState()->willReturn(PaymentInterface::STATE_NEW);  | 
            ||
| 271 | $payment->setOrder($this)->shouldBeCalled();  | 
            ||
| 272 | |||
| 273 | $this->addPayment($payment);  | 
            ||
| 274 | $this->shouldHavePayment($payment);  | 
            ||
| 275 | |||
| 276 | $payment->setOrder(null)->shouldBeCalled();  | 
            ||
| 277 | |||
| 278 | $this->removePayment($payment);  | 
            ||
| 279 | $this->shouldNotHavePayment($payment);  | 
            ||
| 280 | }  | 
            ||
| 281 | |||
| 282 | function it_returns_last_payment_with_given_state(  | 
            ||
| 283 | PaymentInterface $payment1,  | 
            ||
| 284 | PaymentInterface $payment2,  | 
            ||
| 285 | PaymentInterface $payment3,  | 
            ||
| 286 | PaymentInterface $payment4  | 
            ||
| 287 |     ): void { | 
            ||
| 288 | $payment1->getState()->willReturn(PaymentInterface::STATE_CART);  | 
            ||
| 289 | $payment1->setOrder($this)->shouldBeCalled();  | 
            ||
| 290 | |||
| 291 | $payment2->getState()->willReturn(PaymentInterface::STATE_CANCELLED);  | 
            ||
| 292 | $payment2->setOrder($this)->shouldBeCalled();  | 
            ||
| 293 | |||
| 294 | $payment3->getState()->willReturn(PaymentInterface::STATE_PROCESSING);  | 
            ||
| 295 | $payment3->setOrder($this)->shouldBeCalled();  | 
            ||
| 296 | |||
| 297 | $payment4->getState()->willReturn(PaymentInterface::STATE_FAILED);  | 
            ||
| 298 | $payment4->setOrder($this)->shouldBeCalled();  | 
            ||
| 299 | |||
| 300 | $this->addPayment($payment1);  | 
            ||
| 301 | $this->addPayment($payment2);  | 
            ||
| 302 | $this->addPayment($payment3);  | 
            ||
| 303 | $this->addPayment($payment4);  | 
            ||
| 304 | |||
| 305 | $this->getLastPayment(OrderInterface::STATE_CART)->shouldReturn($payment1);  | 
            ||
| 306 | }  | 
            ||
| 307 | |||
| 308 | function it_returns_a_null_if_there_is_no_payments_after_trying_to_get_last_payment(): void  | 
            ||
| 309 |     { | 
            ||
| 310 | $this->getLastPayment(OrderInterface::STATE_CART)->shouldReturn(null);  | 
            ||
| 311 | }  | 
            ||
| 312 | |||
| 313 | function it_returns_last_payment_with_any_state_if_there_is_no_target_state_specified(  | 
            ||
| 314 | PaymentInterface $payment1,  | 
            ||
| 315 | PaymentInterface $payment2,  | 
            ||
| 316 | PaymentInterface $payment3,  | 
            ||
| 317 | PaymentInterface $payment4  | 
            ||
| 318 |     ): void { | 
            ||
| 319 | $payment1->getState()->willReturn(PaymentInterface::STATE_CART);  | 
            ||
| 320 | $payment1->setOrder($this)->shouldBeCalled();  | 
            ||
| 321 | |||
| 322 | $payment2->getState()->willReturn(PaymentInterface::STATE_CANCELLED);  | 
            ||
| 323 | $payment2->setOrder($this)->shouldBeCalled();  | 
            ||
| 324 | |||
| 325 | $payment3->getState()->willReturn(PaymentInterface::STATE_PROCESSING);  | 
            ||
| 326 | $payment3->setOrder($this)->shouldBeCalled();  | 
            ||
| 327 | |||
| 328 | $payment4->getState()->willReturn(PaymentInterface::STATE_FAILED);  | 
            ||
| 329 | $payment4->setOrder($this)->shouldBeCalled();  | 
            ||
| 330 | |||
| 331 | $this->addPayment($payment1);  | 
            ||
| 332 | $this->addPayment($payment2);  | 
            ||
| 333 | $this->addPayment($payment3);  | 
            ||
| 334 | $this->addPayment($payment4);  | 
            ||
| 335 | |||
| 336 | $this->getLastPayment()->shouldReturn($payment4);  | 
            ||
| 337 | }  | 
            ||
| 338 | |||
| 339 | function it_adds_and_removes_shipments(ShipmentInterface $shipment): void  | 
            ||
| 340 |     { | 
            ||
| 341 | $shipment->setOrder($this)->shouldBeCalled();  | 
            ||
| 342 | |||
| 343 | $this->addShipment($shipment);  | 
            ||
| 344 | $this->shouldHaveShipment($shipment);  | 
            ||
| 345 | |||
| 346 | $shipment->setOrder(null)->shouldBeCalled();  | 
            ||
| 347 | |||
| 348 | $this->removeShipment($shipment);  | 
            ||
| 349 | $this->shouldNotHaveShipment($shipment);  | 
            ||
| 350 | }  | 
            ||
| 351 | |||
| 352 | function it_has_a_promotion_coupon(PromotionCouponInterface $coupon): void  | 
            ||
| 353 |     { | 
            ||
| 354 | $this->setPromotionCoupon($coupon);  | 
            ||
| 355 | $this->getPromotionCoupon()->shouldReturn($coupon);  | 
            ||
| 356 | }  | 
            ||
| 357 | |||
| 358 | function it_counts_promotions_subjects(OrderItemInterface $item1, OrderItemInterface $item2): void  | 
            ||
| 359 |     { | 
            ||
| 360 | $item1->getQuantity()->willReturn(4);  | 
            ||
| 361 | $item1->getTotal()->willReturn(420);  | 
            ||
| 362 |         $item1->setOrder($this)->will(function () {}); | 
            ||
| 363 | |||
| 364 | $item2->getQuantity()->willReturn(3);  | 
            ||
| 365 | $item2->getTotal()->willReturn(666);  | 
            ||
| 366 |         $item2->setOrder($this)->will(function () {}); | 
            ||
| 367 | |||
| 368 | $this->addItem($item1);  | 
            ||
| 369 | $this->addItem($item2);  | 
            ||
| 370 | |||
| 371 | $this->getPromotionSubjectCount()->shouldReturn(7);  | 
            ||
| 372 | }  | 
            ||
| 373 | |||
| 374 | function it_adds_and_removes_promotions(PromotionInterface $promotion): void  | 
            ||
| 382 | |||
| 383 | function it_returns_0_tax_total_when_there_are_no_items_and_adjustments(): void  | 
            ||
| 387 | |||
| 388 | function it_returns_a_tax_of_all_items_as_tax_total_when_there_are_no_tax_adjustments(  | 
            ||
| 389 | OrderItemInterface $orderItem1,  | 
            ||
| 390 | OrderItemInterface $orderItem2  | 
            ||
| 391 |     ): void { | 
            ||
| 392 | $orderItem1->getTotal()->willReturn(1100);  | 
            ||
| 393 | $orderItem1->getTaxTotal()->willReturn(100);  | 
            ||
| 394 | $orderItem2->getTotal()->willReturn(1050);  | 
            ||
| 395 | $orderItem2->getTaxTotal()->willReturn(50);  | 
            ||
| 396 | |||
| 397 | $orderItem1->setOrder($this)->shouldBeCalled();  | 
            ||
| 398 | $orderItem2->setOrder($this)->shouldBeCalled();  | 
            ||
| 399 | $this->addItem($orderItem1);  | 
            ||
| 400 | $this->addItem($orderItem2);  | 
            ||
| 401 | |||
| 402 | $this->getTaxTotal()->shouldReturn(150);  | 
            ||
| 403 | }  | 
            ||
| 404 | |||
| 405 | function it_returns_a_tax_of_all_items_and_non_neutral_shipping_tax_as_tax_total(  | 
            ||
| 406 | OrderItemInterface $orderItem1,  | 
            ||
| 407 | OrderItemInterface $orderItem2,  | 
            ||
| 408 | AdjustmentInterface $shippingAdjustment,  | 
            ||
| 409 | AdjustmentInterface $shippingTaxAdjustment  | 
            ||
| 410 |     ): void { | 
            ||
| 411 | $orderItem1->getTotal()->willReturn(1100);  | 
            ||
| 412 | $orderItem1->getTaxTotal()->willReturn(100);  | 
            ||
| 413 | $orderItem2->getTotal()->willReturn(1050);  | 
            ||
| 414 | $orderItem2->getTaxTotal()->willReturn(50);  | 
            ||
| 415 | |||
| 416 | $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT);  | 
            ||
| 417 | $shippingAdjustment->isNeutral()->willReturn(false);  | 
            ||
| 418 | $shippingAdjustment->getAmount()->willReturn(1000);  | 
            ||
| 419 | $shippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT);  | 
            ||
| 420 | $shippingTaxAdjustment->isNeutral()->willReturn(false);  | 
            ||
| 421 | $shippingTaxAdjustment->getAmount()->willReturn(70);  | 
            ||
| 422 | |||
| 423 | $orderItem1->setOrder($this)->shouldBeCalled();  | 
            ||
| 424 | $orderItem2->setOrder($this)->shouldBeCalled();  | 
            ||
| 425 | $this->addItem($orderItem1);  | 
            ||
| 426 | $this->addItem($orderItem2);  | 
            ||
| 427 | |||
| 428 | $shippingAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 429 | $this->addAdjustment($shippingAdjustment);  | 
            ||
| 430 | |||
| 431 | $shippingTaxAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 432 | $this->addAdjustment($shippingTaxAdjustment);  | 
            ||
| 433 | |||
| 434 | $this->getTaxTotal()->shouldReturn(220);  | 
            ||
| 435 | }  | 
            ||
| 436 | |||
| 437 | function it_returns_a_tax_of_all_items_and_neutral_shipping_tax_as_tax_total(  | 
            ||
| 438 | OrderItemInterface $orderItem1,  | 
            ||
| 439 | OrderItemInterface $orderItem2,  | 
            ||
| 440 | AdjustmentInterface $shippingAdjustment,  | 
            ||
| 441 | AdjustmentInterface $shippingTaxAdjustment  | 
            ||
| 442 |     ): void { | 
            ||
| 443 | $orderItem1->getTotal()->willReturn(1100);  | 
            ||
| 444 | $orderItem1->getTaxTotal()->willReturn(100);  | 
            ||
| 445 | $orderItem2->getTotal()->willReturn(1050);  | 
            ||
| 446 | $orderItem2->getTaxTotal()->willReturn(50);  | 
            ||
| 447 | |||
| 448 | $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT);  | 
            ||
| 449 | $shippingAdjustment->isNeutral()->willReturn(false);  | 
            ||
| 450 | $shippingAdjustment->getAmount()->willReturn(1000);  | 
            ||
| 451 | |||
| 452 | $shippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT);  | 
            ||
| 453 | $shippingTaxAdjustment->isNeutral()->willReturn(true);  | 
            ||
| 454 | $shippingTaxAdjustment->getAmount()->willReturn(70);  | 
            ||
| 455 | |||
| 456 | $orderItem1->setOrder($this)->shouldBeCalled();  | 
            ||
| 457 | $orderItem2->setOrder($this)->shouldBeCalled();  | 
            ||
| 458 | $this->addItem($orderItem1);  | 
            ||
| 459 | $this->addItem($orderItem2);  | 
            ||
| 460 | |||
| 461 | $shippingAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 462 | $shippingTaxAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 463 | $this->addAdjustment($shippingAdjustment);  | 
            ||
| 464 | $this->addAdjustment($shippingTaxAdjustment);  | 
            ||
| 465 | |||
| 466 | $this->getTaxTotal()->shouldReturn(220);  | 
            ||
| 467 | }  | 
            ||
| 468 | |||
| 469 | function it_includes_a_non_neutral_tax_adjustments_in_shipping_total(  | 
            ||
| 470 | AdjustmentInterface $shippingAdjustment,  | 
            ||
| 471 | AdjustmentInterface $shippingTaxAdjustment  | 
            ||
| 472 |     ): void { | 
            ||
| 473 | $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT);  | 
            ||
| 474 | $shippingAdjustment->isNeutral()->willReturn(false);  | 
            ||
| 475 | $shippingAdjustment->getAmount()->willReturn(1000);  | 
            ||
| 476 | |||
| 477 | $shippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT);  | 
            ||
| 478 | $shippingTaxAdjustment->isNeutral()->willReturn(false);  | 
            ||
| 479 | $shippingTaxAdjustment->getAmount()->willReturn(70);  | 
            ||
| 480 | |||
| 481 | $shippingAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 482 | $shippingTaxAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 483 | $this->addAdjustment($shippingAdjustment);  | 
            ||
| 484 | $this->addAdjustment($shippingTaxAdjustment);  | 
            ||
| 485 | |||
| 486 | $this->getShippingTotal()->shouldReturn(1070);  | 
            ||
| 487 | }  | 
            ||
| 488 | |||
| 489 | function it_returns_a_shipping_total_decreased_by_shipping_promotion(  | 
            ||
| 490 | AdjustmentInterface $shippingAdjustment,  | 
            ||
| 491 | AdjustmentInterface $shippingTaxAdjustment,  | 
            ||
| 492 | AdjustmentInterface $shippingPromotionAdjustment  | 
            ||
| 493 |     ): void { | 
            ||
| 494 | $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT);  | 
            ||
| 495 | $shippingAdjustment->isNeutral()->willReturn(false);  | 
            ||
| 496 | $shippingAdjustment->getAmount()->willReturn(1000);  | 
            ||
| 497 | |||
| 498 | $shippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT);  | 
            ||
| 499 | $shippingTaxAdjustment->isNeutral()->willReturn(false);  | 
            ||
| 500 | $shippingTaxAdjustment->getAmount()->willReturn(70);  | 
            ||
| 501 | |||
| 502 | $shippingPromotionAdjustment->getType()->willReturn(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT);  | 
            ||
| 503 | $shippingPromotionAdjustment->isNeutral()->willReturn(false);  | 
            ||
| 504 | $shippingPromotionAdjustment->getAmount()->willReturn(-100);  | 
            ||
| 505 | |||
| 506 | $shippingAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 507 | $shippingTaxAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 508 | $shippingPromotionAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 509 | $this->addAdjustment($shippingAdjustment);  | 
            ||
| 510 | $this->addAdjustment($shippingTaxAdjustment);  | 
            ||
| 511 | $this->addAdjustment($shippingPromotionAdjustment);  | 
            ||
| 512 | |||
| 513 | $this->getShippingTotal()->shouldReturn(970);  | 
            ||
| 514 | }  | 
            ||
| 515 | |||
| 516 | function it_does_not_include_neutral_tax_adjustments_in_shipping_total(  | 
            ||
| 517 | AdjustmentInterface $shippingAdjustment,  | 
            ||
| 518 | AdjustmentInterface $neutralShippingTaxAdjustment  | 
            ||
| 519 |     ): void { | 
            ||
| 520 | $shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT);  | 
            ||
| 521 | $shippingAdjustment->isNeutral()->willReturn(false);  | 
            ||
| 522 | $shippingAdjustment->getAmount()->willReturn(1000);  | 
            ||
| 523 | |||
| 524 | $neutralShippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT);  | 
            ||
| 525 | $neutralShippingTaxAdjustment->isNeutral()->willReturn(true);  | 
            ||
| 526 | $neutralShippingTaxAdjustment->getAmount()->willReturn(70);  | 
            ||
| 527 | |||
| 528 | $shippingAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 529 | $neutralShippingTaxAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 530 | $this->addAdjustment($shippingAdjustment);  | 
            ||
| 531 | $this->addAdjustment($neutralShippingTaxAdjustment);  | 
            ||
| 532 | |||
| 533 | $this->getShippingTotal()->shouldReturn(1000);  | 
            ||
| 534 | }  | 
            ||
| 535 | |||
| 536 | function it_returns_0_as_promotion_total_when_there_are_no_order_promotion_adjustments(): void  | 
            ||
| 540 | |||
| 541 | function it_returns_a_sum_of_all_order_promotion_adjustments_applied_to_items_as_order_promotion_total(  | 
            ||
| 542 | OrderItemInterface $orderItem1,  | 
            ||
| 543 | OrderItemInterface $orderItem2  | 
            ||
| 544 |     ): void { | 
            ||
| 545 | $orderItem1->getTotal()->willReturn(500);  | 
            ||
| 546 | $orderItem2->getTotal()->willReturn(300);  | 
            ||
| 547 | |||
| 548 | $orderItem1->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn(-400);  | 
            ||
| 549 | $orderItem2->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn(-600);  | 
            ||
| 550 | |||
| 551 | $orderItem1->setOrder($this)->shouldBeCalled();  | 
            ||
| 552 | $orderItem2->setOrder($this)->shouldBeCalled();  | 
            ||
| 553 | $this->addItem($orderItem1);  | 
            ||
| 554 | $this->addItem($orderItem2);  | 
            ||
| 555 | |||
| 556 | $this->getOrderPromotionTotal()->shouldReturn(-1000);  | 
            ||
| 557 | }  | 
            ||
| 558 | |||
| 559 | function it_does_not_include_a_shipping_promotion_adjustment_in_order_promotion_total(  | 
            ||
| 560 | AdjustmentInterface $shippingPromotionAdjustment,  | 
            ||
| 561 | OrderItemInterface $orderItem1  | 
            ||
| 562 |     ): void { | 
            ||
| 563 | $orderItem1->getTotal()->willReturn(500);  | 
            ||
| 564 | $orderItem1->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn(-400);  | 
            ||
| 565 | |||
| 566 | $shippingPromotionAdjustment->getType()->willReturn(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT);  | 
            ||
| 567 | $shippingPromotionAdjustment->isNeutral()->willReturn(false);  | 
            ||
| 568 | $shippingPromotionAdjustment->getAmount()->willReturn(-100);  | 
            ||
| 569 | |||
| 570 | $orderItem1->setOrder($this)->shouldBeCalled();  | 
            ||
| 571 | $this->addItem($orderItem1);  | 
            ||
| 572 | |||
| 573 | $shippingPromotionAdjustment->setAdjustable($this)->shouldBeCalled();  | 
            ||
| 574 | $this->addAdjustment($shippingPromotionAdjustment);  | 
            ||
| 575 | |||
| 576 | $this->getOrderPromotionTotal()->shouldReturn(-400);  | 
            ||
| 577 | }  | 
            ||
| 578 | |||
| 579 | function it_has_a_token_value(): void  | 
            ||
| 585 | |||
| 586 | function it_has_customer_ip(): void  | 
            ||
| 591 | }  | 
            ||
| 592 |