PHPUnit Woes

Using PS-98.21, on osx 10.6.4...

I'm trying to get started with PHPUnit and having some problems.  I've installed it and a test class seems to recognize phpunit stuff, but when it runs it says no tests were found.  I took a *very* basic example from the phpunit doc and the inspector thinks everything is fine:

<?php

require_once 'PHPUnit/Framework.php';

class StackTest extends PHPUnit_Framework_TestCase

{

    public function testPushAndPop()

    {

        $stack = array();

        $this->assertEquals(0, count($stack));

        array_push($stack, 'foo');

        $this->assertEquals('foo', $stack[count($stack) - 1]);

        $this->assertEquals(1, count($stack));

        $this->assertEquals('foo', array_pop($stack));

        $this->assertEquals(0, count($stack));

    }

}

?>

I've also tried without success to get phpstorm to generate a test class for me.  There I get an error "Failed to execute PHP script.  Please check your PHPUnit configuration".  Below is a screen shot of my php config.
Screen shot 2010-10-01 at 4.17.13 PM.png
My directories ONLY include my project, the help referred to adding PEAR to it, I tried that and didn't seem to make a difference.

Here is what my /usr/lib/php directory looks like in case that helps:

Archive PEAR.php SymfonyComponents doc peclcmd.php

Console PEAR5.php System.php extensions test

Log PHP Text ezc

Log.php PHPUnit XML gengraph.php

OS PhpDocumentor build modules

PEAR Structures data pearcmd.php

I know is probably something stupid, but those things are easy to fix, right?

Thanks
-Doug

8 comments

I will not be able to help you with the 2nd issue ("get phpstorm to generate a test class for me" -- I've used this feature only once, in v1 and it worked ok -- not perfect but ok) but will attempt with the first one.

First of all (which may solve the issue for you straight away): what the filename of the test file? I'm not really using tests ATM, but when I was trying to do them (with success in the end) I had similar issue ("no tests were found"). To solve this -- you have to name your file with word "Test" in it. For example: SimpleTest.php, ComplexTest.php.

If that will not help, then I will post my setup here in pictures, so that you can see and compare (but it's gonna be tommorow, Saturday)

0

Hello Doug,

Did you add '/usr/lib/php' entry manually, or it came from php.ini when you clicked 'Update incude paths'?
Which version of PHPUnit are you using?

Regards,
Kirill

0

Andriy-

The name of the file matches the actual class - StackTest.php.  I'm a java person mostly so that habit is hard to break.  Thanks for any info you can throw my way.

-Doug

0

Kirill-

It came up by clicking on update include paths.  And the version of phpunit is:

About pear.phpunit.de/PHPUnit-3.4.8


Thanks for your help.
-Doug
0

Sorry for delay with my response.

I'm using Windows 7, so the paths and locations are different from MacOS, but I'm sure you will get the idea what and where you need to check based on my details and screenshots.

My PHPUnit version is 3.4.15 -- so it should work in the same way as your 3.4.8. There are (or were) some issues with v3.5 of PHPUnit in PhpStorm build 98.21, like these: http://youtrack.jetbrains.net/issue/WI-3198?projectKey=WI&query=phpunit, http://youtrack.jetbrains.net/issue/WI-3326?projectKey=WI&query=phpunit. Just make sure that the 3.4.x branch is used during tests if you have more than one version of PHPUnit installed.



My PHP is installed in "E:\Projects\php".
PEAR folder is located inside PHP folder: "E:\Projects\php\PEAR".
PHPUnit, accordingly, is located in "E:\Projects\php\PEAR\PHPUnit".

That is what I have in my php.ini:

include_path = ".;E:\Projects\php\PEAR"


Screenshot #1
That's my test project: classes are located in "Core2" folder, and tests (only 2) in "tests" folder (actually in "tests\Helpers" .. but that makes no difference -- this just to have the same folders structure as in classes folder).

Screenshot #2
This is my Run/Debug Configuration for all tests (will run all tests available). The tests will be run locally (console/terminal).
Screenshot #3
The same but for individual test -- as you can see nothing major here -- just a folder or file to test (everything else was left on defaults).

Screenshot #4
Run Results: all tests in 2 test files were run successfully (I've made only 2 test files for 2 classes.. did not really bother with the rest).

Screenshot #5
Results of running PHPUnit manually in console/terminal.

I recommend you to check if you can run the test manually:
1) in terminal navigate to the folder where your  StackTest.php is located
2) type "phpunit  StackTest" or "phpunit StackTest.php" (without quotes) and execute

If it will not run then there are some issues with your PHPUnit installation or PHP configuration .. or even with test file itself (I don't know -- maybe try to remove BOM signature from StackTest.php if it present .. but if that would be the case then I would see some 3-character gibberish just before "PHPUnit 3.4.15 by Sebastian Bergmann." text in output).


I hope this will make any sense to you and will help you in any way (that's in case if you have not resolved this issue already).

Regards,
Andriy

Message was edited by: Andriy Bazanov; Reason -- corrected some typos.



Attachment(s):
screen_00_5.png
screen_00_4.png
screen_00_3.png
screen_00_2.png
screen_00_1.png
0

Hello Doug,

Can you try run the tests with default command line runner or any other tool?
You may also try reinstalling PHPUnit:

pear install -f phpunit/PHPUnit-
3.4.8.

Regards,
Kirill

0

Hi Kirill-

Sorry meant to post back to this yesterday, busy day.

I get a seg fault when running it command line so there appears to be a bigger issue here.   I posted the seg fault issue separately as its clearly not the ide's issue.  http://stackoverflow.com/questions/3855912/phpunit-gets-segmentation-fault

Of course I'd still appreciate any clues anyone might have.

Thanks
-Doug

0

Found the culprit... inclued.so extension was causing the problem in my php.ini.

I reverted back to the original osx php.ini and things worked, so I went back to the problem version of php.ini, removed one thing at a time and inclued extension was the winner!
PHP and PHPUnit now behaves quite nicely.

0

Please sign in to leave a comment.