8000 Call to undefined method Symfony\Component\VarDumper\Caster\CutStub::clear() · Issue #23110 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Call to undefined method Symfony\Component\VarDumper\Caster\CutStub::clear() #23110

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
ianfp opened this issue Jun 8, 2017 · 36 comments
Closed

Comments

@ianfp
Copy link
ianfp commented Jun 8, 2017
Q A
Bug report? yes
Feature request? no
BC Break report? yes
RFC? no
Symfony version 3.3.2

I just upgraded from 3.2.x to 3.3.2, ran my test suite, and got this:

PHPUnit 6.2.1 by Sebastian Bergmann and contributors.

......................E

Time: 17.47 seconds, Memory: 153.28MB

There was 1 error:

1) Tests\My\Project\MyTestCase::myTest
Error: Call to undefined method Symfony\Component\VarDumper\Caster\CutStub::clear()

my-project/var/cache/test/appTestDebugProjectContainer.php:8865
my-project/vendor/doctrine/doctrine-bundle/DoctrineBundle.php:123
my-project/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:155
my-project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php:193
my-project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php:205
my-project/tests/My/Project/ApiTestCase.php:112

Inspecting the CutStub class reveals that, indeed, it does not have a clear() method.

@stof
Copy link
Member
stof commented Jun 12, 2017

Can you show the code of var/cache/test/appTestDebugProjectContainer.php:8865 (actually, please include the code of the whole method surrounding line 8865 to have some context, not only this exact line), to have some idea about what causes the issue ?

@ianfp
Copy link
Author
ianfp commented Jun 12, 2017

Here it is. Look for the comment "THIS IS THE LINE" below.

class DoctrineORMEntityManager_000000007d2f5e2600000000351eda849a0f2049471f845f24e014f05d86efb5 extends \Doctrine\ORM\EntityManager implements \ProxyManager\Proxy\VirtualProxyInterface
{

    /**
     * @var \Closure|null initializer responsible for generating the wrapped object
     */
    private $valueHolder593ebc671f523423023872 = null;

    /**
     * @var \Closure|null initializer responsible for generating the wrapped object
     */
    private $initializer593ebc671f541807848188 = null;

    /**
     * @var bool[] map of public properties of the parent class
     */
    private static $publicProperties593ebc671f4bb291732226 = array(
        
    );

    // methods omitted...

    /**
     * {@inheritDoc}
     */
    public function clear($entityName = null)
    {
        $this->initializer593ebc671f541807848188 && $this->initializer593ebc671f541807848188->__invoke($this->valueHolder593ebc671f523423023872, $this, 'clear', array('entityName' => $entityName), $this->initializer593ebc671f541807848188);

        return $this->valueHolder593ebc671f523423023872->clear($entityName); // THIS IS THE LINE
    }

