NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
PHPUnit integration...


Joined: 16 Oct 2003
Posts: 22
Reply with quote
Hi,

I just wanted to share the string to use in order to integrate PHPEd with PHPUnit. For assumptions please read the section on assumptions.

1. Start Nusphere PHPEd
2. In the menu select: Select Tools > Settings
3. In the Settings dialog select: Tools > Integration
4. Select "Add menu"
5. Write PHPUnit
6. Select Edit
7. In "Execute with" select "Shell"
8. In "Command line" paste the following (or if you have installed PEAR to a different path - please update).
Code:

 "C:\Program\nusphere\TechPlat\apache\php\php.exe" -f "C:\Program\nusphere\TechPlat\apache\php\PEAR\PHPUnit\TextUI\Command.php" @BaseName@ "@FName@"

9. In Shortcut: E.g. __press__: Ctrl+Shift+T
10. Check "Show this command in Workspace popup" and check "for files".
11. Check "Show this command in Explorer popup" and check "for files".
12. Check "Show this command in Tools menu"
13. Check "Show this command in File Bar popup"
14. Check "Show this commanf for local files only"
15. Select "Redirect Output stream to log window"
16. Press Close and OK.
17. In the Workspace or Explorer window in NuSphere you may now right-click a file and select PHPUnit. If you open the file you might even press Shift+Ctrl+T to execute PHPUnit.
18. Verify the output in the log-window.

Assumptions
The instructions above assumes the following:
* NuSphere TechPlatform, PHP, PEAR and PHPUnit is installed on the system
* All PHPUnit-testfiles have the same class-name as filename.
* That Ctrl+Shift+T is availale as short-cut (default key mapping is for <td></td>). You can remove the key mapping by:
* Go to Tools > Settings > Editor > Editor shortcuts
* Scroll all the way down to <td> and select it
* Press delete to remove the key-mapping.

Code:

"C:\Program Files\nusphere\TechPlat\apache\php\.\php.exe" -d include_path=".;D:\path\to\PEAR;" -f "D:\path\to\PEAR\PHPUnit\TextUI\Command.php" @BaseName@ @FName@


Edit:
If you install PHPUnit with the PEAR Installer (and registered the path to PEAR in Windows environment variables) and you have added the PEAR-libraries to the include_path in php.ini you may shorten the above string to:

Code:

@php@ -f "D:\path\to\PEAR\PHPUnit\TextUI\Command.php" @BaseName@ @FName@


For more information see:
- http://www.phpunit.de/wiki

Best Regards,
Jan Bolmeson
View user's profileFind all posts by madwaxSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
applauds!

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
slightly updated instructions:

