top of page

PHPUnit Conversion Progress

If the Runtime Converter hasn't had much news lately, it is because of work on somewhat "large projects" such as converting PHPUnit and Laravel frameworks. We are not so much "converting" these frameworks as we are developing the "ability to convert them" into the Runtime Converter itself. We do, however, expect to release code samples to GitHub when they are ready.

It has taken several months to get to where PHPUnit compiles, but there are still some bugs being worked out. Bugs are fixed by running the converted code in IntelliJ and debugging it line-by line until it becomes clear what is going wrong. In some cases, it is necessary to also run a PHP debugger and step through both PHP and Java at the same time.

One particularly difficult bug was where PHPUnit threw a subclass of \Exception, but it was not caught due to not implementing the "Throwable" interface.

We expect to be able to support all PHPUnit features including ones which use code-generation to create proxy classes. At first, it would seem impossible to take a string of PHP code and convert it to a Java class at runtime without including the converter. It turns out, however, that what PHPUnit is doing with its code-generation classes is to create proxy classes. We plan to build our own proxy-class using the ByteBuddy library and to load this when eval is called from PHPUnit's code generation class. We don't even need to use a regex to get the source + destination class names for the proxy class. We can take it right from the "this" variable properties.

It might seem like a bit of a "hack" but supporting "eval" is not planned for the Runtime Converter. Generating proxy classes for test happens to be the "one case" where runtime code-generation and execution cannot be replaced with a function or class.

A very nice explanation of the usefulness of code-generation and eval is explained on the Byte Buddy website, "At first sight, runtime code generation can appear to be some sort of black magic that should be avoided and only few developers write applications that explicitly generate code during their runtime. However, this picture changes when creating libraries that need to interact with arbitrary code and unknown type hierarchies. In this context, a library implementer must often choose between either requiring a user to implement library-proprietary interfaces or to generate code at runtime when the user's type hierarchy becomes first known to the library. Many known libraries such as for example Spring or Hibernate choose the latter approach which is popular among their users under the term of using Plain Old Java Objects. As a result, code generation has become an ubiquitous concept in the Java space. Byte Buddy is an attempt to innovate the runtime creation of Java types in order to provide a better tool set to those relying on such functionality." (

Featured Posts
Recent Posts
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page