Symfony 2 + Doctrine 2 + PHPUnit 3.5: Serialization of closure exception

Not technically related to your issue. However, I had a really hard time trying to solve the “Serialization of ‘Closure’ is not allowed” issue while using PHPUnit, and this question is the top Google result. The problem comes from the fact that PHPUnit serializes all the $GLOBALS in the system to essential back them up … Read more

Match JsonStructure in PhpUnit Test – Laravel 5.4

Luckily, playing with different options I have solved this issue. A ‘*’ is expected as key if we are to match a nested object in an array. We can see the reference here. Source: TestResponse I have set the structure like this for array ofobjects` $response->assertJsonStructure([ ‘status’, ‘message’, ‘data’ => [ ‘*’ => [ ‘id’, … Read more

How to Determine if PHPUnit Tests are Running?

An alternative approach is to set a constant in the PHP section of your phpunit.xml.*: <php> <const name=”PHPUNIT_YOURAPPLICATION_TESTSUITE” value=”true”/> </php> In your PHP application, you might then use the following check: if (defined(‘PHPUNIT_YOURAPPLICATION_TESTSUITE’) && PHPUNIT_YOURAPPLICATION_TESTSUITE) { echo ‘TestSuite running!’; } First, we check that the constant is defined, secondly, we check the value of the … Read more