LoginSignup
6
3

More than 5 years have passed since last update.

Symfony4を使った開発ではまったところ 2018春

Last updated at Posted at 2018-03-30

LiipFunctionalTestBundleが使えない

現象

composer require --dev liip/functional-test-bundle すると一応入る。(v1.9系)
が、最も使いたいfixtureをymlで書いてロードする用途では使えない。

具体的には、
nelmio/aliceを入れろと言われる 'nelmio/alice should be installed to use this method.'



composer require --dev nelmio/alice とするとnelmio/aliceのv3系が入るが、nelmio/alice v3系とLiipFunctionalTestBundleは互換性がない。



composer require nelmio/alice:"^2.0" とすると、今度はnelmio/alice v2系がSymfony3+と互換性がなく入らない。

解決策

LiipFunctionalTestBundle v2系を使う。ただしまだアルファ版。
composer require --dev liip/functional-test-bundle:"~2.0@alpha" nelmio/alice theofidry/alice-data-fixtures

なお、LiipFunctionalTestBundleのWebTestCaseで $this->loadFixtureFiles(['path/to/yml']); したいだけならHautelookAliceBundleは要らなくなった。
その代わりに必要になったのが theofidry/alice-data-fixtures https://github.com/theofidry/AliceDataFixtures

nelmio/alice theofidry/alice-data-fixtures をcomposer require後、実際に使うためにはバンドルを有効にする必要がある。
まだ(?)flex用レシピがないので config/bundles.php に手動で追加する。

<?php
return [
    // ..
+    Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['dev' => true, 'test' => true],
+    Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true],
];

config/bundles.php を更新した後はキャッシュクリアが必要(dev, testであっても!)
bin/console cache:clear --env=test

NotFoundHttpException, BadRequestHttpExceptionなどHTTPステータスコード制御系の例外がキャッチされない

現象

404とか400にするつもりでコントローラ内でこの系統の例外を投げたら、500エラーになっちゃう。

解決策

この系統の例外を自動キャッチしてHTTPステータスコードを変える機能は、実は symfony/twig-bundleExceptionListener の働きだったので、同様のものを自前で書くか composer require symfony/twig-bundle する。
symfony/twig-bundleはレシピがあるので自動で有効化された。

機能テストをするとSQLのログがバーっと画面に表示される

$ composer require symfony/monolog-bundle
すると出なくなる

TBA...

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3