k-holyのPHPとか諸々メモ

Webで働くk-holyがPHP(スクリプト言語)とか諸々のことをメモしていきます。ソースコードはだいたいWindowsで動かしてます。

Composerでプロジェクトグローバルにインストールした Stagehand_TestRunner + PHPUnit を ver.4 に更新(Windows7 + NYAOS編)

PHPUnit 4 に対応、PEARおよびPHPUnit3.6のサポートを終えた Stagehand_TestRunner V4 をローカル開発環境 (Windows7) に入れたメモです。特に新しいことはしていません。

内容的には Composerでプロジェクトグローバルに Stagehand_TestRunner + PHPUnit をインストール(Windows7 + NYAOS編) の続きになります。

前回時点で Stagehand_TestRunner は PHPUnit4系に未対応だったのですが、その後すぐ対応されてまして、もう2ヶ月経ってしまいました。

そういうわけで今回は PHPUnit 3.7 → 4.1, Stagehand_TestRunner 3.6 → 4.1 という更新を行います。

以下、シェルは NYAOS を使っています。

Windowsの場合 composer global コマンドでインストールしたファイルは %APPDATA%\Composer 以下に配置されます。

(私の環境では C:\Users\k_horii\AppData\Roaming\Composer になりました。)

composer.json ファイルもここにあります。

{
    "require": {
        "piece/stagehand-testrunner": "~4.1@dev",
        "phpunit/phpunit": "4.1.*"
    }
}

GitHubリポジトリを見たところ、Stagehand_TestRunnerの開発版4.1ではまだ安定版が出ていないPHPUnit4.2まですでに対応されているようです。

READMEの導きに従い @devフラグを付けて入れることにします。

@devの意味については kohkimakimoto さんの翻訳記事が参考になります。

なおPHPUnitの方は、安定版の4.1を指定しました。チキンですみません…。

$ composer global update
Changed current directory to C:/Users/k_horii/AppData/Roaming/Composer
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing symfony/class-loader (v2.4.5)
  - Installing sebastian/version (1.0.3)
    Downloading: 100%

  - Removing symfony/yaml (v2.4.5)
  - Installing symfony/yaml (v2.5.2)
    Loading from cache

  - Removing symfony/process (v2.4.5)
  - Installing symfony/process (v2.5.2)
    Downloading: 100%

  - Removing symfony/finder (v2.4.5)
  - Installing symfony/finder (v2.5.2)
    Downloading: 100%

  - Removing symfony/dependency-injection (v2.4.5)
  - Installing symfony/dependency-injection (v2.5.2)
    Downloading: 100%

  - Removing symfony/console (v2.4.5)
  - Installing symfony/console (v2.5.2)
    Loading from cache

  - Removing symfony/filesystem (v2.4.5)
  - Installing symfony/filesystem (v2.5.2)
    Loading from cache

  - Removing symfony/config (v2.4.5)
  - Installing symfony/config (v2.5.2)
    Loading from cache

  - Removing piece/stagehand-testrunner (v3.6.2)
  - Installing piece/stagehand-testrunner (dev-master 184496d)
    Cloning 184496d0c39b304a5db907e6d5b704ad0c436267

  - Installing sebastian/exporter (1.0.1)
    Downloading: 100%

  - Installing sebastian/environment (1.0.0)
    Downloading: 100%

  - Installing sebastian/diff (1.1.0)
    Loading from cache

  - Installing sebastian/comparator (1.0.0)
    Downloading: 100%

  - Removing phpunit/phpunit-mock-objects (1.2.3)
  - Installing phpunit/phpunit-mock-objects (2.1.5)
    Downloading: 100%

  - Removing phpunit/php-code-coverage (1.2.17)
  - Installing phpunit/php-code-coverage (2.0.9)
    Downloading: 100%

  - Removing phpunit/phpunit (3.7.37)
  - Installing phpunit/phpunit (4.1.4)
    Downloading: 100%

Writing lock file
Generating autoload files

PHPUnitはライブラリの一部が sebastian/*** に外出しされたみたいです。Stagehand_TestRunnerは最新のdev-masterが入りました。ついでにSymfonyコンポーネントも2.5系に更新されてます。

testrunner コマンドを実行してみると…

$ testrunner
PHP Warning:  require_once(Stagehand/TestRunner/Core/Bootstrap.php): failed to open stream: No such file or directory in C:\php\testrunner on line 86

Warning: require_once(Stagehand/TestRunner/Core/Bootstrap.php): failed to open stream: No such file or directory in C:\php\testrunner on line 86
PHP Fatal error:  require_once(): Failed opening required 'Stagehand/TestRunner/Core/Bootstrap.php' (include_path='.;c:\php\includes') in C:\php\testrunner on line 86

Fatal error: require_once(): Failed opening required 'Stagehand/TestRunner/Core/Bootstrap.php' (include_path='.;c:\php\includes') in C:\php\testrunner on line 86

以前にPEARでインストールした際の C:\php にtestrunnerコマンドが残っていて、PATH環境変数のせいでそちらが呼ばれているようです。

そういえば、NAYOSのalias設定にまかせてGlobal Composerのコマンドにパスを通してなかったような。

C:\php 以下のファイルは削除、NYAOSの設定ファイルを編集してPATH環境変数にパスを追加、前回aliasに定義したコマンドも修正します。

alias testrunner-phpunit "testrunner phpunit -c testrunner.yml | cat"

set PATH=%PATH%;%APPDATA%\Composer\vendor\bin

PEARサポート切り、Composerオートロード対応ということで、これだけでいけるようになったはず…。

$ source ~/_nya
$ testrunner-phpunit
Please run the following command before running the phpunit command:

  testrunner compile

あっ、また…(汗)

インストール後 phpunit コマンドの前に testrunner compile が必要なのでした。

$ testrunner compile
$ testrunner-phpunit
PHPUnit 4.1.4 by Sebastian Bergmann.

Configuration read from C:\Users\k_horii\Documents\Projects-priv\Volcanus\Volcanus_TemplateRenderer\phpunit.xml

The Xdebug extension is not loaded. No code coverage will be generated.

....................................

(中略)

Time: 1.85 seconds, Memory: 10.00Mb

OK (36 tests, 39 assertions)

やったー。