/** * Returns array of items * * @param \Magento\Sales\Model\Order\Invoice $object * @return InvoiceItem[] */ protected function getItems(\Magento\Sales\Model\Order\Invoice $object) { $items = []; foreach ($object->getAllItems() as $item) { $items[] = $this->invoiceItemMapper->extractDto($item); } return $items; }
/** * Run invoice mapper test * * @return void */ public function testInvoke() { $this->invoiceMock->expects($this->once())->method('getData')->will($this->returnValue(['field-1' => 'value-1'])); $this->invoiceMock->expects($this->once())->method('getAllItems')->will($this->returnValue([$this->invoiceItemMock])); $this->invoiceBuilderMock->expects($this->once())->method('populateWithArray')->with($this->equalTo(['field-1' => 'value-1']))->will($this->returnSelf()); $this->invoiceItemMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->invoiceItemMock))->will($this->returnValue('item-1')); $this->invoiceBuilderMock->expects($this->once())->method('setItems')->with($this->equalTo(['item-1']))->will($this->returnSelf()); $this->invoiceBuilderMock->expects($this->once())->method('create')->will($this->returnValue('data-object-with-invoice')); $this->assertEquals('data-object-with-invoice', $this->invoiceMapper->extractDto($this->invoiceMock)); }