magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.54k stars 9.31k forks source link

"Cannot instantiate interface Magento\Framework\Interception\ObjectManager\ConfigInterface" error in integration tests #12844

Closed schmengler closed 6 years ago

schmengler commented 6 years ago

Preconditions

  1. Magento 2.2.1

Steps to reproduce

  1. Create an integration test with the following fixture:
    protected function setUp()
    {
        $this->objectManager = Bootstrap::getObjectManager();
        $this->commandList = $this->objectManager->create(CommandListInterface::class);
    }

    Expected result

  2. I can use the command list to test registered commands

Actual result

  1. The test fails with an error like this:
    Cannot instantiate interface 
    Magento\Framework\Interception\ObjectManager\ConfigInterface
     PATH/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:50
     PATH/vendor/magento/framework/ObjectManager/ObjectManager.php:70
     PATH/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:144
     PATH/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:230
     PATH/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:34
     PATH/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:59
     PATH/vendor/magento/framework/ObjectManager/ObjectManager.php:70
     PATH/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:144
     PATH/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:230
     PATH/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:34
     PATH/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:59
     PATH/vendor/magento/framework/ObjectManager/ObjectManager.php:70
     PATH/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:144
     PATH/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:230
     PATH/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:34
     PATH/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:59
     PATH/vendor/magento/framework/ObjectManager/ObjectManager.php:70
     PATH/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:180
     PATH/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:156
     PATH/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:230
     PATH/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:34
     PATH/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:59
     PATH/vendor/magento/framework/ObjectManager/ObjectManager.php:56
     PATH/vendor/example/example/tests/ExampleTest.php:53

I logged which classes were instantiated befor the error and it seems like XmlCatalogGenerateCommand has the object manager config in its dependency graph, but in the integration test environment there is no preference for it.

Magento\Developer\Console\Command\XmlCatalogGenerateCommand
=> Magento\Framework\App\Utility\Files
=> Magento\Framework\Component\DirSearch
=> Magento\Framework\App\Utility\RegexIteratorFactory
=> Magento\Developer\Model\XmlCatalog\Format\PhpStorm
=> Magento\Framework\Filesystem\File\WriteFactory
=> Magento\Developer\Console\Command\DiInfoCommand
=> Magento\Developer\Model\Di\Information
=> Magento\Developer\Model\Di\PluginList
=> Magento\Framework\Interception\ObjectManager\ConfigInterface
schmengler commented 6 years ago

I worked around this issue by adding the preference manually in my test:

$this->objectManager->configure(
    [
        'preferences' => [
            ltrim(
                \Magento\Framework\Interception\ObjectManager\ConfigInterface::class,
                '\\'
            ) => ltrim(
                \Magento\TestFramework\ObjectManager\Config::class,
                '\\'
            ),
        ],
    ]
);

But that should not be necessary.

magento-team commented 6 years ago

Hi @schmengler. Thank you for your report. The issue has been fixed in magento/magento2#12845 by @schmengler in 2.2-develop branch Related commit(s):

The fix will be available with the upcoming patch release.

magento-engcom-team commented 6 years ago

Hi @schmengler. Thank you for your report. The issue has been fixed in magento-engcom/magento2ce#1299 by @magento-engcom-team in 2.3-develop branch Related commit(s):

The fix will be available with the upcoming patch release.

djixas commented 5 years ago

Same error exists in 2.3.1, fresh install, after not installing all modules, error 500 in admin panel of products page, all other pages load fine,

Not sure what not installed module is causing the error

`[root@host /home/x/public_html]# php bin/magento setup:upgrade

Fatal error: Uncaught Error: Cannot instantiate interface Magento\Framework\HTTP\ClientInterface in /home/x/public_html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:50 Stack trace:

0 /home/x/public_html/vendor/magento/framework/ObjectManager/ObjectManager.php(70): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Magento\Framewo...')

1 /home/x/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(160): Magento\Framework\ObjectManager\ObjectManager->get('Magento\Framewo...')

2 /home/x/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(246): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument(Array, 'Magento\Framewo...', NULL, 'client', 'Magento\Invento...')

3 /home/x/public_html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgumentsInRuntime('Magento\Invento...', Array, in /home/x/public_html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php on line 50`

FrancYescO commented 5 years ago

@djixas have you fixed? i'm having same error on 2.3.1

djixas commented 5 years ago

@FrancYescO

I did, will stay with v1.9 for foreseeable future and then migrate to a store that does not take 20 seconds to load without 50 cache modules enabled

toniodlab commented 5 years ago

@FrancYescO & @djixas , I just fixed it :

1/ Add the following line into /app/etc/di.xml file :

<preference for="Magento\Framework\HTTP\ClientInterface" type="Magento\Framework\HTTP\Client\Curl" />

2/ Create a new module, with the following /etc/di.xml file :

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Framework\HTTP\ClientInterface" type="Magento\Framework\HTTP\Client\Curl" />
</config>

3/ With command line : php bin/magento setup:di:compile, then php bin/magento setup:upgrade

4/ Remove the line added in 1/ (in /app/etc/di.xml)

5/ With command line : php bin/magento setup:di:compile, then php bin/magento setup:upgrade

This should be fixed

kibbyboi commented 5 years ago

I have this issue after i upgrade my magento to 2.3.1 , can someone help me to resolve it . Thank you

Fatal error: Uncaught Error: Cannot instantiate interface Magento\Framework\Acl\LoaderInterface in /home/edgeexpr/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:116 Stack trace: #0 /home/edgeexpr/public_html/vendor/magento/framework/ObjectManager/Factory/Compiled.php(108): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Magento\Framewo...', Array) #1 /home/edgeexpr/public_html/vendor/magento/framework/ObjectManager/Factory/Compiled.php(150): Magento\Framework\ObjectManager\Factory\Compiled->create('Magento\Framewo...') #2 /home/edgeexpr/public_html/vendor/magento/framework/ObjectManager/Factory/Compiled.php(79): Magento\Framework\ObjectManager\Factory\Compiled->get('Magento\Framewo...') #3 /home/edgeexpr/public_html/vendor/magento/framework/ObjectManager/Factory/Compiled.php(150): Magento\Framework\ObjectManager\Factory\Compiled->create('Magento\Framewo...') #4 /home/edgeexpr/public_html/vendor/magento/framework/ObjectManager/Factory/Compiled.php(79): Magento\Fram in /home/edgeexpr/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 116

stkrelax commented 5 years ago

@djixas module-ups and module-inventory-distance-based-source-selection

have the use Magento\Framework\HTTP\ClientInterface;

@toniodlab fixed the problem

tag 2.3.1 is missing the

<preference for="Magento\Framework\HTTP\ClientInterface" type="Magento\Framework\HTTP\Client\Curl" />

branch 2.3-develop has it