Generate PHPUnit Test context option missing?

I can't tell if there's a bug here or if I'm just missing something obvious.

I see in the documentation that there should be a Generate PHPUnit Test from <selected_class_name> option in the context menu when I right-click a class file if I have PHPUnit setup correctly.  I've configured PHPUnit and it works fine on the command line and inside PhpStorm.

Code assist from within the test classes I create works fine, running my test configuration runs all tests I've defined in my test suite successfully.  Everything seems great except that I don't have that generate test class option in my context menu.

I'm attaching a picture of the entire context menu I get when I right click on an ArrayUtils.php class file.  Shouldn't the Generate PHPUnit Test option show up right around the "Create ArrayUtils.php..." option?  Am I looking in the wrong place entirely?

Just to verify my PHPUnit itself is fine, I've successfully run

phpunit --skeleton-test ArrayUtils from the command line.

I'm using the latest 2.0.1 build 103.156 but I've also tried 2.0.0

Comment actions Permalink

Hi Kevin,

You are looking at the right place for that "Generate PHPUnit Test..." command.

For some reason PhpStorm thinks that it is not possible to generate PHPUnit Test for this file.
*) What is the contents of that ArrayUtils.php file? Does it has any classes inside? If so -- is that class name is unique across whole project (should not affect anything, just checking)?
*) Try creating brand new file and put some very basic class inside and see if it (menu item) will appear this time.
*) Please check if that menu item is actually in the context menu at all (File | Settings | Menus & Toolbars --> Project View Popup Menu --> Project View Popup Menu Run Group --> Run Configurations --> Run Context Group --> Generate PHPUnit Test)

Any way -- try these methods to invoke "Generate PHPUnit Test" action:

1. Search | Find Action (Ctrl+Shift+A). Now type "phpunit" -- that action should appear in the filtered list shortly. Just use it.

2. File | Settings | Keymap. Focus "quick filter" field (next to Filter & Bin icons) and type "phpunit". That action should be now highlighted. Select it and assign any shortcut which you can now use to invoke this action.

Comment actions Permalink

Hi Andriy,

Using your advice I was able to narrow down the cause of the problem.  It seems any class with a namespace does not have the Generate Test option.

The following results in the Generate Test option appearing as expected:

class Foo {}

The following does not show a Generate Test option

namespace Bar;
class Foo {}

Is this a bug or a configuration error on my part?  The test configuration I'm using uses the 'XML file' option.   The XML config just defines one test suite.

Thanks for your time.

Comment actions Permalink

Hi Kevin,

There is no configuration options in PhpStorm for PHPUnit Test generation. The "XML file" option you have mentioned is used when you run the actual PHPUnit tests.

In my opinion if PHPUnit itself (the command line) is able to generate proper unit test skeleton file, then such discovered behaviour is a bug and should be reported as such to the Issue Tracker:

Comment actions Permalink

Hello gentlemen,

Kevin, please submit a bugreport as Andriy have suggested.

Andriy, thanks as usual!


Comment actions Permalink

Thanks for your help guys.

Bug report: WI-5475


Please sign in to leave a comment.