I know PHPUnit tests can be executed from the command line, but is there an easy way to run it from the browser. For example, I have:
class testsSuite extends PHPUnit_Framework_TestSuite
{
public function __construct ()
{
$this->setName('testsSuite');
$this->addTestSuite('MyFirstTest');
}
public static function suite ()
{
return new self();
}
}
And then I have:
class MyFirstTest extends PHPUnit_Framework_TestCase
{
protected function setUp ()
{
parent::setUp();
}
protected function tearDown ()
{
parent::tearDown();
}
public function __construct ()
{
}
public function test__construct ()
{
}
public function test__destruct () {
}
public function testCalculateCost ()
{
print 1; die();
}
}
Is there a URL I can enter in my browser to execute this test? Something like:
http://localhost/tests/testsSuite/calculateCost
Or something similar
From the Menu-bar, select Run | Run As | PHPUnit Test . To debug the PHPUnit Test Case, click the arrow next to the debug button on the toolbar, and select Debug As | PHPUnit Test . From the Main Menu, select Run | Debug As | PHPUnit Test . The unit test will be run and a PHP Unit view will open.
PHPUnit InstallationThe first command creates a folder in your current directory, test-project and the second command moves into it. The last command starts an interactive shell. Follow the prompt, filling in the details as required (the default values are fine).
There is VisualPHPUnit.
At work we sometimes run from browser, using in its basic form a php-script containing:
$argv = array(
'--configuration', 'phpunit.xml',
'./unit',
);
$_SERVER['argv'] = $argv;
PHPUnit_TextUI_Command::main(false);
So you basically put all parameters you normally type on the commandline in an array, and set it in the $_SERVER-global. PHPUnit_TextUI_Cmmand::main(false); then runs your tests. The false-parameter makes sure no exit() is called. In the PHPUnit.xml I configure to log to a JSON file, and the php-script reads that file to show the results (which it can do after the tests because no exit was called).
Note: this is very barebone, simplistic and crude.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With