I have the following code:
<?php
class MyTest extends PHPUnit_Framework_TestCase
{
public function testCalculate()
{
$this->assertEquals(2, 1 + 1);
}
}
?>
When I open the PHP file in the browser, I get the following error:
Fatal error: Class 'PHPUnit_Framework_TestCase' not found
However, if I use the command line it works fine: phpunit [local_path_here]/testcase.php
Result:
.
Time: 0 seconds, Memory: 5.00Mb
OK (1 test, 1 assertion)
Why is that? How can I make it to run it in the browser as well?
You may have a different include path on the command line. Check to see whether you have a
php-cli.ini
file in addition to the normalphp.ini
file. The first one will be used when you run PHP from the command line. That's probably got a differentinclude_path
setting. It might include the PEAR directory, for example, if PHPUnit was installed via PEAR.You can integrate add-on for running unit tests via native web GUI:
https://github.com/NSinopoli/VisualPHPUnit
You can't run unit tests in the browser. Maybe in the future: http://sebastian-bergmann.de/archives/638-PHPUnit-3.0.html#c4983
If you want to view the code coverage run
and then open the index.html file in the coverage directory.
Otherwise, you have to run your tests from the command line.
You can use eclipse also to run phpunit. follow the link below
http://pkp.sfu.ca/wiki/index.php/Configure_Eclipse_for_PHPUnit