phpUnit Debug Technics Guzzle

$body = json_decode($response->getBody());

 fwrite(STDERR, json_encode($json));
 fwrite(STDERR, $body->message);
 public function testSuccesssfulJobCancel()
{

    $this->postOrderSuccesful();

    $headers = [
        'Authorization' => QATemplate::$deleteKey,
    ];
    $url = '/v1/jobId/M111111123-001';

    $response = QATemplate::$http->request(
        'DELETE',
        $url,
        [
            'verify' =>false,
            'http_errors' => false,
            'headers' =>$headers
        ]
    );

    $body = json_decode($response->getBody());

    fwrite(STDERR, json_encode($json));
    fwrite(STDERR, $body->message);


    $this->assertEquals(200, $response->getStatusCode());
    $this->assertContains("Success Job Deleted", $body->message);
}

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/

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