I cannot mock ProductOptionInterface::setExtensionAttributes, I get this error:

PHPUnit_Framework_MockObject_RuntimeException : Cannot mock Magento\Catalog\Api\Data\ProductOptionInterface::setExtensionAttributes() because a class or interface used in the signature is not loaded

Does anyone know how to resolve it?

1 Answer 1


The signature of the method is

public function setExtensionAttributes(
    \Magento\Catalog\Api\Data\ProductOptionExtensionInterface $extensionAttributes

And the error message tells you that a class or interface of the signature is not loaded. This means that the interface Magento\Catalog\Api\Data\ProductOptionExtensionInterface cannot be found.

The "Extension" interfaces are generated files with getters and setters, this particular one should be in var/generation/Magento/Catalog/Api/Data/ProductOptionExtensionInterface.php

To make autoloading and code generation work with unit tests you need to use the test bootstrap file from Magento:

phpunit --bootstrap dev/tests/unit/framework/bootstrap.php YOUR_TEST

If you are running the unit tests from within the dev/tests/unit directory itself, this should already work because the bootstrap file is defined in phpunit.xml.dist there.

  • It real works. Thank you. The problem was that i use default "phpunit.xml.dist". When i show the path to dev/tests/unit/phpunit.xml.dist it resolve my problem
    – Roma Kis
    Mar 10, 2016 at 12:56

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.