Simple test for PHP

Test your PHP code with the SimpleTest PHP unit test framework, and experimental support for PHPUnit2.

Download Simple test for PHP 0.2.0 for EasyEclipse 1.2.2:

(336KB)  (296KB)  (224KB)

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.

There are currently 6 comments for this plugin. You can review them and add more here.

Installing this plugin

This plugin is in the EasyEclipse for LAMP and EasyEclipse for PHP distributions.

You can also install it on any EasyEclipse distribution, because it has no dependencies.

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. Enter or Browse for the location of the php.ini executable to use. This does not matter at first, and can be an empty file - but it has to exist.
  5. Leave the include file blank.
  6. 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.
  7. 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 General 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");
        }
        }
        ?>
        

Useful links

Changelog

Changes in EasyEclipse 1.2.1.1:

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.
    

6 Comments »

Comment by Patrick
2007-09-17 13:22:05

Howdy,
I’ve just installed easyeclipse-php-1.2.2.2 on Ubuntu Feisty, and I can’t get this demo to run. After following the instructions for the test1.php file, I get this error in the console when I try to run:

Running:
echo “addTestFile($fullpath);$test->run(new XmlReporter()); ?>” | “/usr/bin/php” -q -c “/etc/php5/cli/php.ini”
*************
Warning: include_once(eclipse.php): failed to open stream: No such file or directory in /tmp/Simpletest17666.php on line 1
Warning: include_once(): Failed opening ‘eclipse.php’ for inclusion (include_path=’.:/usr/share/php:/usr/share/pear:/opt/easyeclipse-php-1.2.2.2/plugins/net.sf.simpletest.eclipse_0.2.0′) in /tmp/Simpletest17666.php on line 1
Fatal error: Class ‘GroupTest’ not found in /tmp/Simpletest17666.php on line 1
Process returned: 255
Read error:Stream closed
Process error:
Read error:Bad file descriptor

In the error message I can see “$test=new GroupTest($filename);” which appears to be the source of the error.

In Windows->Preferences->Simpletest, I’ve set:
Php.exe file = /usr/bin/php
php.ini file = /home/pb/empty.ini // also tried /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini
Simpletest Path = /opt/easyeclipse-php-1.2.2.2/plugins/net.sf.simpletest.eclipse_0.2.0

Any help appreciated.

P.S. If I want to ensure that previous easyeclipse usage isn’t messing with me, what configuration files should I delete? ~/.eclipse? any others?

 
Comment by papifields
2007-09-27 12:31:44

Try leaving the Simpletest Path blank .. Had the same problem and leaving it blank fixed it ..

 
Comment by Francesco
2009-05-05 09:36:53

Hi, i know the post is a bit outdated but i’m trying now to work with Eclipse 3.4 and SimpleTest 1.0.0 (downloaded from ubuntu repositories) and SimpleTest Plugin 0.2.5. I’m having this problem, also leaving the field SimpleTest path empty in the plugin configuration page.

Any idea? Thanks in advance :)

 
Comment by Buzz
2009-07-16 06:36:24

I met the same problem as Francesco, but I made it solved.

There is a file of simpletest_php.zip in C:\eclipse\plugins\net.sf.simpletest.eclipse_0.2.5, you should unzip it into a subfolder named simpletest_php, and in Windows->Preference->Simpletest, specifying simpletest path to this subfolder, then it will work!

 
Comment by AK
2011-03-02 05:44:19

I have just installed the simpletest extension on eclipse but i cant get it to run the tests, it keeps giving me an error

‘Launching myproject_simpletest’ has encountered a problem.

An internal error occured during: “Launching myproject_simpletest”.

Can you please help with this.

 
Comment by mukesh sheoran
2012-02-06 22:52:48

same problem here!!1

 
Your name (required for validation and display)
Your e-mail (required for validation but never displayed)
Your website URL (optional for display)
Your comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.