    /**
     * {@inheritDoc}
     */
    public function close()
    {
        $this->initializer593ebc671f541807848188 && $this->initializer593ebc671f541807848188->__invoke($this->valueHolder593ebc671f523423023872, $this, 'close', array(), $this->initializer593ebc671f541807848188);

        return $this->valueHolder593ebc671f523423023872->close();
    }

@MasterB
Copy link
Contributor
MasterB commented Jun 13, 2017

I've the same issue after upgrade from 3.2.x to 3.3.2.

Some infos about the issue I've found until now:

Problem appear, if the test calls a page which has a form included and the from itself has a form field with EntityType::class type. The error is thrown during $form->createView().

@nicolas-grekas
Copy link
Member

Could any of you please provide us a small reproducer we could run locally?

@MasterB
Copy link
Contributor
MasterB commented Jun 14, 2017

So far I have no succuess to reproduce this error on a clean installation. I'll try further (I could not make original code public)

@ianfp
Copy link
Author
ianfp commented Jun 14, 2017

Likewise, my application is large and proprietary. I'll try to find some time to dig deeper so I can provide more helpful information.

@stof
Copy link
Member
stof commented Jun 14, 2017

WTF. How are we ending up with a CutStub in a property of the proxy class.
@nicolas-grekas could it be that the class property is accessed by reference when building the dumping info, and then the dumping info is modified to add a CutStub ? I don't see another way here (but I may miss something due to the magic happening in ProxyManager)

@stof
Copy link
Member
stof commented Jun 14, 2017

@ianfp do you have any call to the VarDumper in your own code executed during this test ? And is the profiler enabled in your test environment (it also uses the VarDumper) ?

@nicolas-grekas
Copy link
Member

VarDumper vs ProxyManager, that's going to be a fun issue /cc @Ocramius ;)
A reproducer would definitely help.

@ianfp
Copy link
Author
ianfp commented Jun 14, 2017

@stof Yes! The profiler was enabled, and disabling it solves the problem!

@MasterB
Copy link
Contributor
MasterB commented Jun 16, 2017

I have the profiler not enabled on the functional test, problem still exists.

I've created a simple db update formular, to reproduce the error similar to my app which has the problem, without success. Everything works. Strange.... So, I give up try to reproduce the error on a clean installation.

@ianfp
Copy link
Author
ianfp commented Jun 21, 2017

Would a heavily-redacted copy of my var/cache/test/appTestDebugProjectContainer.php file be of any use?

@nisanov
8000
Copy link
nisanov commented Jul 3, 2017

I can also confirm that the profiler has something to do with this issue since I've a functional test with $this->client->enableProfiler(); and then $mailCollector = $this->client->getProfile()->getCollector('swiftmailer'); related functionality, just the call to $this->client->enableProfiler(); causes this issue to occur, I'm on 3.3.2 too.

$salesperson = $this->manager->getRepository(...)->findOneBy(['...' => '...']);

$crawler = $this->client->request('GET', '...');

$form = $crawler->selectButton('Sign In')->form();

$form['visitor_registry_sign_in[name]'] = $visitor = sprintf('Leeroy Jenkins %s', rand(10000, 99999));
$form['visitor_registry_sign_in[job_title]'] = 'Manager';
$form['visitor_registry_sign_in[company]'] = 'Acme';
$form['visitor_registry_sign_in[email]'] = 'john@mail.com';
$form['visitor_registry_sign_in[phone]'] = '0432123132';
$form['visitor_registry_sign_in[salesperson]'] = $salesperson->getId();
$form['visitor_registry_sign_in[purpose]'] = 'Personal';

$this->client->enableProfiler(); // line that causes the error (I've not investigated further)
$this->client->submit($form);
...

@nicolas-grekas
Copy link
Member

Should be fixed by #23465

nicolas-grekas added a commit that referenced this issue Jul 11, 2017
…f (nicolas-grekas)

This PR was merged into the 3.3 branch.

Discussion
----------

[HttpKernel][VarDumper] Truncate profiler data & optim perf

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23415, #21547 and hopefully #23110 and #23175
| License       | MIT
| Doc PR        | -

Commits
-------

754d3a7 [HttpKernel][VarDumper] Truncate profiler data & optim perf
@ianfp
Copy link
Author
ianfp commented Jul 20, 2017

@nicolas-grekas I'm sorry to report that I'm still seeing this on Symfony 3.3.5.

@MasterB
Copy link
Contributor
MasterB commented Jul 21, 2017

@nicolas-grekas my problems are solved

@nicolas-grekas
Copy link
Member
nicolas-grekas commented Jul 21, 2017 via email

@ianfp
Copy link
Author
ianfp commented Jul 21, 2017

Providing a reproducer does not seem to be feasible at the moment. But here's what I've discovered:

The entity manager proxy in appTestDebugProjectContainer.php wraps an actual EntityManager until ProfilerListener#onKernelTerminate() is called. The problem specifically occurs when FileProfilerStorage serializes the collectors. One of those collectors that gets serialized is the DoctrineDataCollector, which holds a reference to the container and hence the entity manager.

Before serialize() is called, the entity manager proxy holds 8000 an actual EntityManager. Afterwards, it holds an instance of CutStub.

When my test finishes, it calls tearDown(), which calls ensureKernelShutdown(), which shuts down each bundle. When DoctrineBundle shuts down, it calls EntityManager#clear(). But by this point, the actual EntityManager in the proxy has been replaced by a CutStub.

I hope that's of some help.

@nicolas-grekas
Copy link
Member

Strange. Which exact PHP version do you have?

@ianfp
Copy link
Author
ianfp commented Jul 21, 2017
PHP 7.0.18-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.18-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

on Ubuntu 16.04.2 LTS

@nicolas-grekas
Copy link
Member

Can you check if the issue happens if you disable xdebug?

@ianfp
Copy link
Author
ianfp commented Jul 21, 2017

Yes, the error occurs even if xdebug is disabled.

@nicolas-grekas
Copy link
Member

Reproducer?

@nicolas-grekas nicolas-grekas self-assigned this Jul 31, 2017
@nisanov
Copy link
nisanov commented Aug 1, 2017

My example is resolved by 3.3.5

@ossinkine
Copy link
Contributor

I have the same issue as @ianfp. I'll try to provide a reproducer shortly.

@ossinkine
Copy link
Contributor

This is the minimum version to reproduce that I was able to achieve: https://github.com/ossinkine/symfony-standard/tree/issue-23110
This is Symfony Standard edition with installed Sonata admin and Vich uploader bundles and Doctrine migrations package.
I ran test in a container based on php:alpine with installed opache (docker-php-ext-install opcache).
If disable one of Vich uploader, Migrations or Opcache, all work.

@JeromeGill
Copy link

I'm having this issue in Travis but have been unable to reproduce locally.

@Simperfit
Copy link
Contributor

Thanks @ossinkine for the reproducer.

@fabpot fabpot closed this as completed Nov 10, 2017
fabpot added a commit that referenced this issue Nov 10, 2017
…der property (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Bridge/ProxyManager] Remove direct reference to value holder property

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23110
| License       | MIT
| Doc PR        | -

This fixes Ocramius/ProxyManager#394 on Symfony's side, because proxy-manager v1 is not maintained anymore, but is the only one that works on PHP 5.3/5.5, which we still support.
Cannot be tested easily (but code is run by the existing test suite.)

Commits
-------

af9d644 [Bridge/ProxyManager] Remove direct reference to value holder property
@Ocramius
Copy link
Contributor

Hey folks, I still lack a test case that reproduces the issue for:

If somebody can make an example that doesn't involve this hacky/invalid test case, please do let me know. Without a valid test case this won't be merged upstream.

@nicolas-grekas
Copy link
Member

on the hackday's list for me :)

@Invis1ble
Copy link

I have the same issue: symfony 3.3.6, functional tests, profiler enabled. Got errors:

