liip / LiipFunctionalTestBundle

Some helper classes for writing functional tests in Symfony
http://liip.ch
MIT License
641 stars 182 forks source link

Support Symfony 6 #603

Closed alexislefebvre closed 2 years ago

alexislefebvre commented 2 years ago

Based on #598

loginUser() is called when it's available, it was added in Symfony 5.1: https://symfony.com/doc/5.4/testing.html#logging-in-users-authentication

Without it, tests were broken. But with it, it may break some tests suites.

alexislefebvre commented 2 years ago

Please try the alpha release: https://github.com/liip/LiipFunctionalTestBundle/releases/tag/4.6.0-alpha1

kl3sk commented 1 year ago

With a simple test this error show:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "Liip\TestFixturesBundle\Services\DatabaseToolCollection".

Used like this in class UserTest extends KernelTestCase :

    public function setUp(): void
    {
        parent::setUp();

        $this->databaseTool  = static::getContainer()->get(DatabaseToolCollection::class)->get();
        $this->entityManager = static::getContainer()->get(EntityManagerInterface::class);

        $this->users = $this->entityManager->getRepository(User::class)->findAll();
    }

As current doc said: in config/package/test/framework.yaml

framework:
    test: true
    session:
        storage_id: session.storage.mock_file
        name: MOCKSESSION

liip_functional_test: ~
alexislefebvre commented 1 year ago

@kl3sk Thanks, I'll add it to the doc of the other bundle: https://github.com/liip/LiipTestFixturesBundle/pull/206

kl3sk commented 1 year ago

Ok thanks,

Just to be clear. This doen't work for me.

Edit: As default, it is enabled as this in SF6 in: config/package/framework.yaml

when@test:
    framework:
        test: true
        session:
            storage_factory_id: session.storage.factory.mock_file
alexislefebvre commented 1 year ago

Thanks, I'll add this too for Symfony 6.


Edit: @kl3sk if this was enabled by default, why did you have this error?

kl3sk commented 1 year ago

This is a good question @alexislefebvre 🤣

I have a default installation and don't understand why this happen. A though because the compatibility is alpha at least.

kl3sk commented 1 year ago

After some reseach it appears that the cache was the problem. A clear:cache was not enough (many tries before). I have to remove the folder manually .

But now I face of an other error:

Testing
E                                                                   1 / 1 (100%)There is no active transaction

And this fix won't work for me.

Erratum: After removing the cache manually (again). It seems to work with:

liip_test_fixtures:
    keep_database_and_schema: true
   ...