/** * When getting an order address for an item, if the item does not yet have * a loaded order address instance, load a new one and return it. */ public function testGetOrderAddressMemoized() { $addressId = 3; $this->_item->setOrderAddressId($addressId); $address = Mage::getModel('sales/order_address'); // Side-effect test: ensure that the factory, which will load new // address instances for the item, is only invoked one time, no matter // how many times getOrderAddress is invoked. $this->_multishippingFactory->expects($this->once())->method('loadAddressForItem')->with($this->identicalTo($this->_item))->will($this->returnValue($address)); // Invoke getOrderAddress multiple times, the factory should still only // be invoked one time. $this->_item->getOrderAddress(); $this->_item->getOrderAddress(); }
/** * When getting an items collection for the address, if an order item * does not yet exist for the address, a new item collection should be * created and returned. */ public function testGetItemsCollection() { $itemCollection = $this->getResourceModelMockBuilder('sales/order_item_collection')->disableOriginalConstructor()->getMock(); $address = Mage::getModel('sales/order_address', ['multishipping_factory' => $this->_multishippingFactory]); // Mock the factory such that, if given the address, factory will return // the expected item collection. Expect that no matter how many times this // method is called, a new collection will only be created once. $this->_multishippingFactory->expects($this->once())->method('createItemCollectionForAddress')->with($this->identicalTo($address))->will($this->returnValue($itemCollection)); $this->assertSame($itemCollection, $address->getItemsCollection()); // Re-call to ensure that the item collection is stored and not // recreated each time it is requested. Factory's `once` invocation // matcher will ensure the method is only called the one time to create // a new item collection. $this->assertSame($itemCollection, $address->getItemsCollection()); }