Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[PhpUnitBridge] Cannot declare class DeepCopy\DeepCopy, because the name is already in use #44426

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
ivoba opened this issue Dec 2, 2021 · 9 comments

Comments

@ivoba
Copy link
Contributor

ivoba commented Dec 2, 2021

Symfony version(s) affected

5.4.0

Description

When running Functional tests in a symfony project that has DeepCopy as service and dependency this error occurs:

 Symfony\Component\ErrorHandler\Error\FatalError:
Compile Error: Cannot declare class DeepCopy\DeepCopy, because the name is already in use

  at vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php:25

I suppose it is because Phpunit also requires DeepCopy and the PhpUnitBridge somehow mixes dependencies?

The tests outputs the symfony error page.

How to reproduce

Have a project that uses DeepCopy and run a functional test that also uses DeepCopy service f.e in Controller.

Occurs here on PHP7.4 and <server name="SYMFONY_PHPUNIT_VERSION" value="9.5"/>

Possible Solution

No response

Additional Context

Fatal error: Cannot declare class DeepCopy\DeepCopy, because the name is already in use in /opt/atlassian/pipelines/agent/build/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php on line 25
<!-- Compile Error: Cannot declare class DeepCopy\DeepCopy, because the name is already in use (500 Internal Server Error) -->
<!DOCTYPE html>
<html lang="en">
 <head>
     <meta charset="UTF-8" />
     <meta name="robots" content="noindex,nofollow" />
     <meta name="viewport" content="width=device-width,initial-scale=1" />
     <title>Compile Error: Cannot declare class DeepCopy\DeepCopy, because the name is already in use (500 Internal Server Error)</title>
     <link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAgCAYAAAABtRhCAAADVUlEQVRIx82XX0jTURTHLYPyqZdefQx66CEo80+aYpoIkqzUikz6Z5klQoWUWYRIJYEUGpQ+lIr9U5dOTLdCtkmWZis3rbnC5fw/neYW002307mX/cZvP3/7o1PwwOdh95x7vnf39zvnd29AgBer2xO6DclAXiMqZAqxIiNIN/IYSUS2BPhjmGATchUxI+ADWiRhpWK7HKuHFVBFdmU5YvnI4grFGCaReF/EBH4KsZlGgj2JBTuCYBWRIYF8YoEOJ6wBt/gEs7mBbyOjQXruPLSdOgPCiEiPSUUHDoL8Ug5IUo9B/d5wrt+G7OAKNrODPuVdB6vRCIzN6SdBlpW9RIgk/1FeAXabzRlrUPVCS/JhbmwudztnGeeH9AyXBIwtmM3wLinZJZHifjHw2V+NBoRh+9ixQrbgbnaSIcl7cGea6hoXQbNe7za241oeO5Z0p42M4BV2EqP2D50wo+6HzvwC6C4sApNOR8cmOrtcnhtj2kYRyC9eBvXzKrBZrXSs72kFd1t3MoKVbMekQkEnSNKOO8fac3LpmK6l1TlGtsxmsdKFsecPYgwxst0cwROMYDXboSotg0WLBRqjY51jLYcENElXwW2XJKPydvoI2GN9T8rBtrAArYIUruBJXkFheCQYlCpQP6uk5dAQFQNaUROMSGVQFxLmkoQsxDJrhLbTZ+nvVsERME9MgPJRKV/58AsyomTSzE813WLFvWK++qI0xSfQl8k8Pg46sYRuv5t6dS+4RqxDwaa4BGjYH+NTQvKScIp9+YL/hoZh3jDtLRHtt2C3g6bmhX+CpsFBWg7ilDSPgj0lD2ncr5ev/BP8VvyAJhqVyZeUhPOrEhEFxgEtjft846Z/guQTNT89Q5P9flMLoth4F7808wKtWWKzAwNQHxrh/1vaid2F+XpYTSbQf1XA2McOmOpROnvpvMEA4tSjq1cW0sws2gCYxswY6TKkvzYnJq1NHZLnRU4BX+4U0uburvusu8Kv8iHY7qefkM4IFngJHEOUXmLEPgiGsI8YnlZILit3vSSLRTQe/MPIZva5pshNIEmyFQlCvruJKXPkCEfmePzkphXHdzZNQdoRI9KPlBAxlj/I8U97ERPS5bjGbWDFbEdqHVe5caTBeZZx2H/IMvzeN15yoQAAAABJRU5ErkJggg==">
     <style>/* This file is based on WebProfilerBundle/Resources/views/Profiler/profiler.css.twig.
If you make any change in this file, verify the same change is needed in the other file. */
:root {
...
@fancyweb
Copy link
Contributor

fancyweb commented Dec 2, 2021

Hello, can you create a small example application that allows to reproduce your issue please?

@ivoba
Copy link
Contributor Author

ivoba commented Dec 3, 2021

@xabbuh
Copy link
Member

xabbuh commented Dec 3, 2021

@ivoba I cannot reproduce this:

[12:16]-[www-data@app]-[/app]-[git main] 
$ vendor/bin/simple-phpunit
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.

Testing 
..                                                                  2 / 2 (100%)

Time: 00:07.134, Memory: 38.00 MB

OK (2 tests, 2 assertions)

Remaining indirect deprecation notices (1)

  1x: The "Symfony\Bridge\Doctrine\Logger\DbalLogger" class implements "Doctrine\DBAL\Logging\SQLLogger" that is deprecated Use {@link \Doctrine\DBAL\Logging\Middleware} or implement {@link \Doctrine\DBAL\Driver\Middleware} instead.
    1x in FunctionalTest::testTest from App\Tests\Functional

@fancyweb
Copy link
Contributor

fancyweb commented Dec 3, 2021

I cannot reproduce the error on my side, even in your Docker container. Also in this issue you say the error occurs on PHP 7.4, but the Docker container runs PHP 8.0.

@ivoba
Copy link
Contributor Author

ivoba commented Dec 3, 2021

It happens on both 7.4 and 8.0.
I have it happen even in bitbucket pipelines, not just in this Docker container.

<!-- Compile Error: Cannot declare class DeepCopy\DeepCopy, because the name is already in use (500 Internal Server Error) -->

I cleared the test cache hard : rm -rf var/cache/test and then tests pass.

Then i run bin/console cache:clear --env=test and then the error occurs again.
Maybe this helps. Thanks.

@fancyweb
Copy link
Contributor

fancyweb commented Dec 3, 2021

Thanks for the further steps to reproduce, I have the error too now.

@fancyweb
Copy link
Contributor

fancyweb commented Dec 3, 2021

The functional test uses the dumped PHP container. During the controller instantiation, the DeepCopy class file is included:
include_once \dirname(__DIR__, 4).'/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php';

But it already exists and it was included with a different path (./vendor/bin/.phpunit/phpunit-9.5-0/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php) so it fails. I guess it could theoretically happen with any class loaded by the PhpUnitBridge and PHPUnit.

Using PHPUnit directly obvisouly works since the class file path is the same.

@ivoba
Copy link
Contributor Author

ivoba commented Dec 8, 2021

@fancyweb Is there any workaround possible?
Or can you point me to where a possible fix can be applied, so i can give it a try.

@nicolas-grekas
Copy link
Member

You can set the container.dumper.inline_class_loader parameter to false in the test env:

when@test:
    parameters:
        container.dumper.inline_class_loader: false

I'm closing here because we won't be able to do anything in the short term.
Thanks for the details. We need to do something about it at some point.

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

4 participants