无法全局安装旧版本的 phpunit phar

2022-01-25 00:00:00 php phpunit phing

As given in https://phpunit.de/manual/current/en/installation.html#installation.phar.verification, the steps to globally install the PHAR are:

$ wget https://phar.phpunit.de/phpunit.phar
$ chmod +x phpunit.phar
$ sudo mv phpunit.phar /usr/local/bin/phpunit
$ phpunit --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.

I followed the above, but with the URL for the older version, i.e. https://phar.phpunit.de/phpunit-old.phar (because our PHP version is older). I ran the following commands then -

$ chmod +x phpunit-old.phar
$ sudo mv phpunit-old.phar /usr/local/bin/phpunit

Note - My PHP version is 5.3.29. and the Old Stable Release section in phpunit.de says PHPUnit 4.8 is supported on PHP 5.3, PHP 5.4, PHP 5.5, and PHP 5.6.

Looks fine till here. But, running phpunit --version gives -

PHP Fatal error:  require(): Cannot redeclare class phpunit_extensions_database_constraint_tableisequal in /usr/local/bin/phpunit on line 109
zend_mm_heap corrupted

So, instead of moving the .phar to /usr/local/bin/ (in the step 3), I was managing so far by running this -

$ php phpunit-old.phar –-version 

I was also able to run my unit test cases in this way -

php /home/sandeepan/phpunit-old.phar /var/cake_1.2.0.6311-beta/app/webroot/openx/lib/ad_agencies/unittests/Admarvel_generic_network_test.php

But, now I need to integrate phpunit with phing. I would like to use the basic utilities provided by PHPUnitTask of phing. So, I guess it needs phpunit phar to be globally installed.

I tried my luck by writing the following -

<phpunit haltonfailure="true" haltonerror="true" 
                                            pharlocation="/home/sandeepan/phpunit-old">
    <formatter type="plain" usefile="false" />
    <batchtest>
        <fileset dir="${dir.scratchpad}/${dir.subdir}/unittests">
            <include name="**/*_test.php"/>
        </fileset>
    </batchtest>
</phpunit>

But I get this error -

BUILD FAILED
...
: PHPUnitTask requires PHPUnit to be installed

Update

With reference to stackoverflow.com/a/23410676/351903, I tried with this older version of Phpunit, i.e. PHPUnit-3.7.35. Now, phpunit --version command works. But I still have no success using the PHPUnitTask of Phing. Still getting PHPUnitTask requires PHPUnit to be installed error.

Update 2

The solution which worked for me was using PHPUnit 3.7.35. It seems there is some compatibility issue of phing with PHPUnit 4.8.

解决方案

The solution which worked for me was using PHPUnit 3.7.35. It seems there is some compatibility issue of phing with PHPUnit 4.8.

Source - Phing can't see PHPUnit

相关文章