我在测试文件中,我想启动一些 symfony 命令,即一个数据库,然后是一个 drop,然后是一个 create i create schema:
public function runCommand(Client $client, $command)
{
$application = new Application($client->getKernel());
$application->setAutoExit(false);
$fp = tmpfile();
$input = new StringInput($command);
$output = new StreamOutput($fp);
$application->run($input, $output);
fseek($fp, 0);
$output = '';
while (!feof($fp)) {
$output = fread($fp, 4096);
}
fclose($fp);
return $output;
}
公共函数 cleanDataBaseTest() {
$client = self::createClient();
$command_drop_database = $this->runCommand($client, 'doctrine:database:drop --env=test --force');
$command_create_database = $this->runCommand($client, 'doctrine:database:create --env=test');
$command_create_schema = $this->runCommand($client, 'doctrine:schema:create --dump-sql');
echo $command_create_schema;
/*
ALTER TABLE.....
*/
}
或者当我执行 echo $ command_create_schema 时,我只更改表。
C6 FOREIGN KEY (akey) REFERENCES atable (id);
ALTER TABLE atablea ADD CONSTRAINT FK_646DFFB72576E0FD FOREIGN KEY (anid) REFERENCES ....
因此,如果我正在执行命令: php app / 控制台原则:模式:create - dump-sql 我得到了 create 和 alter 表
你知道为什么吗 ?