0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

symfony/http-kernelをphpstorm&dockerでphpunit&xdebug

Last updated at Posted at 2020-10-25

1.ソースのダウンロード
2.dockerの設定
3.phpstormの設定

#1. ソースのダウンロード

git clone https://github.com/symfony/http-kernel.git

#2. dockerの設定

cd ./http-kernel
mkdir docker
touch docker/Dockerfile
touch docker/php.ini
touch docker-compose.yml
Dockerfile
FROM php:7.4

RUN pecl install xdebug \
    && docker-php-ext-enable xdebug

RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y git
php.ini
; timezone
date.timezone = Asia/Tokyo

; error reporing
log_errors = On
error_log = /dev/stderr

; xdebug
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
docker-compose.yml
version: "3"
services:
  php-cli:
    build: ./docker
    volumes:
      - ./:/var/www/html
      - ./docker/php.ini:/usr/local/etc/php/php.ini
    working_dir: /var/www/html
  composer:
    image: composer
    volumes:
      - ./:/app
      - ./docker/php.ini:/usr/local/etc/php/php.ini
    working_dir: /app

#3. Composer Install

docker-compose run composer install
docker-compose run composer require --dev symfony/phpunit-bridge

ちなみにphpunit/phpunitは使いません。1

The PHPUnit bridge is designed to work with all maintained versions of Symfony components, even across different major versions of them. You should always use its very latest stable major version to get the most accurate deprecation report.

使うとエラーが出ます。

docker-compose run php-cli ./vendor/bin/phpunit Tests/
[25-Oct-2020 07:28:39 Asia/Tokyo] PHP Fatal error:  Trait 'Symfony\Bridge\PhpUnit\ExpectDeprecationTrait' not found in /var/www/html/Tests/Controller/ContainerControllerResolverTest.php on line 21

注意

docker-compose run composer ./vendor/bin/simple-phpunit

を一度実行させておくことで、symfony/phpunit-bridgeからphpunit/phpunitをインストールさせておく

#3. phpstormの設定

File > Settings > Languages & Frameworks > PHP

phpstormがdockerのphpを実行するように設定します

CLI interpreterの右端にある...をクリック
Screenshot from 2020-10-25 07-33-45.jpg

追加の+ボタンクリックして、From Docker,...を選択
Screenshot from 2020-10-25 07-34-02.png

Docker-composeにチェックを入れ、dockerから実行させるphpのservice(この場合php-cli)を選択
Screenshot from 2020-10-25 07-34-26.png

OK押して、phpが読み込まれてversionなどが表示されてれば問題ありません
Screenshot from 2020-10-25 07-34-43.png

Phpunit

File > Settings > Languages & Frameworks > PHP > Test Frameworks

phpstormがdocker内のphpunitを実行するように設定します

追加の+ボタンから PHPUnit by Remote Interpreterを選択
Screenshot from 2020-10-25 07-37-21.png

php-cliを選択
Screenshot from 2020-10-25 07-37-40.png

  1. PHPUnit library の Path to phpunit.phar にチェック入れる
  2. Path to phpunit.pharに /var/www/html/vendor/bin/simple-phpunit
  3. Test Runner の Default configulation file にチェック入れ、/var/www/html/phpunit.xml.dist

Screenshot from 2020-10-25 10-00-25.png

いざ実行

editor右上の虫のアイコン左のセレクタでedit configurationを選択
画面が開いたら追加の+ボタンからPhpunitを選択し、下記のように設定
Screenshot from 2020-10-25 09-56-18.png

breakpointを貼って、simple-phpunitが選択されている状態で虫アイコンをクリック

Screenshot from 2020-10-25 08-30-20.png

  1. https://symfony.com/doc/current/components/phpunit_bridge.html#installation

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?