While trying to figure out TestDisableDisplayErrors, I started wondering if there could be an easier way to specify tests. Something along the lines of PHPUnit's assertThat().
I was think something along the lines of (using TestDisableDisplayErrors as an example):
class TestDisableDisplayErrors extends \Psecio\Parse\Test
{
public function evaluate($node, $file = null)
{
return $this->failIf(
$this->assertNode($node)
->isFunction('ini_set')
->withStringArg(0, 'display_errors')
->withBoolArg(1, true)
->orIf()->withStringArgNot(1, "0") // any string but "0"
->orIf()->withNumericArgNot(1, 0) // any number but 0
// The last three might be collapsed into something like
// ->withArgNot(false)
// which would check for a falsey value like 0, "0" or false
);
}
}
Of course, that's only with a few minutes of thinking on it. I haven't worked out exactly how it would work, except that assertNode() and all the assertion methods return some sort of assertion object that carries a Node object. The failIf() method would then evaluate the final assertion and return true or false based on the results of the assertion.
This is just a thought. There would be a fair bit of work implementing it. But it would make for more readable tests.
It also has the potential to be moved into a separate library usable by other users of PhpParser. Of course, maybe something like this already exists.... I'll have to look.
While trying to figure out
TestDisableDisplayErrors, I started wondering if there could be an easier way to specify tests. Something along the lines of PHPUnit'sassertThat().I was think something along the lines of (using
TestDisableDisplayErrorsas an example):Of course, that's only with a few minutes of thinking on it. I haven't worked out exactly how it would work, except that
assertNode()and all the assertion methods return some sort of assertion object that carries aNodeobject. ThefailIf()method would then evaluate the final assertion and return true or false based on the results of the assertion.This is just a thought. There would be a fair bit of work implementing it. But it would make for more readable tests.
It also has the potential to be moved into a separate library usable by other users of PhpParser. Of course, maybe something like this already exists.... I'll have to look.