0

I set up unit testing in Zend Studio last week, and it was working fine.. until suddenly after some refactoring, I got an error that the following file was not found in ZendPHPUnit.php:

/var/folders/Td/Tdnh++2KEdWAsk8Y0O4N0k+++TI/-Tmp-/zend.phpunit.UserMapperTest.php.2428213892936827201.php 

The file path is stored in $_SERVER['ZEND_PHPUNIT_TESTS_LOCATION'] in ZendPHPUnit.php

I checked the folder and I found zend.phpunit.UserrMapperTest.php.6031927106542896607.php (the number is different)

I was a little desperate so I made it work by forcing

$_SERVER['ZEND_PHPUNIT_TESTS_LOCATION'] = '/var/folders/Td/Tdnh++2KEdWAsk8Y0O4N0k+++TI/-Tmp-/zend.phpunit.UserMapperTest.php.6031927106542896607.php';

Eventually, after I worked with a few other test cases, the problem fixed itself. Now, I refactored some code again, and the problem is back. None of my testcases work.

Restarting the comp doesnt help, Project -> Clean doesnt help. I am on a mac running Snow Leopard.

Any insights on what is causing this?

Thanks!

crazyphoton
  • 623
  • 5
  • 20

1 Answers1

1

The problem is that PHPUnit doesn't work with the files themselves but with copies of the files that it creates on the fly and stores on directories that are also created on the fly. These files are modified to include PHPUnit logic. This goes for the test files themselves as well as for the php.ini (which forces you to load extensions in the main php.ini file for the tests, since additional .ini files are ignored). Every time you run the tests these files will be re-created with a new unique name (original name plus unique identifier).

The best way that I've found to work around this issue is to create launch configurations for the tests and save them as .launch files in your project (right click -> run as -> create new PHPUnit config -> select "shared file" in the common tab). Once you have the launch configs you can just run this by opening on the editor and clicking the Run button. You will see that after every time you run them there will be a line like the following on each launch file that has changed (easy to see if the configs are in version control):

<mapEntry key="ZEND_PHPUNIT_TESTS_LOCATION" value="/var/folders/my/ph9spb0s45z5_11l9tqw256r0000gn/T/DefaultWorkspace.phpunit.AssignmentRequestControllerDateCriteriaTest.php.4951739174960507380.php"/>

I usually just commit this change together with whatever other changes I've been working on at that time.

It's still kind of annoying that the file changes and thus the launch config, but at least in this way your tests will always run and you don't have to worry about having to re-run the manually, or clean the project, or anything like that.

ceiroa
  • 5,833
  • 2
  • 21
  • 18
  • So, I found "shared file" in the common tab (under Save As. the other option is "local"). What do I set shared file to? some dummy file on my comp that doesnt change everytime ? thanks for the detailed explanation! – crazyphoton Jul 30 '12 at 05:56
  • I would suggest creating a folder called "launchers" in your project and store the launch configurations there. This way they can be in version control with the rest of the project and can be used by everyone on the project. You can give the file any name but the extension should be ".launch". You have to create the actual .launch file (blank) before storing the launch config there (eclipse quirk). – ceiroa Jul 31 '12 at 14:09