  1. Tests\AppBundle\Controller\SomeControllerTest::testCreateValidationFailed with data set #0 ('superadmin')
    Error: Call to undefined method Symfony\Component\VarDumper\Caster\CutStub::getRepository()

/var/www/vhosts/warehouse/www/var/cache/test/appTestDebugProjectContainer.php:8980
/var/www/vhosts/warehouse/www/vendor/doctrine/common/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php:242
/var/www/vhosts/warehouse/www/tests/AppBundle/Controller/ControllerTestCase.php:190
/var/www/vhosts/warehouse/www/tests/AppBundle/Controller/ControllerTestCase.php:51
/var/www/vhosts/warehouse/www/tests/AppBundle/Controller/ControllerTestCase.php:148
/var/www/vhosts/warehouse/www/tests/AppBundle/Controller/ControllerTestCase.php:131
/var/www/vhosts/warehouse/www/tests/AppBundle/Controller/ControllerTestCase.php:78
/var/www/vhosts/warehouse/www/tests/AppBundle/Controller/SomeControllerTest.php:186

  1. Tests\AppBundle\Controller\SomeControllerTest::testCreateValidationFailed with data set #0 ('superadmin')
    Error: Call to undefined method Symfony\Component\VarDumper\Caster\CutStub::clear()

/var/www/vhosts/warehouse/www/var/cache/test/appTestDebugProjectContainer.php:8890
/var/www/vhosts/warehouse/www/vendor/doctrine/doctrine-bundle/DoctrineBundle.php:124
/var/www/vhosts/warehouse/www/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:155
/var/www/vhosts/warehouse/www/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php:193
/var/www/vhosts/warehouse/www/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php:205

@nicolas-grekas
Copy link F438
Member
nicolas-grekas commented Nov 24, 2017

@Invis1ble of course: it has been fixed in v3.3.11.

@Invis1ble
Copy link

@nicolas-grekas Thanks. I thought I had the latest version.

@nicodemuz
Copy link
Contributor
nicodemuz commented Jan 25, 2023

I'm facing the same issue on my CI machine when upgrading from Symfony 5.4 to Symfony 6.2.

My test also uses $client->enableProfiler();. My application code also uses EntityType::class.

1) App\Tests\Controller\WorkshopShowControllerTest::testUpcomingWorkshopRegistrationForUnregisteredWorkshopUser

