Given the following phpunit-bootstrap.php file that i use as bootstrap in php unit:
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../app/AppKernel.php';
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Input\ArrayInput;
use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand;
$kernel = new AppKernel('test', true); // create a "test" kernel
$kernel->boot();
$application = new Application($kernel);
// add the database:drop command to the application and run it
$command = new DropDatabaseDoctrineCommand();
$application->add($command);
$input = new ArrayInput(array(
'command' => 'doctrine:database:drop',
'--force' => true,
));
$command->run($input, new ConsoleOutput());
// add the database:create command to the application and run it
$command = new CreateDatabaseDoctrineCommand();
$application->add($command);
$input = new ArrayInput(array(
'command' => 'doctrine:database:create',
));
$command->run($input, new ConsoleOutput());
// add the schema:create command to the application and run it
$command = new CreateSchemaDoctrineCommand();
$application->add($command);
$input = new ArrayInput(array(
'command' => 'doctrine:schema:create',
));
$command->run($input, new ConsoleOutput());
It comes from Matias Noback blog. This is my config_test.yml configuration:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_sqlite
memory: true
When i call first test loading fixtures it says me like the database have not the table in his schema.
But if I switch to mysql pdo driver counterpart, the complain vaporizes.
The error I get is:
SQLSTATE[HY000]: General error: 1 no such table: usr_user_role
Just like the table has not been created. But the console outputs to me:
Dropped database for connection named "mydatabase"
Created database "mydatabase" for connection named default
ATTENTION: This operation should not be executed in a production environment.
Creating database schema...
Database schema created successfully!
PHPUnit 5.7.2 by Sebastian Bergmann and contributors.
Aucun commentaire:
Enregistrer un commentaire