6

I want to use a local installation of PHPUnit (via composer) to run my tests and display it on screen (acessing /admin/tests for instance). But the only way to run tests I found in the documentation was the command line tool.

Bellow is an hypothetical example of what I'm looking for:

$session = new PHPUnit_TestSession('path/to/folder');
$results = $session->runAll();
echo $results->failuresCount();
// other hipotetical $result->methods...
// maybe $results->dump()

1 Answer 1

6

This may be an overkill but you are in for a treat: https://github.com/NSinopoli/VisualPHPUnit :)

EDIT Here is a rudimentary use of PHPUnit using the TextUI_TestRunner

// make sure you have PHPUnit on your path
require_once "PHPUnit/Framework/TestSuite.php";
require_once "PHPUnit/TextUI/TestRunner.php";

$suite = new PHPUnit_Framework_TestSuite();
$suite->addTestSuite('YourTestCase');

// run the test suite with TextUI_TestRunner
PHPUnit_TextUI_TestRunner::run($suite);

The YourTestCase class is a subclass of PHPUnit_Framework_TestCase, which you can read more on how to write at the official website: http://www.phpunit.de/manual/3.2/en/writing-tests-for-phpunit.html

However, I'd also recommend getting a copy of this book: http://www.amazon.com/Advanced-PHP-Programming-George-Schlossnagle/dp/0672325616 The author teaches you quite a few cool tricks, including autoloading tests, etc.

Sign up to request clarification or add additional context in comments.

3 Comments

the documentation suggests that it needs a global PEAR installation. I was really hoping to make this portable...
I've updated my answer. The TestRunner library provides you with some tools to run test suites in the browser but I hate it, lol.
it just prints the command line output to the screen. LOL ~ but it's a really good start. thank you (:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.