我有一个Symfony命令,用于删除实体文件并使用其他数据库中的新信息重新生成它。问题是测试会删除文件并再次创建它,但在test
目录下。
我想,因为它是一个测试,它不应该删除项目文件(模拟或创建虚拟文件)
/**
* @test
*/
public function test_command()
{
$kernel = static::createKernel();
$kernel->boot();
$application = new Application($kernel);
$application->add(new MyCommand());
$command = $application->find('my:command');
$commandTester = new CommandTester($command);
$commandTester->execute(
[
'command' => $command->getName(),
]
);
$statusCode = $commandTester->getStatusCode();
$this->assertEquals(0, $statusCode);
}
任何想法都要避免测试删除文件,就好像它是在“生产”中执行一样
提前致谢
更新1:
这是命令的代码。 generateEntity()
方法是谁删除表并创建新表(在我说的错误文件夹中运行测试)
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->logger->info(sprintf('Starting job "%s"', $this->getName()));
try {
$changesDone = $this->importService->importQuestionsAndChoices();
if ($changesDone) {
if (!$input->getOption('no-profile-generation')) {
$this->logger->info('Questions have changed. Re-generating table');
$this->profileGenerator->generateEntity();
}
} else {
$this->logger->info('No new questions or choices available');
}
} catch (\Exception $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
}
$this->logger->info(sprintf('Ending job "%s"', $this->getName()));
}