Coder Social home page Coder Social logo

Comments (7)

alexislefebvre avatar alexislefebvre commented on June 16, 2024

@Dekrikh do the database schema has lots of entites with many columns?

You can try to keep the schema: #12 (comment)

from liiptestfixturesbundle.

Dekrikh avatar Dekrikh commented on June 16, 2024

@alexislefebvre
Yes, the reason is that generating the table takes a significant amount of time.

I measured the command's execution time using the following:

Measure-Command { php bin/console --env=test doctrine:schema:update --force }
The result was:

TotalMilliseconds: 6489.8295


Now, I have good performance with #12 (comment), thank you.

However, I encountered another issue. In my test, I send a request with the method api of the paht ID of one. The problem is that the test doesn't start with ID 1; it uses the previous ID plus one (AUTO_INCREMENT)."

I thought of using the Event https://github.com/liip/LiipTestFixturesBundle/blob/2.x/doc/events.md to reset an AUTO_INCREMENT. Any thoughts to share with me?

from liiptestfixturesbundle.

alexislefebvre avatar alexislefebvre commented on June 16, 2024

@Dekrikh Try to set the id to 1 in the fixtures of the entity, it should ignore the auto increment. Or try with the event.

from liiptestfixturesbundle.

Dekrikh avatar Dekrikh commented on June 16, 2024

I chose simplicity a "DELETE FROM table_name" looping over all tables with a reset of AUTO_INCREMENT = 1; at each start of the test

if someone has the same need, this code using doctrine in symfony :

public function clearAllTablesInDatabaseAndResetAutoIncrement(){
        $em = $this->getContainer()->get('doctrine.orm.entity_manager');

        $em->getConnection()->exec('SET FOREIGN_KEY_CHECKS = 0');
        // clear all the tables
        foreach ($em->getMetadataFactory()->getAllMetadata() as $metadata) {
            $queryBuilder = $em->createQueryBuilder();
            $queryBuilder->delete($metadata->getName());
            $queryBuilder->getQuery()->execute();
        }

        foreach ($em->getMetadataFactory()->getAllMetadata() as $metadata) {
            $em->getConnection()->exec('ALTER TABLE ' . $metadata->getTableName() . ' AUTO_INCREMENT = 1;');
        }

        $em->getConnection()->exec('SET FOREIGN_KEY_CHECKS = 1');
    }

from liiptestfixturesbundle.

alexislefebvre avatar alexislefebvre commented on June 16, 2024

@Dekrikh thanks for sharing the code. Is it faster if you keep the tables but remove the data with TRUNCATE and reset the AUTO_INCREMENT?

from liiptestfixturesbundle.

Dekrikh avatar Dekrikh commented on June 16, 2024

@alexislefebvre yes, that's a better idea.

from liiptestfixturesbundle.

alexislefebvre avatar alexislefebvre commented on June 16, 2024

Actually, is your code already doing this? I'm not sure if the call to delete remove only the rows or the table entirely.

from liiptestfixturesbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.