Home » Php » php – Magento – Unit Testing

php – Magento – Unit Testing

Posted by: admin July 12, 2020 Leave a comment

Questions:

I have been having some problems with a Magento site recently and am looking for a way to check the integrity of a Magento site at any given point.

Unit Testing jumps out as one method of doing this but I would assume it would be a very big job to write a whole lot of tests to check everything in the site is working as it should.

Can anyone involved in unit testing and magento advise on the following:

  1. Is it possible to test the whole site and not just custom modules –
    is so some examples of tests would be amazing.
  2. Given that the site is heavily linked to the database – how would it
    be possible to fully test the site without disturbing the database
  3. Are there any better ways to automaticlly check the integrity of a
    magento site

When I say integrity i really mean that there are no faults on the site – shipping, payment etc are all working correctly.

How to&Answers:

This is a big task, however there are Magento community members who have tackled it.

The EcomDev_PHPUnit module provides a framework for unit testing Magento, but it doesn’t contain any actual tests. It could (and has) been used to test core functionality or modules that you have developed yourself.

One of the key advantages of the EcomDev module is that it does provide 100% isolation of your database. It creates an exact copy of your database structure, and then uses fixtures (see pg 6 of the manual) to insert data into those tables to create test pre-requisites. This is powerful and best practice, but does require quite a bit of setup.

You can try using phpMyAdmin to export data into YAML in readiness for creating fixtures.

The alternative is to create and automate a comprehensive Selenium test suite for the browser UI. In fact, the best solution is to prepare both unit and UI tests as there will be areas that can only be tested in one functional domain. There is a significant amount of business logic built into Magento’s Javascript (all the validation.js for example) that PHPUnit can’t easily test, Selenium is your best option here.

There have been early conversations about creating a repository of unit tests to cover the core functionality, however keep in mind that Magento 2.0 (planned for 2012) advertises complete test coverage.