Practices for database testing in Symfony2? How to isolate?

前端 未结 4 1882
别那么骄傲
别那么骄傲 2021-02-13 19:42

What are the current best practices for testing database interaction with Symfony2? I have a simple CRUD setup and i want to make sure my testing is OK. Right now, i have 4 test

4条回答
  •  青春惊慌失措
    2021-02-13 19:52

    testing on local machine is pain in the ... ,so i'm started to using ci system buddy.works (there is free stand-alone version) , and for this i neeeded to resolve this issue on my own.

    result is :

    • all tests works
    • tests are runing on production sql data
    • tests are running in separation (not in dev or production) - so i can do anything that i want with database
    • all pushes to git are tested and i have notification if something is broken
    • all pushes/pull request to deploy branch are automatic uploaded to production

    This is my solution :

    1. second parameters.yml in config with configuration for test
    2. on production i'm making daily sqldump
    3. on starting test on ci this sql backup is copied via scp to test machine
    4. to prepare all this i'm using robo.li ( my config is below)

    /**
    * This is project's console commands configuration for Robo task runner.
    *
    * @see http://robo.li/
    */
    class RoboFile extends \Robo\Tasks
    {
    
    function  loadDb(){
        $this->taskExecStack()
            ->stopOnFail()
            ->exec(" mysql -h mariadb -u root -pqwerty -e 'create database test' ")
            ->exec(" mysql -h mariadb -u root -pqwerty test < test.sql ")
            ->run();
    }
    
    
    function prepareDb(){
        $this->taskExecStack()
            ->stopOnFail()
            ->exec("cp  app/config/parameters-test.yml app/config/parameters.yml")
            ->run();
    
        $this->taskReplaceInFile('app/config/parameters.yml')
            ->from('database_host:     127.0.0.1')
            ->to("database_host:     'mariadb'")
            ->run();
    
        $this->taskReplaceInFile('app/config/parameters.yml')
            ->from('database_user:     dbuser')
            ->to("database_user:     'root'")
            ->run();
    
        $this->taskReplaceInFile('app/config/parameters.yml')
            ->from('database_password: 123')
            ->to("database_password: 'qwerty'")
            ->run();
    
    
    }
    

    }

    i hope it help you to create idea how to organize all this . Using stand alone ci is difficult to setup , but it's really good idea

提交回复
热议问题