ZF-3302: Zend_Cache Unit Tests should utilize TMPDIR environment


Zend_Cache Unit Tests write to a directory in the ZF tests/ tree. Unfortunately, for systems that utilize packaging -- Fedora, Ubuntu -- this causes issues when running tests where the user running the tests is not root. It would be better to utilze the environment's TMPDIR for the tests.


This can be accomplished either via additions to TestHelper.php or via a config.ini directive.

It was the case but for some reasons, it has been changed to this.

So I change the bug statut to feature request.

I will try to introduce a sort of switch (is the ZF tests tree writable ? no => TMPDIR) or something like that ?

Attached is a patched CommonBackendTest.php file that would correct the issue.

Your patch use a ini config file ?

I don't have it ? And I don't see why ? $this->_root isn't enough ?

About $this->_root not being enough, consider the following example:

The FC RPM installs ZF under /usr/share. However, the permissions on /usr/share do not allow regular users to write there. Therefore, if a regular user wishes to run the unit tests, he will not be able to create a temp dir under $this->_root.

The config.ini file does not currently exist and should be added. The code looks there first and, if the directive is not found, searches for the ENV var TMPDIR and, if all else fails, attempts to create the tmpdir under $this->_root.

sure but what about something like :


public function getTmpDir()
    if (is_writeable($this->_root)) {
        return $this->_root . DIRECTORY_SEPARATOR . 'zend_cache_tmp_dir';
    } else {
        if (getenv('TMPDIR')){
            return getenv('TMPDIR').DIRECTORY_SEPARATOR . 'zend_cache_tmp_dir';
        } else {
            die("no writable tmpdir found"); 


This is similar to my patch only it takes the option of $this->_root . DIRECTORY_SEPARATOR . 'zend_cache_tmp_dir' as preferable and does not allow the option of setting it in an INI file, which might be much more convenient than setting an ENV var. I think the config.ini option is useful and should be supported.

Any reason why you object to adding config.ini? in the future, it might serve for other things as well..

I don't want a specific configuration file for Zend_Cache

But I will try something with TestConfiguration.php which is a global one

The idea is not for config.ini to be specific to Zend_Cache. I thought it could be a generic ZF config file which can be used for many other configurable options. TestConfiguration.php is a bit problematic cause it's more annoying to manipulate via scripting, like a package postinstall script. I think exporting TMPDIR can probably be sufficient if you really don't like the config.ini idea... But could you concat a timestamp for the zend_cache_tmp_dir? Like: return getenv('TMPDIR').DIRECTORY_SEPARATOR . 'zend_cache_tmp_dir_'.date("mdyHi");

This is because it might happen that 2 users are trying to execute the unit test at the same time.. this is a multiuser ENV after all :)

Sorry, probably should be:

return getenv('TMPDIR').DIRECTORY_SEPARATOR . 'zend_cache_tmp_dir_'.date("mdyHis");

ok, it seems a good idea

Great. Could you notify me once the patch is applied? I'd like to build a ZF RPM and verify this to be OK..

You may find a related discussion over here:

Maybe you'll also have feedback on the ZF sub packages layout Alexander has devised.

fixed in SVN trunk, please reopen in there is still a problem


Hi Fabian,

Thanks. I've given instruction for the Alexander Dahl who is responsible for packging ZF as RPM in Fedora. I'll keep you posted. What about config.ini? Is there a reason why you object to idea?

Updating for the 1.6.0 release.