PHP Unit test configuration for local single test

I have a suite of tests that run locally and all the tests run well. Now I would like to be able to run an individual test in that suite. I have aconfiguration for one of the tests:

individualUnit.jpg

I know that this indicates that the test should run on the server but that is part of the question. How do I get this test to run locally like the suite of tests? Even if I run on the server I get the error:

unitError.jpg

The error indicates that there is no valid mapping. How do I set up the mapping?

Thank you.

11 comments

Hi there,

Your post is confusing (for me, at least)

1) Why do you ask about PHPUnit on Server (which executes tests on remote server via web interface) if you are not intended to use it?

2) What problems you are having with running test for individual method with PHPUnit type of Run/Debug Configuration (which is for running tests locally in CLI mode) ?

How do I get this test to run locally like the suite of tests?

Create Run/Debug Configuration of PHPUnit type and configure accordingly.

The error indicates that there is no valid mapping. How do I set up the mapping?

Mappings should be taken from your Server (Deployment entry) -- have set them up there?


P.S.
http://blog.jetbrains.com/phpstorm/2013/04/recording-of-the-webinar-quality-assurance-for-php-projects-using-phpstorm-with-michelangelo-van-dam/ -- it covers unit testing with PHPUnit.

0

1) Why do you ask about PHPUnit on Server (which executes tests on remote server via web interface) if you are not intended to use it?

When I try to execute an individual test rather than the whole group PHPStorm seems to automatically setup a PHPUnit on Server. I would like to learn how to configure it but I only want to run one of the group of tests. If I select the individual method that I want to test and then right click and down on the 'Run' item of the context menu I have two options, 1) Run the configuration group and the other seems to be a preconfigured configuration for testing the individaul method. If I select this then I get the configuration PHPUnit on Server.

2) What problems you are having with running test for individual method with PHPUnit type of Run/Debug Configuration (which is for running tests locally in CLI mode) ?

Basically I don't know how to do it. Do I right click on the individual test, do I specify something when I click on the green arrow, is there a configuration setting . . . . ?

0
When I try to execute an individual test rather than the whole group PHPStorm seems to automatically setup a PHPUnit on Server. I would like to learn how to configure it but I only want to run one of the group of tests. If I select the individual method that I want to test and then right click and down on the 'Run' item of the context menu I have two options, 1) Run the configuration group and the other seems to be a preconfigured configuration for testing the individaul method. If I select this then I get the configuration PHPUnit on Server.

Please show a screenshot of such context menu and specify which one you are using.

As I see it from here you are selecting wrong 2nd option (which is PHPUnit on Server) while you need to select 1st one (which is just PHPUnit). And yes -- they seem to be named differently (1st one looks like "ClassName.MethodName" while 2nd looks like "MethodName on ServerName") -- this must be what's confusing you.

screen01.png

Basically I don't know how to do it. Do I right click on the individual test, do I specify something when I click on the green arrow, is there a configuration setting . . . . ?

When you use "Run" via context menu, IDE is either selects already existing configuration or creates temporal one for you.

You can always delete unwanted / create new / edit existing / convert temp into permanent via "Run | Edit Configurations" .. (or the same via drop-down box on main toolbar -- next to Run/Debug buttons). You can always create new configuration there of correct type manually (PHPUnit), select desired scope (Method) and specify what method to test.

When you click green "Run" or "Debug" button on main toolbar, the currently selected configuration (drop-down box on the left) is getting executed. Using context menu is more context aware and may offer method or whole class test run depending here you invoke context menu (cursor position -- try invoking it inside some method and between methods). You can use any of these -- depending on what you need right now and where in the file (and what current file is) you currently are: if via main toolbar then it will always execute configuration from drop-down box; if via context menu -- then it depends on context.

0

Here is the screen shot:

test.jpg
I don't get an option of on the server or local I only get the whole thing ('WebApiExterAccess...) or an individual test (testGetSiteProperties). When I select the later it seems to already be setup for 'on the server' and I don't know how to edit it so it will just run.

0

The text is just too long so it's gets truncated. But they are different -- look at icons:

  1. this one is for PHPUnit
  2. this one is for PHPUnit on Server

But the context is the same -- to test "testGetSiteProperies" methd of "WebApiExternalAccess..." class.

You need to choose first one.

"Run | Edit Configurations..." -- you can edit/delete/create different configs there. Those that have faded icon are temporal (will get deleted when limit is reached) -- they are created when you using Run or Debug via context menu (if no more appropriate configuration already exist).

0

OK Under Edit Configurations I created a testGetSiteProperties configuration under PHPUnit (not PHPUnit on Server) but when I select this test I still get the following error:

unitError.jpg
So something is still wrong. Here is the configuration for the individual test:

individualUnit.jpg

0

Well -- you need to show the configuration itself -- I cannot say from this screenshot what you have missed/did incorrectly.

0

I posted the individual configuration when editing my previous post.

0

The screenshot shows one for executing all tests in specific folder (and subfolders). Even this does not work? For specific method only you need to select "Method" instead of "Directory" for Test scope (2 more fields needs to be filled)

TBH I cannot say what could be wrong here -- it looks OK for me. The only difference is that I have custom working folder specified:
screen01.png

0

OK when I try to add a configuration for an individual method I get:

creatingNewUnit.jpg
Notice that the method and class text boxes are disabled.

0

For whatever reason IDE is unable to detect any PHPUnit tests in that file.

1) Do you have PHPUnit Framework files anywhere in your project (actual project or External Libraries) ? You need to add them if you have not got them (based on warnings from screenshot -- this must be the case). "Settings | PHP | Include path" -- if PEAR installation is used (otherwise (composer or PHAR) it should already be in your project).
2) What file icon that file has (please show)
3) How is that class is named and what class it extends.

0

Please sign in to leave a comment.