dmaicher / doctrine-test-bundle

Symfony bundle to isolate your app's doctrine database tests and improve the test performance
MIT License
1.08k stars 60 forks source link

Not clearing EntityManager #226

Closed VirginiaPhoenix closed 1 year ago

VirginiaPhoenix commented 1 year ago

Hello, I am using DAMA in the Symfony project. Rollbacks work well. But I encountered an error, when using dataProvider, entities are not detached. Because of this, I cannot reuse the same data in the same test - they are not saved. If you call $this->getEntityManager()->clear() then everything works. Do not prompt, in what there can be a problem?

my test:

/**
     * Проверка получения списка решенных задач
     * @see ModerationTaskDoctrineRepository::getResolvedByChunk()
     * @dataProvider dataGetResolvedByChunk
     */
    public function testGetResolvedByChunk(
        int $moderatorId,
        array $tasks,
        int $limit,
        int $offset,
    ): void {
        $this->saveModerationTasks($tasks); //if the same data comes, the database will be empty

        $history = array_filter(
            $tasks,
            fn(ModerationTask $task) => $task->isResolved() && $task->getModeratorId() === $moderatorId,
        );

        array_multisort(
            array_map(fn(ModerationTask $task) => $task->getNumberOfOffers(), $history),
            SORT_DESC,
            $history,
        );

        $searchedTasks = self::$repository->getResolvedByChunk(
            ['moderatorId' => $moderatorId],
            ['numberOfOffers' => 'DESC'],
            $limit,
            $offset,
        );

        $history = array_slice($history, $offset, $limit);

        $this->assertEquals($history, $searchedTasks);
    }

Thanks!

dmaicher commented 1 year ago

Does this test work without using my bundle? I cannot see how its related. My bundle only deals with the DBAL layer of Doctrine. It does literally nothing at all related to ORM and EntityManagers except caching meta data statically.

VirginiaPhoenix commented 1 year ago

thanks for the answer. I'll try to figure it out myself. I'll write if I can

dmaicher commented 1 year ago

Closing for now