Skip to content

Instantly share code, notes, and snippets.

@umanda
Last active August 29, 2015 14:16
Show Gist options
  • Save umanda/9754641f5336f738ad87 to your computer and use it in GitHub Desktop.
Save umanda/9754641f5336f738ad87 to your computer and use it in GitHub Desktop.
Set up PHPUnit in Windows + XAMPP + Eclips
<?php
class HelloTest extends \PHPUnit_Framework_TestCase {
public function testTrueIsTrue()
{
$foo = true;
$foo2 = false;
$this->assertTrue($foo);
$this->assertFalse($foo2);
}
}
Requirement (Windows)
1. PHP 5.3.3 or higher
2. dom, json, pcre,reflection,spl extensions
3. Xdebug 2.1.3 or higher , tokenizer (For code coverage support)
4. xmlwriter extension ( For log code coverage)
5. phar extention ( for PHP Archive)
6. openssl (for --self-update function)
* most of the extensions are built in xampp. but make sure whether those enable or not
Install PEAR
1. Go to http://pear.php.net/go-pear.phar
2. Save file into your PHP directory. This directory comprise the php.exe
3. Open command prompt as a "Administrator" mode (To do that right click on cmd.exe then select "Run as administrator").
4. Navigate PHP installation directory via cmd
5. Type php go-pear.phar and hit Enter
6. After run this, Add the "pear" directory path in to "Environmental Variable" list from control panel
7. To verify pear is working, execute pear version
Install PHPUnit
1. Open command prompt as a "Administrator" mode (To do that right click on cmd.exe then select "Run as administrator").
2. Execute command pear config-set auto_discover 1
3. Execute command pear install pear.phpunit.de/PHPUnit
4. To verify PHPUnitis is working, execute phpunit --version
How to run:
Configure Eclipse:
1. Open Eclipse
2. Select "Run" from menu bar and go to Run > External Tools > External Tools Configuration...
3. Right click on "Program" link and select New (Left hand side pane in External Tools Configuration window)
4. Give a proper name in "Name" section (i.e PHPUnit Test )
5. In "Location" in "Main" tab add the "phpunit.bat" path (ie C:\xampp\php\phpunit.bat)
6. In "Working Directory" in "Main" tab add the ${workspace_loc}
7. In "Arguments" in "Main" tab add the ${selected_resource_loc}
8. Select "Apply" and then "Close"
Run test cases
1. Select the test case or test suit
2. Select "Run" from menu bar and go to Run > External Tools > PHPUnit Test
* "PHPUnit Test" is name has given to the previously in "Configure Eclipse" step 4. So this name will differ according to your configurations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment