lchrusciel / ApiTestCase

Handy PHPUnit test case for testing JSON APIs in your Symfony applications.
MIT License
410 stars 35 forks source link

Symfony 4.1 update - Error #123

Closed vitalyiegorov closed 6 years ago

vitalyiegorov commented 6 years ago

@lchrusciel Today after updating to the latest Symfony 4.1 I start getting this error in my tests:

Error : Call to undefined method Symfony\Bundle\FrameworkBundle\Test\TestContainer::getMockedServices()
 /vendor/lakion/api-test-case/src/ApiTestCase.php:117

Problem related to getting MockedContainer Services for unmocking:

public function tearDown()
    {
        if (null !== $this->client && null !== $this->client->getContainer()) {
            foreach ($this->client->getContainer()->getMockedServices() as $id => $service) {
                $this->client->getContainer()->unmock($id);
            }
        }

        \Mockery::close();
        $this->client = null;
        $this->entityManager = null;
        $this->fixtureLoader = null;

        parent::tearDown();
    }

As symfony update states they have simplified testing container =) So this code should be removed/changed and docs updated.

As temporary solution/workaround until fix would be released create your own TestCase wrapper and override tearDown() like this:

use Lakion\ApiTestCase\JsonApiTestCase;

/**
 * TestCase wrapper.
 */
class TestCase extends JsonApiTestCase
{
    public function tearDown()
    {
        \Mockery::close();
        $this->client = null;

        static::ensureKernelShutdown();
    }
}
pamil commented 6 years ago

Same happening for Sylius, I think it's a bug introduced by Symfony.

bendavies commented 6 years ago

@pamil are you going to work on this?

loic425 commented 6 years ago

@pamil @lchrusciel Is it work now ? cause sylius 1.2.0 is released with symfony 4.1 support.

lchrusciel commented 6 years ago

3.1.0 is working with Symfony 4.1, but with few workarounds. Please, check how Sylius is handling it: https://github.com/Sylius/Sylius/commit/25f969e50e53c266572abb3694bc52b17e3a796a.

We need to wait for Symfony 4.1, to get this fix: https://github.com/symfony/symfony/issues/27494