0

I want codesniffer to produce error output in CLI and exit before proceeding any further to avoid running other tests like behat, phpmd, phpcpd so that comes after.

Current code (as shown below) creates a XML report with errors listed in but it won't terminate the process. How should I modify the code in order to have a XML report, CLI error output and terminate the process in case of an error?

CURRENT CODE in PHING:

<target name="codesniffer-phpcs">
    <echo msg="Checking coding standards ..." />
    <tstamp />
    <phpcodesniffer standard="PSR2" showWarnings="true" format="full">
        <fileset refid="sourcecode" />
        <formatter type="checkstyle" outfile="phing/phpcs/psr2_${DSTAMP}-${TSTAMP}.xml" />
    </phpcodesniffer>
</target>

This is what I would like to see in CLI as well as having XML file:

FOUND 4 ERROR(S) AFFECTING 4 LINE(S)
--------------------------------------------------------------------------------
   69 | ERROR | There must not be more than one property declared per statement
  108 | ERROR | The abstract declaration must precede the visibility
  657 | ERROR | Expected 1 space after comma in function call; 2 found
  812 | ERROR | A cast statement must be followed by a single space
--------------------------------------------------------------------------------
BentCoder
  • 12,257
  • 22
  • 93
  • 165

1 Answers1

0

I think the attribute "haltonerror" inside the task will be your friend here. http://www.phing.info/docs/guide/stable/apcs48.html

common sense
  • 3,775
  • 6
  • 22
  • 31
  • Yes it did stop but didn't tell me in which file the error was. Just killed the process wit: Execution of target "test-phpcs" failed for the following reason: `/var/www/html/local/symfony/build.xml:189:65: phpcodesniffer detected 1 error BUILD FAILED /var/www/html/local/symfony/build.xml:189:65: phpcodesniffer detected 1 error Total time: 2.7364 seconds` – BentCoder Oct 18 '14 at 20:49
  • The question is anyway why* you like to stop it after a violation occurred. Normally you parse the output of phpcs with jenkins or other CI tools and analyze the result in a graph or file list with error markers. * I know it runs longer – common sense Oct 18 '14 at 20:54
  • We have many tests running so we tend to stop and solve the problems before proceeding any further. That's why. – BentCoder Oct 18 '14 at 20:57