I have, almost completely, solved my problem by:
Install the drivers needed for db-communication ;)
PDO_SQLITE driver not present.. what to do?sudo apt-get install php5-sqlite
Recreate schema on every Test-run
https://stackoverflow.com/a/10463614/1177024
This is my Class testing against a database
namespace Qkprod\MangressBundle\Entity;
use Qkprod\MangressBundle\Entity\Genre;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
private $em;
/**
* Sets up environment for testing
* Regenerates Database schema before every test-run
*/
public function setUp() {
static::$kernel = static::createKernel();
static::$kernel -> boot();
$this -> em = static::$kernel->getContainer()
->get('doctrine')
->getEntityManager();
$this->regenerateSchema();
}
protected function tearDown() {
parent::tearDown();
$this -> em -> close();
}
/**
* Drops current schema and creates a brand new one
*/
protected function regenerateSchema() {
$metadatas = $this->em->getMetadataFactory()->getAllMetadata();
if (!empty($metadatas)) {
$tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
$tool -> dropSchema($metadatas);
$tool -> createSchema($metadatas);
}
}
public function testInsert() {
$genre = new Genre();
$genre -> setName("testGenre");
$this -> em -> persist($genre);
$this -> em -> flush();
$result = $this -> em
-> createQuery("SELECT g "
. " FROM QkprodMangressBundle:Genre g "
. " WHERE g.name = :name")
-> setParameter("name", $genre -> getName())
-> getResult();
$this -> assertEquals($result[0] -> getName(), $genre -> getName());
}
}
Could not get the LiipBundle to work but you can increase speed incredibly by setting up symfony to save the sqlite db in memory instead of filesystem.
https://stackoverflow.com/a/10460139/1177024
# app/config/config_test
doctrine:
dbal:
driver: pdo_sqlite
path: :memory:
memory: true
Or maybe only create the schema once and instead of recreating it, just override the database with a fresh backup.
I hope this shortens the search for some people having the same problem! Thanks to everyone helping me along the way :) You are great!