/** * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function testGetItems() { $expectedResult = []; $linkTypeMocks = []; foreach ($this->linkTypes as $type => $typeCode) { $value = ['name' => $type, 'code' => $typeCode]; $linkTypeMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductLinkTypeInterface'); $linkTypeMock->expects($this->once())->method('setName')->with($type)->willReturnSelf(); $linkTypeMock->expects($this->once())->method('setCode')->with($typeCode)->willReturnSelf(); $linkTypeMocks[] = $linkTypeMock; $expectedResult[] = $linkTypeMock; } $this->linkTypeFactoryMock->expects($this->exactly(3))->method('create')->will($this->onConsecutiveCalls($linkTypeMocks[0], $linkTypeMocks[1], $linkTypeMocks[2])); $this->assertEquals($expectedResult, $this->model->getItems()); }
/** * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function testGetItems() { $expectedResult = []; $objectMocks = []; foreach ($this->linkTypes as $type => $typeCode) { $value = ['name' => $type, 'code' => $typeCode]; $objectMock = $this->getMock('\\Magento\\Framework\\Object', ['create'], [], '', false); $objectMock->expects($this->once())->method('create')->willReturn($value); $objectMocks[] = $objectMock; $expectedResult[] = $value; } $valueMap = function ($expectedResult, $objectMocks) { $output = []; foreach ($expectedResult as $key => $result) { $output[] = [$expectedResult[$key], $objectMocks[$key]]; } return $output; }; $this->linkTypeBuilderMock->expects($this->exactly(3))->method('populateWithArray')->will($this->returnValueMap($valueMap($expectedResult, $objectMocks))); $this->assertEquals($expectedResult, $this->model->getItems()); }