1

I've developed a module that must return some data by REST. When I call it by web browser everything works as well, but when I call it by test class, PHPUnit Test, the method get($sku) of interface Magento\Catalog\Api\ProductRepositoryInterface returns a null value. What am I doing wrong? My method setUp()

protected function setUp()
{
    $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
    $this->priceService = $this->objectManager->getObject('my_class');
}
1

In unit tests there is no database. That means to test interaction with a repository you should replace the repository with a test double that returns a predefined value for "get()"

Since you did not show the actual test code and I don't know what you are trying to test, I cannot go into much detail. But the keyword you are looking for is "mock objects"

| improve this answer | |

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.