usage-additional-debug-output.md 1.7 KB

追加のデバッグ出力

Codeception は全ての出力をバッファするため、テストケースの中では単純な var_dump() を実行することが出来ません。 その代りに、Codeception\Util\Debug::debug() 関数を使って、テストを --debug オプションを付けて実行する必要があります。 例えば、

<?php

use Codeception\Util\Debug;

SomeDebugTest extends \yii\codeception\TestCase
{
    public function testSmth()
    {
        Debug::debug('some string');
        Debug::debug($someArray);
        Debug::debug($someObject);
    }

}

そして、コマンド php codecept.phar run --debug unit/SomeDebugTest を実行すると、次のような出力が表示されます。

  some string

  Array
  (
      [0] => 1
      [1] => 2
      [2] => 3
      [3] => 4
      [4] => 5
  )
  
  yii\web\User Object
  (
      [identityClass] => app\models\User
      [enableAutoLogin] => 
      [loginUrl] => Array
          (
              [0] => site/login
          )
  
      [identityCookie] => Array
          (
              [name] => _identity
              [httpOnly] => 1
          )
  
      [authTimeout] => 
      [autoRenewCookie] => 1
      [idParam] => __id
      [authTimeoutParam] => __expire
      [returnUrlParam] => __returnUrl
      [_access:yii\web\User:private] => Array
          (
          )
  
      [_identity:yii\web\User:private] => 
      [_events:yii\base\Component:private] => 
      [_behaviors:yii\base\Component:private] => 
  )

更なる説明は、Yii 2.0 決定版ガイド のテストの節を参照してください。