Categories
PHPUnit

What do you verify before deploying your code ?

vendor/bin/phpcs --standard=PSR2 --colors -p src/ && vendor/bin/phpunit --stop-on-failure  

PSR-2 Code Styling

This command returns all PSR-2 (code styling errors)

vendor/bin/phpcs --standard=PSR2 ~/directory_to_scan

vendor/bin/phpcs –standard=PSR2 –colors -pv src/ApiBundle

with more information

This command fix all fixable PSR-2 (code styling errors) issues

vendor/bin/phpcbf --standard=PSR2 --report=json ~/directory_to_scan

Run the Functional and Unit Tests

vendor/bin/phpunit –stop-on-failure

Categories
General

PHPUnit, how to stop on failure ?

Find below the command that exit out phpunit ghracefully when a first error pop out=

phpunit --stop-on-failure
phpunit David Raleche
phpunit David Raleche
Categories
PHP PHPUnit Unix

Developer Helper – Command Cine

PSR-2 Code Styling

vendor/bin/phpcs --standard=PSR2  app src
vendor/bin/phpcbf --standard=PSR2  app src
vendor/bin/phpcbf --standard=PSR2 --report=json app src

phpunit

vendor/bin/phpunit
vendor/bin/phpunit --log-junit web/phpunit/phpunit.xml --coverage-clover web/phpunit/coverage.xml --coverage-html web/phpunit/

Swagger Generate swagger documentation Swagger endpoint

vendor/bin/openapi -o "web/swagger.json" app/ src/ web/
Categories
BEST PHP CODE

Force to write debugging messages in PhpUnit

If you found yourself trying to debug PhpUnit the following php line will relieve your frustration. This line will instantly output the message or variables values that you are trying to debug

fwrite(STDERR, "TEST");
Categories
BEST PHP CODE PHPUnit

PHPUnit (truncated…) – SOLUTION

Hi Team,

If you experienced the difficult task to debug through PhpUnit find here a global solution !

The exception caught is related to the guzzle version

The solution is a try-catch around your phpunit test and expose the GuzzleException $e

 $client = new GuzzleHttp\Client(['base_uri' => 'https://foo.com/api/']);

try {

       $response = $client->request('GET','/v1/testYourEndpoint');

} catch (\GuzzleHttp\Exception\ClientErrorResponseException  $e) {
    var_dump($e->getResponse()->getBody()->getContents());

} catch (\GuzzleHttp\Exception\RequestException $e) {
    var_dump($e->getResponse()->getBody()->getContents());

} catch (\GuzzleHttp\Exception\ClientException  $e) {
    var_dump($e->getResponse()->getBody()->getContents());
}

Enjoy !
David Raleche