/** * @param int|null $id * @param int|null $entityId * @dataProvider getDataProvider */ public function testGet($id, $entityId) { if (!$id) { $this->setExpectedException('Magento\\Framework\\Exception\\InputException'); $this->subject->get($id); } else { $address = $this->getMock('Magento\\Sales\\Model\\Order\\Address', ['load', 'getEntityId'], [], '', false); $address->expects($this->once())->method('load')->with($id)->willReturn($address); $address->expects($this->once())->method('getEntityId')->willReturn($entityId); $this->metadata->expects($this->once())->method('getNewInstance')->willReturn($address); if (!$entityId) { $this->setExpectedException('Magento\\Framework\\Exception\\NoSuchEntityException'); $this->subject->get($id); } else { $this->assertEquals($address, $this->subject->get($id)); $address->expects($this->never())->method('load')->with($id)->willReturn($address); $address->expects($this->never())->method('getEntityId')->willReturn($entityId); $this->metadata->expects($this->never())->method('getNewInstance')->willReturn($address); // Retrieve Address from registry. $this->assertEquals($address, $this->subject->get($id)); } } }
/** * @param int|null $id * @param int|null $entityId * @dataProvider getDataProvider */ public function testGet($id, $entityId) { if (!$id) { $this->setExpectedException('Magento\\Framework\\Exception\\InputException'); $this->subject->get($id); } else { $address = $this->getMock('Magento\\Sales\\Model\\Order\\Address', ['getEntityId'], [], '', false); $address->expects($this->once())->method('getEntityId')->willReturn($entityId); $mapper = $this->getMockForAbstractClass('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb', [], '', false, true, true, ['load']); $mapper->expects($this->once())->method('load')->with($address, $id)->willReturnSelf(); $this->metadata->expects($this->once())->method('getNewInstance')->willReturn($address); $this->metadata->expects($this->once())->method('getMapper')->willReturn($mapper); if (!$entityId) { $this->setExpectedException('Magento\\Framework\\Exception\\NoSuchEntityException'); $this->subject->get($id); } else { $this->assertEquals($address, $this->subject->get($id)); $mapper->expects($this->never())->method('load'); $this->metadata->expects($this->never())->method('getNewInstance'); $this->metadata->expects($this->never())->method('getMapper'); $this->assertEquals($address, $this->subject->get($id)); } } }