Simpletest Eclipse Plugin
Compatibility
-
Operating System.
This plugin should work on any platform on which Eclipse works. Specifically the plugin has been tested to work on Linux, OS X, and Windows. If the plugin does not appear to work on one of these platforms a new incompatibility may have emerged, but this is relatively unlikely. -
Eclipse
The plugin has been designed to work with Eclipse versions 3.1.X+ and 3.2.X+. Eclipse in general requires a JVM version of 1.4.x; there are no additional requirements for the plugin. -
PHP
The plugin has been tested to work with PHP 4.3.x+ (including PHP 5.1.x.). -
Xdebug
The plugin can be configured to work with Xdebug (version 2.0.0RC1 or later). The php.ini file which is used by the plugin (see below for specifying the php.ini file) must load the Xdebug extension. This is usually accomplished by adding a zend_extension_ts="Some Windows Path" or zend_extension="Some Linux Path" to your php.ini file. Specific instructions can be found at: http://xdebug.org/install.php Do not worry about specifying any other parameters, the plugin will handle setting the necessary parameters, as needed. -
Simpletest
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. PHPUnit3 is not currently supported but will be supported in the near future.
Installation
- Download and Install Eclipse (www.eclipse.org) – if you are not sure what to download, download the Eclipse 3.1.0 SDK.
- Download the latest Simpletest Eclipse plug-in zip file (Simpletest Sourceforge)
- Extract the zip file to a temporary location {this will be referred to later in this documentation as $unzip}
- Start Eclipse
- Open the Install Wizard by clicking "Help" > "Software Updates" > "Find and Install" from the menu bar.
- Select the second button, "Search for new features to install" and click "Next".
- Click the button on the right hand side, "New Local Site".
- Select the folder $unzip {the folder extracted previously}.
- Click the "OK" button.
- In the "Edit Local Site" window, Click the "OK" button
- Click the "Finish" button
- In the "Search Results" window, drill down and select "Simpletest plug-in 0.0.x"
- Click the "Next" button.
- Read the license and accept the license by clicking the "I accept the terms in the license agreement" radio button and then clicking the "Next" button
- In the "Installation" window you can choose to change the location -- most users should just click the "Finish" button
- In the "Feature Verification" window, click the "Install" button.
- When prompted, restart Eclipse
-
After starting Eclipse for the first time after installation you will need to perform a quick configuration of the Simpletest Plug-in. To perform this configuration:
- Select "Window" > "Preferences" from the menu bar
- Select "Simpletest" from the categories on the left hand side of the popup box.
- 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.
- Hit the "Ok" button to close the preferences window.
Update Existing Installation
- Select "Help" > "Software Updates" > "Manage Configuration" from the menu
- Drill down to find the Simpletest plugin and select it
- In the right hand pane click the link for "Scan for Updates"
- IF no updates are found, navigate to Window > Preferences > Install/Update > Valid Updates in the Eclipse preferences and select 'Compatible', not 'equivalent'. Then repeat the steps above.
- Select the feature versions that you wish to upgrade, and click "Next".
- Review the license agreements for the upgraded features. If the terms of all these licenses are acceptable, check "I accept the terms in the license agreements." Do not proceed to download the features if the license terms are not acceptable.
- Click "Install" to allow the downloading and installing to proceed.
- Once all the features and plug-ins have been downloaded successfully and their files installed into the product on the local computer, a new configuration that incorporates these features and plug-ins will be formulated. Click Yes when asked to exit and restart the Workbench for the changes to take effect.
Uninstall
Note: this will only work if the plugin was installed via the Feature Update method. If installed via alternate methods, then the plugin can be uninstalled by deleting the directories which were previously added.
- Select "Help" > "Software Updates" > "Manage Configuration"
- Drill down to find the Simpletest plugin
- Right-click on the Simpletest plugin and select the option "Disable"
- when prompted, restart Eclipse
- After Eclipse has restarted, select "Help" > "Software Updates" > "Manage Configuration" from the menu bar
- Select the option from the toolbar "Show Disabled Features"
- Drill down to find the Simpletest plugin
- Right-click on the Simpletest plugin and select the option "Uninstall"
- When prompted, restart Eclipse
Usage
The following details some sample usages of the plugin.
- Create a new test project (a holding place for related files)
- Select "File" > "New" > "Project.." from the menu
- Expand the folder "General" 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".
Future Features
These are features that should eventually make it into this plugin
- Allow different "include" file on each runner (override the "master" include)
- Handle fatal errors better