Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

PHPUnit via composer not running in PHP 5.2 #12

Description

@rogeriopradoj

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!

Activity

  1. self-assigned this
    on Jun 4, 2015
  2. danbruce commented on Jun 5, 2015

    @danbruce
    Contributor

    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.

  3. rogeriopradoj commented on Jun 6, 2015

    @rogeriopradoj
    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!

  4. danbruce commented on Jun 6, 2015

    @danbruce
    Contributor

    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.

  5. rogeriopradoj commented on Jun 16, 2015

    @rogeriopradoj
    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>
  6. removed their assignment
    on Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions