First we have to install PEAR.
If you do not have “go-pear.phar” file at your PHP folder you should download it from the “pear.php.net/go-pear.phar” web address, create a folder called “pear” at your PHP folder (for ex: C:\wamp\bin\php\php5.3.8) and then place the “go-pear.phar” file into it. Then open a command prompt and type the following command:
php .\pear\go-pear.phar
By the way, in order not to encounter any problem during command prompt operations, I recommend you to open the command prompt windows with “Run as administrator” option throughout this tutorial.
Just press ENTER as a reply to the following question:
Then press ENTER in order to accept all of the paths listed:
Reply as “Y” to the following question:
Then press ENTER again to finish the installation.
Now your pear installation is completed:
After the installation, add your php directory (for ex: C:\wamp\bin\php\php5.3.8) to the system environment variable “PATH” in order to be able to call “pear.bat” from any location (if you have not added yet before the pear installation).
Moreover, it is better to run “PEAR_ENV” registry file located at your PHP folder (for ex: C:\wamp\bin\php\php5.3.8) in order to add useful environment variables.
From now on we can install PHPUnit using pear. First we can check whether it is updated by the following command:
pear upgrade-all
After we are sure that it is updated, we should add the following channels:
pear channel-discover components.ez.no
pear channel-discover pear.phpunit.de
pear channel-discover pear.symfony-project.com
If something goes wrong with the above pear commands you could try the “pear clear-cache” command to make sure that the installer does not use cached data.
Finally, we can install the PHPUnit using the following command:
pear install –alldeps phpunit/PHPUnit
The following components are installed:
phpunit/PHPUnit can optionally use PHP extension “curl”
phpunit/PHPUnit can optionally use PHP extension “dbus”
phpunit/PHPUnit_MockObject can optionally use PHP extension “soap”
pear/HTTP_Request2 can optionally use PHP extension “curl”
pear/HTTP_Request2 can optionally use PHP extension “fileinfo”
pear/HTTP_Request2 can optionally use PHP extension “openssl”
downloading PHPUnit-3.5.15.tgz …
Starting to download PHPUnit-3.5.15.tgz (118,859 bytes)
……………………..done: 118,859 bytes
downloading DbUnit-1.0.3.tgz …
Starting to download DbUnit-1.0.3.tgz (39,292 bytes)
…done: 39,292 bytes
downloading File_Iterator-1.2.6.tgz …
Starting to download File_Iterator-1.2.6.tgz (3,439 bytes)
…done: 3,439 bytes
downloading Text_Template-1.1.0.tgz …
Starting to download Text_Template-1.1.0.tgz (2,783 bytes)
…done: 2,783 bytes
downloading PHP_CodeCoverage-1.0.5.tgz …
Starting to download PHP_CodeCoverage-1.0.5.tgz (115,040 bytes)
…done: 115,040 bytes
downloading PHP_Timer-1.0.2.tgz …
Starting to download PHP_Timer-1.0.2.tgz (3,686 bytes)
…done: 3,686 bytes
downloading PHPUnit_MockObject-1.0.9.tgz …
Starting to download PHPUnit_MockObject-1.0.9.tgz (18,414 bytes)
…done: 18,414 bytes
downloading PHPUnit_Selenium-1.0.3.tgz …
Starting to download PHPUnit_Selenium-1.0.3.tgz (16,587 bytes)
…done: 16,587 bytes
downloading YAML-1.0.6.tgz …
Starting to download YAML-1.0.6.tgz (10,010 bytes)
…done: 10,010 bytes
downloading XML_RPC2-1.1.1.tgz …
Starting to download XML_RPC2-1.1.1.tgz (68,431 bytes)
…done: 68,431 bytes
downloading ConsoleTools-1.6.1.tgz …
Starting to download ConsoleTools-1.6.1.tgz (869,994 bytes)
…done: 869,994 bytes
downloading PHP_TokenStream-1.0.1.tgz …
Starting to download PHP_TokenStream-1.0.1.tgz (7,250 bytes)
…done: 7,250 bytes
downloading HTTP_Request2-2.0.0.tgz …
Starting to download HTTP_Request2-2.0.0.tgz (97,476 bytes)
…done: 97,476 bytes
downloading Cache_Lite-1.7.12.tgz …
Starting to download Cache_Lite-1.7.12.tgz (30,469 bytes)
…done: 30,469 bytes
downloading Base-1.8.tgz …
Starting to download Base-1.8.tgz (236,357 bytes)
…done: 236,357 bytes
downloading Net_URL2-2.0.0.tgz …
Starting to download Net_URL2-2.0.0.tgz (11,325 bytes)
…done: 11,325 bytes
install ok: channel://pear.phpunit.de/File_Iterator-1.2.6
install ok: channel://pear.phpunit.de/Text_Template-1.1.0
install ok: channel://pear.phpunit.de/PHP_Timer-1.0.2
install ok: channel://pear.phpunit.de/PHPUnit_Selenium-1.0.3
install ok: channel://pear.symfony-project.com/YAML-1.0.6
install ok: channel://pear.php.net/Cache_Lite-1.7.12
install ok: channel://components.ez.no/Base-1.8
install ok: channel://pear.php.net/Net_URL2-2.0.0
install ok: channel://pear.phpunit.de/DbUnit-1.0.3
install ok: channel://pear.phpunit.de/PHPUnit_MockObject-1.0.9
install ok: channel://components.ez.no/ConsoleTools-1.6.1
install ok: channel://pear.php.net/HTTP_Request2-2.0.0
install ok: channel://pear.php.net/XML_RPC2-1.1.1
install ok: channel://pear.phpunit.de/PHP_TokenStream-1.0.1
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.0.5
install ok: channel://pear.phpunit.de/PHPUnit-3.5.15
After the installation has finished, we can check the PHPUnit version as follows:
Before the Eclipse integration part, we can check whether it works correctly at the command prompt:
As we have completed PHPUnit installation, it is time to integrate it with Eclipse.
PHPUnit can be integrated into Eclipse environment via “External Tools Configurations” feature of the Eclipse IDE. Firstly, you should open the “External Tools Configurations” window through the path “Run->External Tools-> External Tools Configurations…” as follows:
Here you should select the option and then click on “New launch configuration” button (). Then give “PHPUnit” as the name of the new configuration. Moreover you should specify the path for the “phpunit.bat” file and the path for your unit tests location as below:
The working directory should be set as $(container_loc) via the “Variables…” button in order to adjust the working directory as the absolute file system path of the unit test file:
Lastly, the “Arguments” part of the configuration windows should be set as $(resource_name). This could be set again by the “Variables…” button as below:
After these settings are done, you should apply them and close the window. From now on you can run your phpunit tests by selecting the test file from the explorer and clicking the “Run external Tools” button () which is in this case “Run PHPUnit”:
The results are shown at the “Console” window:
Adnan Kalay
Traceper Team
www.ankara-gtug.org
Không có nhận xét nào:
Đăng nhận xét