0

I'm writing PHPUnit test cases for a custom module. Got struct in writing mocks for the chained methods.

$product = $this->productRepository->get($item->getSku())->getData('bc_giftcard_code_set');

Tried with below, but didn't work.

$productRepository = $this->getMockBuilder(\Magento\Catalog\Model\ProductRepository::class)
        ->disableOriginalConstructor()
        ->setMethods(['get', 'getData'])
        ->getMock();
$productRepository->expects($this->any())->method('get')->will($this->returnSelf());
$productRepository->expects($this->any())->method('getData')->will($this->returnValue(2));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.