Magento2: Class Magento\Catalog\Api\Data\ProductExtensionInterfaceFactory does not exist -error while running Magento integration tests

Created on 20 Dec 2019  路  7Comments  路  Source: magento/magento2

Preconditions (*)

  1. Magento 2.3.3 CE with Sample Data installed
  2. Site was previously v.2.3.1 (installed and updated with composer installation method)

Steps to reproduce (*)

  1. Set up/prepare local integration test configurations and database based on the documentation: https://devdocs.magento.com/guides/v2.3/test/integration/integration_test_execution.html#setup
  2. Navigate to dev/tests/integration folder
  3. Run Magento Integration Tests -testsuite using CLI with the command ../../../vendor/bin/phpunit --testsuite "Magento Integration Tests"

Expected result (*)

  1. Magento Integration Tests -testsuite executes and completes without errors.

Actual result (*)

  1. Class MagentoCatalogApiDataProductExtensionInterfaceFactory does not exist -error occurs while running the Magento Integration Tests -testsuite using CLI command: ../../../vendor/bin/phpunit --testsuite "Magento Integration Tests" in the dev/tests/integration -folder.
root@AMBWKS429:/mnt/c/Users/kimmok/Documents/magento23.local.fi/dev/tests/integration# ../../../vendor/bin/phpunit --testsuite "Magento Integration Tests"
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
.........Error in fixture: "\/mnt\/c\/Users\/kimmok\/Documents\/magento23.local.fi\/dev\/tests\/integration\/testsuite\/Magento\/Catalog\/_files\/product_simple.php".
 Class Magento\Catalog\Api\Data\ProductExtensionInterfaceFactory does not exist
 #0 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/magento/framework/Code/Reader/ClassReader.php(19): ReflectionClass->__construct('Magento\\Catalog...')
#1 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/magento/framework/ObjectManager/Definition/Runtime.php(49): Magento\Framework\Code\Reader\ClassReader->getConstructor('Magento\\Catalog...')
#2 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(48): Magento\Framework\ObjectManager\Definition\Runtime->getParameters('Magento\\Catalog...')
#3 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/magento/framework/ObjectManager/ObjectManager.php(70): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Magento\\Catalog...')
#4 /mnt/c/Users/kimmok/Documents/magento23.local.fi/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple.php(24): Magento\Framework\ObjectManager\ObjectManager->get('Magento\\Catalog...')
#5 /mnt/c/Users/kimmok/Documents/magento23.local.fi/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixture.php(214): require('/mnt/c/Users/ki...')
#6 /mnt/c/Users/kimmok/Documents/magento23.local.fi/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixture.php(244): Magento\TestFramework\Annotation\DataFixture->_applyOneFixture('/mnt/c/Users/ki...')
#7 /mnt/c/Users/kimmok/Documents/magento23.local.fi/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixture.php(60): Magento\TestFramework\Annotation\DataFixture->_applyFixtures(Array)
#8 [internal function]: Magento\TestFramework\Annotation\DataFixture->startTestTransactionRequest(Object(Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricingTest), Object(Magento\TestFramework\Event\Param\Transaction))
#9 /mnt/c/Users/kimmok/Documents/magento23.local.fi/dev/tests/integration/framework/Magento/TestFramework/EventManager.php(49): call_user_func_array(Array, Array)
#10 /mnt/c/Users/kimmok/Documents/magento23.local.fi/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php(76): Magento\TestFramework\EventManager->fireEvent('startTestTransa...', Array)
#11 /mnt/c/Users/kimmok/Documents/magento23.local.fi/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php(46): Magento\TestFramework\Event\Transaction->_processTransactionRequests('startTest', Object(Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricingTest))
#12 [internal function]: Magento\TestFramework\Event\Transaction->startTest(Object(Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricingTest))
#13 /mnt/c/Users/kimmok/Documents/magento23.local.fi/dev/tests/integration/framework/Magento/TestFramework/EventManager.php(49): call_user_func_array(Array, Array)
#14 /mnt/c/Users/kimmok/Documents/magento23.local.fi/dev/tests/integration/framework/Magento/TestFramework/Event/PhpUnit.php(126): Magento\TestFramework\EventManager->fireEvent('startTest', Array)
#15 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/phpunit/phpunit/src/Framework/TestResult.php(395): Magento\TestFramework\Event\PhpUnit->startTest(Object(Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricingTest))
#16 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/phpunit/phpunit/src/Framework/TestResult.php(637): PHPUnit\Framework\TestResult->startTest(Object(Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricingTest))
#17 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/phpunit/phpunit/src/Framework/TestCase.php(894): PHPUnit\Framework\TestResult->run(Object(Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricingTest))
#18 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/phpunit/phpunit/src/Framework/TestSuite.php(755): PHPUnit\Framework\TestCase->run(Object(PHPUnit\Framework\TestResult))
#19 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/phpunit/phpunit/src/Framework/TestSuite.php(755): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#20 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/phpunit/phpunit/src/Framework/TestSuite.php(755): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#21 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(545): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#22 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/phpunit/phpunit/src/TextUI/Command.php(195): PHPUnit\TextUI\TestRunner->doRun(Object(PHPUnit\Framework\TestSuite), Array, true)
#23 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/phpunit/phpunit/src/TextUI/Command.php(148): PHPUnit\TextUI\Command->run(Array, true)
#24 /mnt/c/Users/kimmok/Documents/magento23.local.fi/vendor/phpunit/phpunit/phpunit(53): PHPUnit\TextUI\Command::main()
#25 {main}
Format is valid Dev.Experience

