10000 [PHPUnit-Bridge] symlink phpunit-bridge with relative paths? · Issue #37099 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PHPUnit-Bridge] symlink phpunit-bridge with relative paths? #37099

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

Closed
acasademont opened this issue Jun 4, 2020 · 10 comments
Closed

[PHPUnit-Bridge] symlink phpunit-bridge with relative paths? #37099

acasademont opened this issue Jun 4, 2020 · 10 comments

Comments

@acasademont
Copy link
Contributor

Description

We use Docker containers for our symfony app, and inside the Docker container the Symfony app lives on the "/app" directory and everything works fine. However, from time to time I'd like to execute some specific unit tests from my local machine, which has a very different absolute root directory, and phpunit fails with a file not found error, the main reason being PHPUnit Bridge symlinks with an absolute path to the main vendor folder that doesn't exist outside the Docker container.

    "repositories": {
        "phpunit-bridge": {
            "type": "path",
            "url": "/app/vendor/symfony/phpunit-bridge"
        }
    }

Would it be possible to symlink using relative paths? Or if not, would it be ok to tell composer to not symlink and mirror instead? Both solutions would work. Happy to send a PR. Not sure also if this could be considered a bug-fix or not.

Thanks!

@nicolas-grekas
Copy link
Member

The symlink is created by composer. I'm afraid there is nothing we can do here.
Did you try using the "symlink" option of composer, as explained in https://getcomposer.org/doc/05-repositories.md#path ?

Closing as explained.

@acasademont
Copy link
Contributor Author

I'm sorry @nicolas-grekas but this has nothing to do with my composer.json but the composer.json generated by the phpunit bridge here https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php#L214

Could you please reopen the issue?

@nicolas-grekas
Copy link
Member

Sure. But as I noted, this link is created by composer...

@nicolas-grekas nicolas-grekas reopened this Jun 8, 2020
@nicolas-grekas
Copy link
Member
nicolas-grekas commented Jun 8, 2020

An idea might be to replace this symlink by the one you want in your Dockerfile, after running simple-phpunit install.

@acasademont
Copy link
Contributor Author
acasademont commented Jun 8, 2020

On Windows we're already using the {"symlink": false} option over the symlink. Is there any reason we might not do the same on Linux?

@nicolas-grekas
Copy link
Member

Is there any reason we might not do the same on Linux?

yes: because it's convenient to have one single copy of the bridge when working on the bridge itself.

@acasademont
Copy link
Contributor Author

I agree it's convenient. Another solution might be to use a relative path instead of an absolute one on the symlink, I believe composer doesn't really care about absolute vs relative. I'll try to work on a PR for that.

@nicolas-grekas
Copy link
Member

@Seldaek just taught me about the COMPOSER_MIRROR_PATH_REPOS env var. That looks like the perfect solution, isn't it?

@acasademont
Copy link
Contributor Author

Ah! Yes that would fix it, I added the env variable and it works like a charm, thank you. In case anybody ends up here in the future, this how my bin/phpunit looks like with the changes

#!/usr/bin/env php
<?php

if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
    echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
    exit(1);
}

if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
    putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
}

//We use this Composer ENV variable so that repositories in the bridge are mirrored and not symlinked to avoid Docker issues
if (false === getenv('COMPOSER_MIRROR_PATH_REPOS')) {
    putenv('COMPOSER_MIRROR_PATH_REPOS=1');
}

require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';

Thanks @nicolas-grekas

@zimzat
Copy link
zimzat commented Jul 2, 2020

This appears to be caused by a logic change in Composer in 1.10.4 (released Apr 9) in composer/composer#8700

When the repository phpunit-bridge sets the path to is absolute, the symlink is now set as absolute.

Is it possible to make the url set in the composer.json be relative so it reverts to the original behaviour? Or is the recommendation for every project that works with multiple paths (e.g. locally and within a virtual machine) to specify the COMPOSER_MIRROR_PATH_REPOS, as recommended above, in their local bin/phpunit?

Toilal added a commit to Toilal/symfony that referenced this issue Apr 20, 2021
Toilal added a commit to Toilal/symfony that referenced this issue Apr 20, 2021
Toilal added a commit to Toilal/symfony that referenced this issue Apr 20, 2021
Toilal added a commit to Toilal/symfony that referenced this issue Apr 20, 2021
Toilal added a commit to Toilal/symfony that referenced this issue Apr 20, 2021
Toilal added a commit to Toilal/symfony that referenced this issue Apr 20, 2021
…t-bridge repository

# Conflicts:
#	CHANGELOG-5.3.md
Toilal added a commit to Toilal/symfony that referenced this issue Apr 20, 2021
Toilal added a commit to Toilal/symfony that referenced this issue Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0