I was wondering – is there a tool which will look at my PHP code and automatically generate a PHPUnit test for it? Or is there a tool like this for any other language, which I might be able to port to PHP?
I’m not talking about generating a skeleton. I was thinking that it would be possible for a tool to look at tokenized PHP and determine the code paths through a method, and then automatically generate a test for each code path, creating mocks and setting “expects” calls as necessary.
Even if there’s no tool that currently does it, might such a task be feasible or am I overlooking something?
Advertisement
Answer
Turns out there is no tool that does this currently, so I wrote one (with help from my colleagues). Not complete – just enough to explore the concept. By using nikic’s PHP-Parser(https://github.com/nikic/PHP-Parser), it’s possible to find all the method calls in the methods of a class, and then mocks can be created for them.
At the very least, I might eventually get it to the point where I can use it to make some fill-in-the-blank unit tests.