Most helpful comment

I'm reopening this mostly as a help for anyone who may stumble upon this issue while looking for the ProductExtensionInterfaceFactory error message (including myself :-) ).
If the fix I suggest below is not acceptable, please close the issue again.

It looks like the issue happens if one tries to run the tests in an application mode other than developer OR if the mode is developer but there is dirty data in the "generated" directory.
Initially I had Magento set to the default application mode and had run the setup:di:compile command. That caused the ProductExtensionInterfaceFactory error to appear when I ran the tests of a module I was developing.
I switched to the developer mode, but the problem persisted.
Only when I cleared the contents of "generated" (still in developer mode), the issue went away.

I don't know if this is something that should (or can) be fixed by Magento or if it is something that has to be handled manually. Perhaps automatically clearing the contents of "generated" when one switches mode wouldn't be a bad idea.

All 7 comments

Hi @ambkimmok. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@ambkimmok do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

Hello @ambkimmok

I can't reproduce this issue on the fresh Magento 2.4-develop.

Testing scenario:

  1. Set up/prepare local integration test configurations and database based on the documentation: https://devdocs.magento.com/guides/v2.3/test/integration/integration_test_execution.html#setup
  2. Navigate to dev/tests/integration folder
  3. Run Magento Integration Tests -testsuite using CLI with the command ../../../vendor/bin/phpunit --testsuite "Magento Integration Tests"

Result:
Magento Integration Tests -testsuite executes and completes without errors.
image

So i have to close this issue as not reproducible.

Thanks for your report!

I'm reopening this mostly as a help for anyone who may stumble upon this issue while looking for the ProductExtensionInterfaceFactory error message (including myself :-) ).
If the fix I suggest below is not acceptable, please close the issue again.

It looks like the issue happens if one tries to run the tests in an application mode other than developer OR if the mode is developer but there is dirty data in the "generated" directory.
Initially I had Magento set to the default application mode and had run the setup:di:compile command. That caused the ProductExtensionInterfaceFactory error to appear when I ran the tests of a module I was developing.
I switched to the developer mode, but the problem persisted.
Only when I cleared the contents of "generated" (still in developer mode), the issue went away.

I don't know if this is something that should (or can) be fixed by Magento or if it is something that has to be handled manually. Perhaps automatically clearing the contents of "generated" when one switches mode wouldn't be a bad idea.

Hi @engcom-Hotel. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

Hello @azambon
Yes, you are right. We must run integration tests only in developer mode, because e.g. ProductExtensionInterfaceFactory will be generated when you will try to execute some class where you call it.

This issue should be closed.

Thanks for collaboration and contributing!

I just run into the same problem. Magento2 seems to fail to generate class \Magento\Catalog\Api\Data\ProductExtensionInterfaceFactory.

The Generator responsible for this class generates the files, but is unable to save it because the directory is not yet created.

\Magento\Framework\Code\Generator\EntityAbstract::generate()

Calling $this->_ioObject->makeResultFileDirectory($this->_getResultClassName()); before writeResultFile seems to fix the issue.

Was this page helpful?
0 / 5 - 0 ratings