install phpunit
In order to install phpunit for php shipped with PhpED open cmd console (*) and type the following commands:
Code:
cd %PROGRAMFILES%\NuSphere\PhpED\php53
go-pear.bat
<press enter when it asks to install for system>
<at this point it will ask to install, enter `all', and update installation path ($prefix) to for example C:\MyPear if directory where installed PHP containst spaces>
<proceed with enter until it finished or prints ERRORs, see notes below on what to do in this case>
pear.bat channel-update pear.php.net
pear.bat upgrade-all
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear channel-discover pear.phpunit.de
pear.bat install phpunit/PHPUnit


*) Note: if you're logged in under unprivileged account (like W7 or Vista offers by default), you have to perform the commands in an elevated command prompt (you will find a lot of posts in the i-net on how to run elevated cmd).
**) Note: you may want to inquire PhpUnit maintainers about php versions is supported and make sure that you're updating php supported by current phpUnit.
***) Note: because of errors in php or phar, phar signature is not recognized or not applied. If you get "phar "go-pear.phar" does not have a signaturePHP, please add/uncomment the following line in php.ini:
phar.require_hash = On
and set this option to OFF:
phar.require_hash = Off
or open go-pear.bat in an editor and add -d phar.require_hash=0 like below
%PHP_BIN% -d output_buffering=0 -d phar.require_hash=0 PEAR\go-pear.phar
****) Note: Note: for some unknown reason it will fail to unpack Structures_Graph-1.0.4.tgz while performing pear.bat upgrade-all, so you may want to unpack it manually and copy Structures directory with all its content into PEAR subdirectory then re-run pear.bat upgrade-all

add PHPUnit command
1. Start Nusphere PHPEd
2. In the menu select: Select Tools > Settings
3. In the Settings dialog select: Tools > Integration
4. Select "Add menu"
5. Write PHPUnit
6. Select Edit
7. In "Execute with" select "Shell"
8. In "Command line" paste the following (or if you have installed PEAR to a different path - please update).
Code:
"@php5cli@" "C:\MyPear\phpunit"  "@FName@"

9. In Shortcut: E.g. __press__: Ctrl+Shift+T
10. Check "Show this command in Workspace popup" and check "for files".
11. Check "Show this command in Explorer popup" and check "for files".
12. Check "Show this command in Tools menu"
13. Check "Show this command in File Bar popup"
14. Check "Show this commanf for local files only"
15. Select "Redirect Output stream to log window" and "Redirect Error stream to log window"
16. Press Close and OK.

verifying the results
1. create the following file in phped:
Code:
<?php
    require_once 'PHPUnit/Framework.php';
    class ExpectedErrorTest extends PHPUnit_Framework_TestCase {
        /**
         * @expectedException PHPUnit_Framework_Error
         */
        public function testFailingInclude() {
            include 'not_existing_file.php';
        }
    }
?>

2. save it under test1.php name
3. right click on the test1.php file tab and select "PHPUnit"
4. open log winodow (View->Tabs->Log) and make sure that it contains testcase output, like below:
Code:
"C:\Program Files\NuSphere\PhpED\php5\php.exe" "C:\Program Files\NuSphere\PhpED\php5\phpunit" "C:\tests\Test1.php"
#!C:\Program Files\nusphere\PhpED\php5\.\php.exe
PHPUnit 3.3.17 by Sebastian Bergmann.

.

Time: 0 seconds

OK (1 test, 1 assertion)


Last edited by dmitri on Sun Jun 19, 2011 7:28 am; edited 11 times in total

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 30 Aug 2006
Posts: 116
Reply with quote
Just an update for PHPUnit 3.5.x there are some changes to the above procedures:

install phpunit
In order to install phpunit for php shipped with PhpED open cmd console and type the following commands:
Code:
cd %PROGRAMFILES%\NuSphere\PhpED\php5
go-pear.bat
<press enter when it asks to install for system>
<press enter when it asks to install all>
<press enter when it asks to quit>
pear.bat channel-update pear.php.net
pear.bat upgrade-all
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear.bat install phpunit/PHPUnit


The rest follow Dmitri's post.
View user's profileFind all posts by rudderSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Starting with phped 6.2 you can install both PEAR and phpUnit by clicking [check] button. See Tools->Settings->External Tools->Path to php PEAR.
The installation is fully automated.

As of how to write tests - please check
phpUnit manual: http://www.phpunit.de/manual/current/en/
and a real project suggested by the author https://github.com/sebastianbergmann/php-object-freezer/

Tests can be run from Tools->Show Test Suite [F6] window.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 10 Jun 2014
Posts: 7
Reply with quote
As of December 2014, PhpUnit will no longer be available via PEAR, since the channel is closing. The preferred installation method is either downloading a phar or using Composer. Until PhpEd introduces changes to cover this, here is a way of using a Composer-installed PhpUnit in the IDE.

Follow the instructions here to install PhpUnit, making sure you do a global system-wide installation. You can update PhpUnit in future by running the command:
composer global update phpunit/phpunit

The following must replace the phpunit file in your PEAR installation directory (see Path to php PEAR in Settings | External Tools).

Code:
<?php
    /*
      This script calls the global Composer installation of phpunit.
      If you are not using PHP5.4 +, you must replace PHP_BINARY
      with the PHPBIN value found in phpunit.bat 
    */

    $args[] = PHP_BINARY;

    if (!$path = getenv('COMPOSER_HOME')) {
        $path = getenv('APPDATA') . '/Composer';
    }

    $args[] = $path . '/vendor/phpunit/phpunit/phpunit';

    array_shift($argv);
    while($arg = array_shift($argv)) {
        $args[] = $arg;
    }

    $cmd = implode(' ', array_map('escapeshellarg', $args));
    return passthru($cmd);



Note that we call the file in a new php process - we cannot simply require it because it will not work if any tests are run in a seperate process.

Also, beware that if you run Check Path to php PEAR then agree to check phpunit from the message box, it will fail - if you choose to install/reinstall it, the above file will be overwritten.
View user's profileFind all posts by JohnStevensonSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
I'm not sure what you meant here if (!$path = getenv('COMPOSER_HOME')) {. Why !$path? Perhaps it should be: if (!($path = getenv('COMPOSER_HOME'))) {, so if COMPOSER_HOME is not sure, it will be substituted from %APPDATA% + Composer subpath

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 10 Jun 2014
Posts: 7
Reply with quote
getenv returns either a string containing the environment variable value or FALSE.

So this is fine:
Code:

    if (!$path = getenv('COMPOSER_HOME')) {
        $path = getenv('APPDATA') . '/Composer';
    }

because $path will be %APPDATA%/Composer if COMPOSER_HOME has not been set. There is only a need for extra brackets if the if statement contains more than one condition, though I guess it is also a matter of personal coding styles.
View user's profileFind all posts by JohnStevensonSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
ok. It's yet another PHP quirk then.
In C something like if (!somevar = somevalue) wouldn't be even compiled b'ze ! is a unary operator

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
PHPUnit integration...
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic