Simple test for PHP 0.1.9
Test your PHP code with the Simpletext PHP unit test framework, and experimental support for PHPUnit2.
Download Simple test for PHP 0.1.9:
SimpleTest is a PHP testing framework built around test case classes.
Simpletest provides unit testing, mock objects and web testing framework for PHP built around test cases. Simpletest also adds JWebUnit style testing including cookies, authentication and form handling, and experimental support for PHPUnit2.
Tests are written as extensions of base test case classes, each extended with methods that contain test code. Top level test scripts then invoke the run() methods on every test cases. Each test method is written to perform assertions (the tests themselves) that the developer expects to be true. Examples are assertEqual() that tests the equality of the output of two expressions. If the expectation is correct, then a successful result is dispatched to the observing test reporter, but any failure triggers an alert and a description of the mismatch.
If you are familiar with JUnit or some of the PHPUnit clones Simpletest is similar.
The plugin has been tested to work with PHP 4.3.x+ (including PHP 5.0.x.).
The plugin has been designed to work with a specific version of Simpletest and in fact includes the associated version of Simpletest in the plugin for compatibility. A plugin with a version number of 1.0.0_0.0.4 would indicate that the plugin was compatible with Simpletest version 1.0.0 and was version 0.0.4 of the plugin. Some slight modifications to the Simpletest code are required to make the plugin work with Simpletest; these modifications may or may not be in the released version of Simpletest.
PHPUnit2
Starting with plugin version 0.1.6 experimental support for the CVS version of PHPUnit2 is available. To use PHPUnit2 select a path to PHPUnit2 and select PHPUnit2 test instead of SimpleTest. Note: this is the path to the folder that contains the PHPUnit2 folder.
Getting started
To get started with Simpletest:
- Select the menu "Window" -> "Preferences"
- Select "Simpletest" from the categories on the left hand side of the popup window.
- Enter or Browse for the location of a PHP executable to use.
- Leave the include file blank
- Enter .php as the Test File Suffix. Alternately if you name your test PHP files with a sufficiently different suffix (e.g sometest.tst.php) you could enter in a more differentiating suffix (e.g. .tst.php). This helps when the plug-in is looking for tests to execute.
- Click the "Ok" button to close the preferences window.
Once the plugin is configured, you can start using it:
- Create a new test project (a holding place for related files)
- Select "File" > "New" > "Project.." from the menu
- Expand the folder "Simple" and select "Project"
- Click the "Next" button
- On the next tab enter a project name: "Test"
- Use the default Project Contents
- Click the "Finish" button
- Create a Single Passing Test
- In the Package Explorer View right-click on the "Test" project and select "New" > "File".
- For the filename enter: test1.php and click "Finish"
- Double-click on the test1.php entry in the Package Explorer which should open a new view to edit the file.
- Enter the following for the contents of the file:
<?php class test1 extends UnitTestCase { function test_pass(){ $x = 1; $y = 2; $total = $x + $y; $this->assertEqual(3,$total, "This should pass"); } } ?>
- Select "File" > "Save" from the menu.
- Right click on the test1.php entry and select "Run" > "Run Simpletest".
- The "Result View" should populate with information about the test run and the Simpletest console should fill with some information as well.
- Single Test class multiple tests
- In the Package Explorer View right-click on the "Test" project and select "New" > "File".
- For the filename enter: test2.php and click "Finish".
- Double-click on the test2.php entry in the Package Explorer which should open a new view to edit the file.
- Enter the following for the contents of the file:
<?php class test2 extends UnitTestCase { function test_pass(){ $x = 1; $y = 2; $total = $x + $y; $this->assertEqual(3,$total, "This should pass"); } function test_fail(){ $x = 1; $y = 2; $total = $x + $y; $this->assertEqual(4,$total,"This should fail"); } } ?>
- Select "File" > "save" from the menu bar.
- Right click on the test2.php entry and select "Run" > "Run Simpletest".
- The Result View should populate with information about the test run and the Simpletest console should fill with some information as well
- Group Tests (test multiple files at once)
- In the Package Explorer View right-click on the "Test" project and select "New" > "File"
- For the filename enter: grouptest.php and click "Finish".
- Double-click on the grouptest.php entry in the Package Explorer which should open a new view to edit the file.
- Enter the following for the contents of the file:
<?php class myGroupTest extends GroupTest { function myGroupTest() { parent::GroupTest(''); $this->addTestFile(dirname(__FILE__).'/test1.php'); $this->addTestFile(dirname(__FILE__).'/test2.php'); } } ?>
- Select "File" > "save" from the menu
- Right click on the grouptest.php entry and select "Run" > "Run Simpletest"
- The Result View should populate with information about the test run and the Simpletest console should fill with some information as well
Known Issues
- Make sure that if a constructor is used in the test case that the last line of the constructor calls the parent constructor (e.g. parent::UnitTestCase)
- Do not put any assertions into the test class constructor
- If you get an error indicating that a class could not load; then restart Eclipse. Once Eclipse restarts, open the Result View manually by selecting "Window"->"Show View"->"Other..." Then select the SimpleTest Category and select "Result View" and click "OK".
To get started with PHPUnit tests, you can use those sample tests:
<?php require_once 'PHPUnit2/Framework/TestCase.php'; class phpunit2test extends PHPUnit2_Framework_TestCase { public function testPass() { $this->assertEquals(1, 1); } public function testFail() { $this->assertEquals(2, 3); $this->assertEquals(1, 2); } public function testError() { throw new Exception("Error"); } } ?>
Requirements and limitations
- Beta release - We have not yet fully tested this plugin. Please report a bug for any problem you encounter. We welcome your feedback (positive and negative!) in the forums, mailing lists and bug trackers.
- This plugin will run with any distribution of EasyEclipse.
- It may also work with a standard installation of Eclipse 3.1.2. We have not tested it, though.
- This plugin is present in the following distributions:
Links
- Simple test for PHP home
- Simple test for PHP provides support for the PHPUnit framework.
- Simple test for PHP provides support for the Simpletest framework.
- Simple test for PHP provides support for the PHP programming language.
Changelog
Changes in EasyEclipse 1.0.1:
- Initial release (with Simple test for PHP 0.1.9).
Credits and License
Credits: Steven Balthazor, Marcus Baker, Jason Sweat, Clay Loveless, Demian Turner, Neil Green, Michael Krenz, Dmitry Polyakov, Perrick Penet, Travis Swicegood
Copyright (c) 2005-2006 Steven Balthazor. All rights reserved.
This plugin is licensed under the Eclipse Public License 1.0 license.
the plugin is licensed under the EPL. Simpletest (the framework) is licensed under the The Open Group Test Suite License. Visit http://www.simpletest.org/ric_LICENSE.html for more details.