Error: Call to undefined method Symfony\Component\VarDumper\Caster\CutStub::clear()



/var/lib/jenkins/workspace/PR-3803/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:624

/var/lib/jenkins/workspace/PR-3803/symfony/vendor/doctrine/doctrine-bundle/Registry.php:80

/var/lib/jenkins/workspace/PR-3803/symfony/vendor/doctrine/doctrine-bundle/Registry.php:65

/var/lib/jenkins/workspace/PR-3803/symfony/vendor/symfony/http-kernel/DependencyInjection/ServicesResetter.php:47

/var/lib/jenkins/workspace/PR-3803/symfony/vendor/symfony/http-kernel/Kernel.php:110

/var/lib/jenkins/workspace/PR-3803/symfony/vendor/bref/symfony-bridge/src/BrefKernel.php:62

/var/lib/jenkins/workspace/PR-3803/symfony/vendor/symfony/framework-bundle/KernelBrowser.php:154

/var/lib/jenkins/workspace/PR-3803/symfony/vendor/symfony/browser-kit/AbstractBrowser.php:370

/var/lib/jenkins/workspace/PR-3803/symfony/vendor/symfony/browser-kit/AbstractBrowser.php:568

/var/lib/jenkins/workspace/PR-3803/symfony/tests/Controller/WorkshopShowControllerTest.php:292

Here is the relevant code from my test case:

$client = $this->createWebClientByUsername('test');

// Enable profiler so we get sent email
$client->enableProfiler();

$client->request('POST', '/workshop/1', array(
    'workshop_signup' => array(
        'firstName' => 'Testing',
        'lastName' => 'User',
        'email' => 'test@testing.com',
        'phone' => '12345678',
        'userType' => WorkshopSignup::USER_TYPE_TEACHER,
        'school' => null,
        'georegion' => '7',
    ),
));

$this->assertResponseRedirects();

// Ensure one workshop registration email is sent
$mailCollector = $this->getMailCollector($client);
$this->assertEquals(1, sizeof($mailCollector->getEvents()->getEvents()));

// Ensure workshop Zoom URL is in the email message
/** @var Email $email */
$email = $mailCollector->getEvents()->getEvents()[0]->getMessage();
/** @var TextPart $textPart */
$textPart = $email->getBody();
$emailBody = $textPart->getBody();
$this->assertStringContainsString('https://us02web.zoom.us/j/1234567890?pwd=abcdefg', $emailBody);

$client->followRedirect(); // Line WorkshopShowControllerTest.php:292 in above stack trace

@nicolas-grekas any idea?

@robertfausk
Copy link
robertfausk commented Jan 27, 2023

@nicodemuz I got the same issue like you after upgrading symfony 6.1 to 6.2 (on PHP 8.1).
Got it solved by upgrading to PHP 8.2 ... so I didn't investigate further.

@stof
Copy link
Member
stof commented Jan 27, 2023

This issue from 2 days ago is probably similar to #49091, which is caused by a PHP bug in PHP 8.1.0 to 8.1.7 (fixed in 8.1.8).

Anyway, it is much better to create a new issue than commenting on a ticket closed 6 years ago (because your issue is likely not the same even if the error message is similar)

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

0