LoginSignup
2
3

More than 5 years have passed since last update.

FuelPHPでユニットテストを行う設定

Last updated at Posted at 2015-04-13

CentOS 6.5 環境で、

  • PHPUnit
  • Stagehand_TestRunner

を使った自動テストの準備。

PHPUnit, Stagehand_TestRunner のインストールをcomposerで行う場合。

設定

項目 設定値
FuelPHPプロジェクトファイルpath /path/to/project

必要なパッケージをOSにインストール

# yum install php-xml
# yum install php-mbstring

Stagehand TestRunner のインストール

composer.json の設定

/path/to/project/composer.json に require-dev 項目を追加

"require-dev": {
    "piece/stagehand-testrunner": ">=3.6.1" 
},

composerの実行

$ cd /path/to/project
$ php composer.phar update piece/stagehand-testrunner

インストールされていることの確認

$ /path/to/project/vendor/bin/testrunner --version
Stagehand_TestRunner version 4.1-gba4fca8

Copyright (c) 2005-2014 KUBO Atsuhiro and contributors,
All rights reserved.

PHP Unit のインストール

composer.json の設定

"require-dev": {
    "phpunit/phpunit" : "4.6.*"
},

composerの実行

$ cd /path/to/project
$ php composer.phar update phpunit/phpunit

インストールされていることの確認

$ /path/to/project/vendor/bin/phpunit --version
PHPUnit 4.6.2 by Sebastian Bergmann and contributors.

テストのテスト

Stagehand TestRunnerの準備

$ cd /path/to/project/fuel
$ ./vendor/bin/testrunner compile -p ./vendor/autoload.php

テストクラスの作成

/path/to/project/fuel/app/test/model/SampleTest.php として、以下を作成

<?php
Class SampleTest extends PHPUnit_Framework_TestCase
{
    /**
     * @test
     */
    public function TestTest()
    {
        $this->assertTrue(true);
    }

テストクラスファイルの監視を行いながらテストの実行

$ cd /path/to/project/fuel
$ ./vendor/bin/testrunner phpunit -p ./vendor/autoload.php -a ./app/tests/

(略)

その他オプション

ヘルプ

$ ./vendor/bin/testrunner phpunit --help

(phpunitに対するヘルプを表示させる必要があるので、testrunner --help ではない)

通知

OSXの通知センターに結果を通知させる。サウンドが出るので、失敗か成功かを耳で確認できる。

$ ./vendor/bin/testrunner phpunit -m -p ./vendor/autoload.php -a ./app/tests/
2
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
2
3