How can I from PHP, re-create my Database, maybe inserting default data. Currently, I am intending to use the behavior for Unit Tests.
I am using Doctrine 2, Zend Framework 1.11, Zend_Test
for unit tests
I could use the CLI
doctrine orm:schema-tool:update --force
Or
doctrine orm:schema-tool:drop --force
doctrine orm:schema-tool:create
I am looking for a PHP replacement, so far found this
but it will look something like
$tool = new \Doctrine\ORM\Tools\SchemaTool($em);
$classes = array(
$em->getClassMetadata('Entities\User'),
$em->getClassMetadata('Entities\Profile')
);
$tool->dropSchema($classes, \Doctrine\ORM\Tools\SchemaTool::DROP_DATABASE);
$tool->createSchema($classes);
And I don't really want having to specify the model classes, esp in development when they can change. It should just read from the all classes specified in ... below ... just like with the CLI, you don't need to specify the classes you want?
$driverImpl = $config->newDefaultAnnotationDriver(array(realpath('../models')));
$config->setMetadataDriverImpl($driverImpl);
dropSchema()
andcreateSchema()
at every test is really expensive, and a large suite of tests takes forever to run. Using PHPUnit fixtures is much faster. I will have to check out Benjamin's extension as well. – Winnick