0
0

More than 1 year has passed since last update.

5分でPHPUnitをGitHub Actionsで動くようにする

Last updated at Posted at 2022-01-26

5分は誇張ですが…
サクッとPHPUnitをGitHub Actionsで動かす際のメモ

Step1 PHPUnitを動かす

PHPUnitのGetting Startedを参考にして

composerでPHPUnit追加

composer require --dev phpunit/phpunit ^9

composer.jsonにautoloadの設定を追加

composer.json
{
    "autoload": {
        "classmap": [
            "src/"
        ]
    },
    "require-dev": {
        "phpunit/phpunit": "^9"
    }
}

テスト対象とテストコードを準備

Getting Startedにある、src/Email.phpとtests/EmailTest.phpをコピペすればOK

PHPUnit実行

↑まで終わったら

./vendor/bin/phpunit tests

で、PHPUnitが動くはず。

Step2 GitHubActionsで動かす

後は、
.github/workflows/に適当な名前でyamlを作成してあげて

build.yml
name: Build
on: push

jobs:
  phpunit:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - run: composer install
      - run: ./vendor/bin/phpunit tests

な感じに書いて、リポジトリにPush
以降はpushするたびにActionsが動いてテストされる

最終的な構成

$ tree -a -I '.git|vendor|LICENSE|README.md|.gitignore|.phpunit.result.cache' 
.
├── .github
│   └── workflows
│       └── build.yml
├── composer.json
├── composer.lock
├── src
│   └── Email.php
└── tests
    └── EmailTest.php

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