1

I want to to glue PHPUnit with other command tools and I need a simple way to check if the tests passed or failed.

Somethings like

phpunit path_to_folder_containing_the_test

Would return "ok" if all passed or "failed" if any test failed.

[So I can simply check for "ok" and "failed" values from other tools]

Alex
  • 5,510
  • 8
  • 35
  • 54
  • Hi @Alex if mine or any answer has solved your question please consider [accepting it](http://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Matteo Mar 22 '15 at 14:25

2 Answers2

4

I have a very simply shell script that capture the exit code like:

>phpunit TestOk.php
>echo $?
0

and

>phpunit TestKo.php
>echo $?
1

Hope this help

Matteo
  • 37,680
  • 11
  • 100
  • 115
  • First what you posted seems like a bash variable (I'm on a Windows machine), secondly the output of phpunit is verbose regardless of your test output, so in short it does not work – Alex Mar 20 '15 at 11:21
  • 1
    Hi @Alex I collapse the (irrilevant?) output of the phpunit but i confirm that is work. I suggest you to give a try and to capture the exit code that is something like an `error_level` variable, check something like http://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line – Matteo Mar 20 '15 at 11:24
1

In your batch file, look for ERRORLEVEL

@echo off
call PHPUNIT.bat
if ERRORLEVEL 1 goto Fail
if ERRORLEVEL 0 goto Pass
:Pass
echo PHPUnit Successfully Executed
goto End
:Fail
echo PHPUnit Failed
goto End
:End

Change the echo statements to do whatever you wanted. If PHPUnit is returning other error codes (255 and down) then you can continue to use if ERRORLEVEL 255 to control functionality on that specific return code.

Steven Scott
  • 10,234
  • 9
  • 69
  • 117