LoginSignup
5
1

More than 3 years have passed since last update.

PhpStorm+Docker+PHPUnitでテストをする

Last updated at Posted at 2020-11-01

PhpStormの上の方に、RUNボタンがありますよね。
ここでいろいろなCofigurationを作ることで、Scriptを実行したり、
UnitTestを走らせることが出来ます。

今回は表題のとおり、Docker環境上でPhpStormからテストを走らせたい場合の
設定をしましたので共有します。

Interpreterの設定

まず、PHPのInterpreterから設定が必要です。
今回の場合ははDockerコンテナ内のInterpreterを指定します。
⌘,で設定画面を開き、phpと検索するとLaguage$Frameworksというのが見えると思いますのでクリックしてください。

CLI Interpreterを設定します。
Screen Shot 2020-11-01 at 22.06.52.png

...を押すと下記のような画面になりInterpreterを追加できます。
左上の+を押してください。
Screen Shot 2020-11-01 at 22.07.12.png

From Docker...を押します。
Screen Shot 2020-11-01 at 22.07.21.png

Docker Composeにチェックを入れ、ConfigurationFileにdocker-compose.ymlのPathを入力。
すると、コンテナ一覧がService:のところに現れると思うので、PHPがインストールされているコンテナを選んでください。
Screen Shot 2020-11-01 at 22.08.22.png

これで設定されました!
Screen Shot 2020-11-01 at 22.08.52.png

テスト側の設定

Test Frameworksを選択し、左上+からPHPUnit by Remote Interpreterを追加します。
Screen Shot 2020-11-01 at 22.25.38.png
先程設定したものを選択。
Screen Shot 2020-11-01 at 22.26.18.png
Path to Scriptに、Dockerコンテナ上にあるautoload.phpを選択します。
Default configuration fileにもphpuni.xmlへのPathを書きます。
Screen Shot 2020-11-01 at 22.28.32.png

最後に実行ファイル設定

エディター右上のRUNボタン隣にEdit Configurationがあるのでクリック。
Screen Shot 2020-11-01 at 22.54.26.png

左の+ボタンからPHPUnit用設定を追加し、名前は任意のものをつけます。
Defined in the Configuration fileにチェックを付けてOKボタンを押したら完了
🎉
Screen Shot 2020-11-01 at 22.30.48.png

5
1
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
5
1