Revive your Magento integration tests

Continuous Integration, Integration test, Magento 2, Magento 2 testing, Open source

​In my day to day job as a freelancer i get to work on quite a few different Magento setups. Now as i try to practice Test Driven Development (TDD) wherever i can, i kept hitting the same bump in the road: when you have an installation that is around for some time, there is a big chance that the integration test setup is broken.​

There are several causes for this, but the common cause is that dependencies between extensions are not properly set up. ​

I have written a blog about how to fix this before, but this keeps being hard to solve as it’s a long and dreading process. ​ (ad)

Do you want your Magento store to be more reliable? Tired of things that suddenly break the checkout process without anyone noticing? You can hire my services to kickstart End-2-End testing for your Magento store. This way you know for sure that your store is behaving as expected before releasing that new feature or that update.

View for more information.

Meet Revive

That’s why i decided to build Revive: a tool that checks your integration test and tells you what is wrong with it before running anything. After that it takes over the process to fix the wrong dependencies. It continues until it fixes all dependencies. If it has done that but it still fails it tries to tell you why. ​​

What's in the name?

We've been all in that place: A shiny new project. You can do everything right this time! But as times goes by and deadlines needs to get meet, testing may not be very high on you priority list. When you finally want to start writing tests it turns out that your test setup is broken.

That's why it's called Revive: It helps you to revive this feeling at the start of the project: You ARE going to do this better. Heck, you've already got this far that you are trying to run integration tests.

Behind the scenes

Revive checks a few things for you:

  • It checks if you have a phpunit.xml and install-config-mysql.php configuration file.

  • It checks the Mysql and Rabbitmq configuration, and warns you about it.

Now that's great, but when it tries to run the integration tests some really magic happens. First of all, it tries to patch your AbstractFactory.php as described in the blogpost. After this it runs your integration test. This is likely going to fail (why would you use this tool otherwise), but this time it registers the instance that is failing and tries to patch it. It does this by adding proxies for all it's contstructor arguments. After this another test run is done.

By default a none-0 exit code is thrown when one or more tests are failing. For this reason a custom module is added in app/code/MichielGerritsen/ReviveFixes with 1 single test that always passes. The changes required for the proxies are also added in this module.

Show me the code

You can find the code on Github:

Want to respond?