mardi 3 novembre 2015

PHPMD Catch/Suppress fatal errors

I'm trying to automate my testing. As a smoke test I would like to check my PHP code with PHPMD before continuing with the actual Unit tests. Sounds sensible enough right?

Thing is that PHPMD seems to crash when fatal errors arise in my PHP files. For a test I added an extra accolade at a function definition like so:

function foo() {{
    // Stuff
}

Were I expected a 1 exit code, PHPMD seems to crash completely and instead returns a 0 exit code. Rendering my automated script useless. Is there a way to suppress these errors and return the expected exit code? For PHPUnit the --process-isolation option solved this problem but I can't seem to find such option for PHPMD.

Relevant automated testing code

#!/usr/bin/php
<?php

    exec('meta/phpmd', $output, $returnCode);
    if ($returnCode == 1) {
        echo '[Fail] PHP code is breaking', PHP_EOL;
        exit(1);
    } elseif ($returnCode == 2) {
        echo '[Warn] PHP code is unclean', PHP_EOL;
    } else {
        echo '[OK] Code is clean! ', PHP_EOL;
    }

Aucun commentaire:

Enregistrer un commentaire