During the course of their MidCamp event for 2014, the Drupal community revealed a fascinating aspect of the latest version of their development framework. With the use of Drupal 8, PHPUnit will now have its support system made as part of the base distribution. This is of great importance to us Drupal developers at PHP Programmers who have been making every effort to integrate automated tests into our build system. The “Self-Testing Build” feature of this development framework is what makes it one of the most sought-after platform for the developers who are on the lookout for embracing Continuous Integration in their development philosophy.
At present we make use of PHPUnit for all our testing-related activities. A new technique known as Behavioral Driven Development (BDD) designed using PHP Unit along with PhantomJS, Mink and Behat allows us to practice easily developed self-code for review.
However, one major issue with this form of testing workflow is that the developers are required to jump in to the Functional Test level everytime they are required to test something. This is not much of an improvement on the Simple Test workflow that Drupal had been using for so long. Now, with Drupal releasing their latest version Drupal 8, something better has been presented to the developers: provision for testing functionalities at a unit level.
Testing with Drupal was a near impossible task until Drupal 8 was brought into the fray. Only thing that developers could work with was the Simple Test framework that came integrated with the development tool. However, it followed something that, in the terminology of developers, we refer to as “Use one Car to Test Another Car” approach. To be more specific, it requires that developers have a full Drupal instance running in order to create a fake Drupal instance that will carry out all the required tests.
Moreover, the functional code does not have much of an encapsulation. Simply put, developers can just test by saying “I shall be giving abc as input and getting xyz as output.” The lack of encapsulation may be blamed on the predominant use of global variables that prevents functionalities from being grouped together with data akin to what can be done with the objects in Object Oriented Programming.
However, there is no need to fear. The new object-oriented framework of Drupal 8 gives easy access to a number of new features and programming patterns such as object mocking and dependency injection. This allows consolidation of a single unit of code. A unit may be defined as a single function within a class which is the smallest unit of code which can possibly be tested using PHP Unit.
This serves as a much needed inspiration for developers to write code that is not only testable and better, but also available in smaller testable units. This increases their reusability and also makes the overall testing process much easier.
Under numerous circumstances, it is altogether possible to do away with the various functional tests. If the individual components of a system are working as per expectations, then their sum total would add up to a feature that gives equally satisfactory levels of performance. Last but not the least, these modern tests are faster as compared to those done with the older version of Drupal, even if only by a few orders of magnitude.
This allows the tests to be integrated into the build script rather than having to use a different testing module such as Travis-CI for the purpose. And speaking of the latter, it can now be integrated directly with Drupal 8 rather than bringing them together out-of-the-box in order to create a favorable environment for testing purposes.
While BDD is undoubtedly a testing feature that is here to stay- thanks largely to its improved features of direct communication with the clients on various aspects of testing- unit testing allows users to build a set of codes that are reusable and available at lower maintenance costs. With unit testing, developers are better equipped to gauge the quality of their code.
Strictly from the perspective of a PHP programmer, this will help improve our existing testing process especially with regards to our migration services and technical projects based on integrations and APIs. The future prospects surrounding the use of Drupal 8 are certainly exciting as the new unit test results will serve as an insurance for the clients and backup our claims of providing quality service. As long as the developers are happy, we can give assurance of making our clients happy, and it is all thanks to the release of Drupal 8.