Running PHPUnit from PHP instead of runner

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
jadent
Forum Newbie
Posts: 3
Joined: Fri Jan 21, 2011 10:43 pm

Running PHPUnit from PHP instead of runner

Post by jadent »

Using PHPUnit 3.6 how to you run a php test suite using PHP instead of the test runner and get output like the test runner?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Running PHPUnit from PHP instead of runner

Post by josh »

Do you mean through the web browser? Because the test runner is a PHP script....

Just make file whatever.php

You can use the exec() & passthru() commands to run command line commands, like the PHP test runner, and send it's output to the browser. There's also html based reports PHPunit can dump, as well as phpundercontrol which has it's own reporting styles
jadent
Forum Newbie
Posts: 3
Joined: Fri Jan 21, 2011 10:43 pm

Re: Running PHPUnit from PHP instead of runner

Post by jadent »

Thanks but i don't want to run system commands because PHP takes 6 seconds to load.if i run it as a PHP script using the PHPUnit API and then run that through apache then PHP is already loaded and will run immediately.

Running a system command is exactly the same as running on the command line and will take 6 seconds just to load.

You used to be able to run it very easily by getting the result of a test suite and then just doring a $result->toString() or $result->toHtml() but PHPUnit's Framework doesn't provide that so not sure how to get the output easily.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Running PHPUnit from PHP instead of runner

Post by John Cartwright »

jadent wrote:Thanks but i don't want to run system commands because PHP takes 6 seconds to load.if i run it as a PHP script using the PHPUnit API and then run that through apache then PHP is already loaded and will run immediately.

Running a system command is exactly the same as running on the command line and will take 6 seconds just to load.

You used to be able to run it very easily by getting the result of a test suite and then just doring a $result->toString() or $result->toHtml() but PHPUnit's Framework doesn't provide that so not sure how to get the output easily.
Your PHP takes 6 seconds to load? Mine loads immediately from CLI.
jadent
Forum Newbie
Posts: 3
Joined: Fri Jan 21, 2011 10:43 pm

Re: Running PHPUnit from PHP instead of runner

Post by jadent »

there are numerous modules that take a while to load. any help on the PHPUnit script?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Running PHPUnit from PHP instead of runner

Post by josh »

PHPunit can take a few moments to analyze all your test files before it begins to execute tests. This hit comes only when running the entire suite at once, when I run only certain tests at once theres much less lag. I have 1,000+ tests with an average of 5 tests per class.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Running PHPUnit from PHP instead of runner

Post by VladSun »

If I understand your problem right, you may create a custom php.ini for your CLI tests.
It will load only the necessary modules thus your PHP CLI "loading" will be much faster:

Code: Select all

php -c /path/to/my-simple/php.ini `which phpunit` arguments.....
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply