Fix for phpunit "no assertion" warning, making tests more robust

Phpunit complains about testInvoke, which does not perform any assertions.
Indeed testInvoke only checks, thanks to the 'closure' function, that when
the closure is called, the expected parameters are passed. It does not check
that the closure is called the expected number of times.

This commit changes the closure function so that it checks the number of
times it is called, removing the warning and making the whole test more robust