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:

(296KB)  (280KB)  (200KB)

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:

  1. Select the menu "Window" -> "Preferences"
  2. Select "Simpletest" from the categories on the left hand side of the popup window.
  3. Enter or Browse for the location of a PHP executable to use.
  4. Leave the include file blank
  5. 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.
  6. Click the "Ok" button to close the preferences window.

Once the plugin is configured, you can start using it:
  1. Create a new test project (a holding place for related files)
    1. Select "File" > "New" > "Project.." from the menu
    2. Expand the folder "Simple" and select "Project"
    3. Click the "Next" button
    4. On the next tab enter a project name: "Test"
    5. Use the default Project Contents
    6. Click the "Finish" button
  2. Create a Single Passing Test
    1. In the Package Explorer View right-click on the "Test" project and select "New" > "File".
    2. For the filename enter: test1.php and click "Finish"
    3. Double-click on the test1.php entry in the Package Explorer which should open a new view to edit the file.
    4. 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");
              }
              }
              ?>
              
    5. Select "File" > "Save" from the menu.
    6. Right click on the test1.php entry and select "Run" > "Run Simpletest".
    7. The "Result View" should populate with information about the test run and the Simpletest console should fill with some information as well.
  3. Single Test class multiple tests
    1. In the Package Explorer View right-click on the "Test" project and select "New" > "File".
    2. For the filename enter: test2.php and click "Finish".
    3. Double-click on the test2.php entry in the Package Explorer which should open a new view to edit the file.
    4. 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");
              }
              }
              ?>
              
    5. Select "File" > "save" from the menu bar.
    6. Right click on the test2.php entry and select "Run" > "Run Simpletest".
    7. The Result View should populate with information about the test run and the Simpletest console should fill with some information as well
  4. Group Tests (test multiple files at once)
    1. In the Package Explorer View right-click on the "Test" project and select "New" > "File"
    2. For the filename enter: grouptest.php and click "Finish".
    3. Double-click on the grouptest.php entry in the Package Explorer which should open a new view to edit the file.
    4. 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');
              }
              }
              ?>
              
    5. Select "File" > "save" from the menu
    6. Right click on the grouptest.php entry and select "Run" > "Run Simpletest"
    7. The Result View should populate with information about the test run and the Simpletest console should fill with some information as well

Known Issues
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

Links

Changelog

Changes in EasyEclipse 1.0.1:

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.