我正在嘗試為 Symfony 撰寫 API 測驗
public function testRegistration(): void
{
$response = static::createClient()->request(
'POST',
'/register',
[
'body' => json_encode([
'email' => '[email protected]',
'password' => '12345678'
])
]
);
$this->assertResponseIsSuccessful();
$this->assertJsonContains([]);
}
我有這個配置
when@test:
doctrine:
dbal:
driver: pdo_sqlite
memory: true
charset: UTF8
但得到一個錯誤
An exception occurred while executing a query: SQLSTATE[HY000]: General error: 1 no such table: user
如何解決這個問題?
uj5u.com熱心網友回復:
它不會自動發生。您需要更新資料庫中的模式。
使用它(在 setUp 函式或測驗函式中)設定資料庫。
$entityManager = $kernel->getContainer()->get('doctrine.orm.entity_manager');
$metadata = $entityManager->getMetadataFactory()->getAllMetadata();
$schemaTool = new SchemaTool($entityManager);
$schemaTool->updateSchema($metadata);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/497532.html
