LoginSignup
6
5

More than 5 years have passed since last update.

LaravelでPhpunitをステップ実行するシンプルな方法

Last updated at Posted at 2015-07-12

概要

Laravel4.2で、ユニットテストをステップ実行する方法です。
既にxdebugを利用して、ブラウザでのステップ実行を行っている人は、phpunitをブラウザで実行すれば、すぐにphpunitのステップ実行ができます。phpunitをブラウザで実行する方法を紹介します。

対象

・ブラウザでxdebugからステップ実行の設定がすでにできている人
・ごくたまに、phpunitをステップ実行してソースやライブラリの動きを確認したい人

手順

PHPUnitを実行するルートを追加して、ブラウザから通常通りxdebugでデバッグできます。

//route.phpにphpunit実行用のルートを作成
Route::get("phpunit", function(){
    //通常コマンドラインで渡す以下のようなパラメタを、配列に入れます。
    // phpunit -c phpunit.xml --filter testMyUnitTest app/tests/MyUnitTest
    // ファイルは、route.phpからのパスになるので、必要に応じて変更してください。
    $argv = array(
        "-c",
        "../phpunit.xml",
        "--filter",
        //ステップ実行したいテスト名
        "testMyUnitTest",
        //ステップ実行したいテストのあるファイル
        __DIR__."/tests/MyUnitTest.php"
        );

    $_SERVER['argv'] = $argv;
    $command = new PHPUnit_TextUI_Command();
    $ret = $command->run($argv, false);
});
6
5
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
6
5