0

In unit testing I want to create mock object for factory classes e.g.

$this->getMockBuilder(\Magento\Framework\Controller\Result\RawFactory::class)->disableOriginalConstructor()->getMock();

but I have following error,

generation does not exist.

So how to generate factory class in in generation when create unit testing.

0

You can do it like this,

$rowFactoryMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\RawFactory::class)
            ->disableOriginalConstructor()
            ->getMock();

        $rawResult = $this
            ->getMockBuilder(\Magento\Framework\Controller\Result\Raw::class)
            ->disableOriginalConstructor()
            ->getMock();

        $rowFactoryMock
            ->method('create')
            ->will($this->returnValue($rawResult));

First, you need to create mock of RawFactory class then you need to create mock Raw class and last you need to assign $rawResult to $rowFactoryMock

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.