ho-nl / magento2-ReachDigital_TestFramework

Faster drop-in replacement for Magento's integration test.
MIT License
75 stars 13 forks source link

Fixes for running tests with Magento 2.4 #22

Closed jissereitsma closed 3 years ago

jissereitsma commented 3 years ago

When running the Quick Integration tests on Magento 2.4.1, I bumped into the following error: Uncaught RuntimeException: Override fixture resolver isn't initialized in .../dev/tests/integration/framework/Magento/TestFramework/Workaround/Override/Fixture/Resolver.php:69 Diving into this, I see that the bootstrap.php in Magento 2.4.X is quite different from the bootstrap.php of the Quick Integration framework. But we can fix that! By adding the following lines of code into the bootstrap.php file of the Quick Test framework, it works all nicely:

    $overrideConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
        Magento\TestFramework\Workaround\Override\Config::class
    );
    $overrideConfig->init();
    Magento\TestFramework\Workaround\Override\Config::setInstance($overrideConfig);
    Magento\TestFramework\Workaround\Override\Fixture\Resolver::setInstance(
        new  \Magento\TestFramework\Workaround\Override\Fixture\Resolver($overrideConfig)
    );

I placed it somewhere after the Files::setInstance call.

To be on the safe-side, I've also added the newly created $overrideConfig variable to the unset line:

unset($testsBaseDir, $logWriter, $settings, $shell, $application, $bootstrap, $overrideConfig);

Additionally, the phpunit.xml.dist file needs to include the following line:

<phpunit>
    <php>
        <const name="USE_OVERRIDE_CONFIG" value="enabled"/>
    </php>
</phpunit>

Next, in the class TestFramework\Bootstrap\DocBlock a new class needs to be added to the return:

new \Magento\TestFramework\Workaround\Override\Fixture\Resolver\TestSetter(),

Now, the question is: Why not add this as a PR? Happy to do that! But because this specifically works for Magento 2.4, I wonder what the best procedure would be, because the PR would make things incompatible with Magento 2.3. Perhaps simply a new branch magento-2.4 and a new major release 2.0?

Vinai commented 3 years ago

How about wrapping the relevant statements in a

if (class_exists(\Magento\TestFramework\Workaround\Override\Config::class))

Sounds simpler to me, because no two branches would need to be maintained.

jissereitsma commented 3 years ago

Sounds good to me :) Working on it

jissereitsma commented 3 years ago

https://github.com/ho-nl/magento2-ReachDigital_TestFramework/pull/23