3
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?

DrupalのPHPUnit実行方法メモ

Posted at

コアのUnitテスト実行方法。

$ cd path/to/project_root
$ ./vendor/bin/phpunit -c web/core web/core/modules/system/tests/src/Unit
実行結果
PHPUnit 9.6.17 by Sebastian Bergmann and contributors.

Testing /Users/hikarumaruyama/src/github.com/hmaruyama/drupal-exercise-q12024/web/core/modules/system/tests/src/Unit
...............................................................  63 / 113 ( 55%)
..................................................              113 / 113 (100%)

Time: 00:00.423, Memory: 22.00 MB

OK (113 tests, 380 assertions)

Legacy deprecation notices (12)

さらに、ddevで実行する方法。

$ ddev exec ./vendor/bin/phpunit -c web/core web/core/modules/system/tests/src/Unit

ddevコンテナ内でKernelテストを実行する方法。
まずは web/core/phpunit.xml.dist の内容を web/core/phpunit.xml にコピーする。

$ cp web/core/phpunit.xml.dist web/core/phpunit.xml

phpunit.xmlの中身を、SIMPLETEST_BASE_URLSIMPLETEST_DB の2箇所書き換える。

phpunit.xml
    <env name="SIMPLETEST_BASE_URL" value="http://drupal-exercise-q12024.ddev.site"/>
    <env name="SIMPLETEST_DB" value="mysql://db:db@db/db"/>

プロジェクトルート直下で、 ddev exec を頭につけて実行する。

$ ddev exec ./vendor/bin/phpunit -c web/core web/core/modules/system/tests/src/Kernel

実行結果

PHPUnit 9.6.17 by Sebastian Bergmann and contributors.

Testing /var/www/html/web/core/modules/system/tests/src/Kernel
...............................................................  63 / 264 ( 23%)
............................................................... 126 / 264 ( 47%)
............................................................... 189 / 264 ( 71%)
............................................................... 252 / 264 ( 95%)
............                                                    264 / 264 (100%)

Time: 03:36.452, Memory: 16.00 MB

OK (264 tests, 2179 assertions)

コントリビュートモジュールも同じ方法でKernelテストを実行できた。

$ ddev exec ./vendor/bin/phpunit -c web/core web/modules/contrib/devel/tests/src/Kernel/
3
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
3
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?