Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPUnit via composer not running in PHP 5.2 #12

Open
rogeriopradoj opened this issue Jun 3, 2015 · 4 comments
Open

PHPUnit via composer not running in PHP 5.2 #12

rogeriopradoj opened this issue Jun 3, 2015 · 4 comments

Comments

@rogeriopradoj
Copy link

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
Copy link
Contributor

danbruce commented Jun 5, 2015

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
Copy link
Author

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
Copy link
Contributor

danbruce commented Jun 6, 2015

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 rogeriopradoj reopened this Jun 16, 2015
@rogeriopradoj
Copy link
Author

Tweets:

@s_bergmann hello, sorry for bother! Is available any phpunit3.6.phar around? The intention is provide it in https://t.co/3F4KxFOYtM php52

— Rogerio Prado J (@rogeriopradoj) June 9, 2015
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

@rogeriopradoj No because PHAR support was added in PHPUnit 3.7.

— Sebastian Bergmann (@s_bergmann) June 9, 2015
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

@rogeriopradoj You can use the zip files, can't you? https://t.co/PIdfwGLm1L

— Augusto Pascutti (@augustohp) June 9, 2015
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

@danbruce danbruce removed their assignment Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants