Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 22 |
Sqlite | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 22 |
__construct($dsn, $user, $password) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
cleanup() | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
load($sql) | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 12 |
<?php | |
namespace Codeception\Util\Driver; | |
class Sqlite extends Db | |
{ | |
protected $hasSnapshot = false; | |
protected $filename = ''; | |
protected $con = null; | |
public function __construct($dsn, $user, $password) { | |
parent::__construct($dsn, $user, $password); | |
$this->filename = \Codeception\Configuration::projectDir().substr($this->dsn, 7); | |
$this->dsn = 'sqlite:'.$this->filename; | |
} | |
public function cleanup() { | |
$this->dbh = null; | |
file_put_contents($this->filename,''); | |
$this->dbh = new \PDO($this->dsn, $this->user, $this->password); | |
} | |
public function load($sql) { | |
if ($this->hasSnapshot) { | |
$this->dbh = null; | |
file_put_contents($this->filename, file_get_contents($this->filename . '_snapshot')); | |
$this->dbh = new \PDO($this->dsn, $this->user, $this->password); | |
} else { | |
if (file_exists($this->filename . '_snapshot')) unlink($this->filename . '_snapshot'); | |
parent::load($sql); | |
copy($this->filename, $this->filename . '_snapshot'); | |
$this->hasSnapshot = true; | |
} | |
} | |
} |