Symfony 4 アプリケーションで、複数のエンティティ マネージャーを構成しました。機能テストで、両方のマネージャーの DB テーブルを自動的に作成したいと考えています。
ただし、テストを実行すると; PHP ユニットで次のエラーが発生します。
PDOException: SQLSTATE[42S02]: ベース テーブルまたはビューが見つかりません: 1146 テーブル 'test.example' が存在しません
config/packages/doctrine.yaml:
doctrine:
dbal:
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
custom:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
orm:
default_entity_manager: default
auto_generate_proxy_classes: '%kernel.debug%'
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
Model:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Model'
prefix: 'App\Entity\Model'
alias: Model
custom:
connection: custom
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
Custom:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Custom'
prefix: 'App\Entity\Custom'
alias: Custom
テーブルを作成してフィクスチャをロードするには、現在Liip Functional Test Bundleを使用しています。
簡単なテストは次のようになります。
tests\Functional\GeneralControllerTest.php:
class GeneralControllerTest extends WebTestCase
{
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->loadFixtures([
SomeFixtures::class,
MoreFixtures::class,
]);
}
/**
* @dataProvider providePageUris
* @test
* @param string $uri
*/
public function checkThatPageLoads($uri)
{
$client = static::createClient();
/* ... more code ... */
$client->request(Request::METHOD_GET, $uri);
static::assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode());
}
/**
* @return array
*/
public function providePageUris()
{
return [
["/dashboard"],
];
}
}
テスト ケースで他のカスタム Doctrine EntityManager 用のデータベース テーブルを作成するにはどうすればよいですか?
私は追加しようとしました:
$this->loadFixtures([], true, "custom");
また:
$this->runCommand("doctrine:schema:create --env=test --em=custom");
テスト ケースの setUp() メソッドに追加しましたが、必要な結果にはなりませんでした。フィクスチャをデータベースにロードする前に、データベース テーブルをすべて作成する必要があります。