Vectorface / dunit

Test code against multiple versions of PHP with the help of docker
MIT License
248 stars 12 forks source link

PHPUnit via composer not running in PHP 5.2 #12

Open rogeriopradoj opened 9 years ago

rogeriopradoj commented 9 years ago

Hello, first of all, thanks for this awesome project!

Unfortunately, I'm having a problem with a project:

root@fc2202c5aeef:/# php -d error_reporting=-1 /opt/source/vendor/bin/phpunit

Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /opt/source/vendor/phpunit/phpunit/composer/bin/phpunit on line 41

Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /opt/source/vendor/phpunit/phpunit/composer/bin/phpunit on line 42
You need to set up the project dependencies using the following commands:
curl -s http://getcomposer.org/installer | php
php composer.phar install

I trying to find a way to install phpunit in PHP 5.2, found some clues (I hope this can help):

Anyway, thanks again!

danbruce commented 9 years ago

Hello;

This is not really a dunit issue. In order to use PHPUnit with PHP 5.2 you need a very old (unsupported, outdated, hard to find) version of PHPUnit. I believe 3.6 is the last version you can use with PHP5.2. By default dunit will simply use the phpunit script located in your project's vendor folder.

That said, I thought it would be an interesting challenge to tackle (and may prove useful for future versions of dunit). Here's what I did to get a "working" version of PHPUnit within the PHP 5.2 docker image.

My composer.json:

...
"require": {
    "php": ">=5.2.0"
},
"require-dev": {
    "xrstf/composer-php52": "1.*",
    "phpunit/phpunit-php52": "dev-3.6.12-php52",
    "phpunit/phpunit-mock-objects-php52": "dev-1.1.0-php52",
    "vectorface/dunit": "~2.0"
},
"repositories": [
    {
        "type": "git",
        "url": "https://github.com/garex/phpunit"
    },
    {
        "type": "git",
        "url": "https://github.com/garex/phpunit-mock-objects"
    }
],
"scripts": {
    "post-install-cmd": [
        "xrstf\\Composer52\\Generator::onPostInstallCmd"
    ],
    "post-update-cmd": [
        "xrstf\\Composer52\\Generator::onPostInstallCmd"
    ],
    "post-autoload-dump": [
        "xrstf\\Composer52\\Generator::onPostInstallCmd"
    ]
}
...

then:

$> composer update
...
$> docker run -i -t -v `pwd`:/opt/source vectorface/php5.2
root@c18b8af431e8:/# cd /opt/source
root@c18b8af431e8:/opt/source# php -d error_reporting=-1 ./vendor/bin/phpunit-php52 ./PHP52Test.php 
PHPUnit @package_version@ by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 3.75Mb

OK (1 test, 1 assertion)

Note that I had to actually write a new test because none of my own are PHP 5.2 compatible, but that test does run. Please note that PHPUnit 5.2 is provided but not officially support for running modern unit test suites. Primarily the PHP 5.2 image is for running linting (php -l). Anyway, hope this was helpful for you. Best of luck.

rogeriopradoj commented 9 years ago

Hi, @danbruce, thanks so much for getting in touch.

I've been thinking to suggest you include a phpunit52.phar (I was working on it) or something like that inside your docker image, but you made clear that ...

Primarily the PHP 5.2 image is for running linting (php -l)

... so it would be pointless.

Again, thanks and congrats for releasing this awesome project!

danbruce commented 9 years ago

The reason I tagged this as an "enhancement" is due to exactly what you mentioned. I am now considering (in a future version) of packaging a version of PHPUnit within each docker image that is compatible with the PHP version. This is especially relevant as PHPUnit plans to drop support for all PHP < 5.6.

rogeriopradoj commented 9 years ago

Tweets: