Welcome Guest, Not a member yet? Register   Sign In
Testing, specifically when having database dependant code
#3

(08-14-2019, 12:24 PM)albertleao Wrote: Couldn't you mock out your db calls?

I guess so, but wouldn't that defeat the purpose of testing, specially on Controller level?

My current approach is to use the seed function to copy the few tables I need to do testing on from the database backup (virtu12_vtester)  to the testing database (ci4test). Both databases live on the same MySQL server and ci4test user has read access to the database backup:
PHP Code:
class CITestSeeder extends Seeder
{
    public function 
run()
    {
        
$tables = [ 'country''territories' ];
        foreach (
$tables as $t)
        {
            if ( ! 
$this->db->tableExists('db_' $t))
            {
                
$this->db->query("CREATE TABLE IF NOT EXISTS ci4test.db_$t SELECT * FROM virtu12_vtester.$t");
            }
        }
    }

Reply


Messages In This Thread
RE: Testing, specifically when having database dependant code - by tgix - 08-15-2019, 01:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB