John Geliberte
John Geliberte

Reputation: 1025

How to get Phpunit Test Summary

Im currently working on a Phpunit test and i was wondering if is it possible to get the Test Summary and store it to a variable so i can send it via Email?.

Time: 11.92 minutes, Memory: 20.00Mb

There were 4 failures:

1) BingTestTool::testPushCampaign_without_status
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-''
+'Active'

Here is the result that phpunit outputs in the console, can i store this to a variable? so that i can send it tru email after the test run

Upvotes: 0

Views: 939

Answers (1)

axiac
axiac

Reputation: 72206

If you run phpunit in your console then just pipe its output to mail:

$ phpunit | mail [email protected] -s 'Results of phpunit'

The -s command line argument allows setting the email's Subject.


If the execution of phpunit is just a step of a longer process (a deployment, for example) and you need the output for some processing, you can enclose the phpunit command into backquotes (``) or $() and use the expression as the right-hand side of an assignment:

RESULT="`phpunit`"

or

RESULT="$(phpunit)"

The double quotes around the expression are needed to keep the output (which is a multi-line string) as a single word and prevent the shell from interpreting it. There must be no spaces around the equal sign.

Now you can display it:

echo "$RESULT"

or pipe it to the input of various Unix programs. For example:

echo "$RESULT" | grep '^Time:' | cut -f1 -d,

feeds the content of variable $RESULT to grep that extracts and outputs only the line that starts with Time:; the output of grep is piped then to cut to keep only the first column using , as delimiter.

Upvotes: 1

Related Questions