LoginSignup
1
0

More than 3 years have passed since last update.

laravel dumpが原因でphpunit Target class [config] does not exist

Last updated at Posted at 2020-11-23

備忘録です。
コントローラーを書いている時など、dump()は画面で確認出来て便利なのですが、
そのdumpが残ったままphpunit で当該コントローラーのテストを行うと、
Target class [config] does not exist
のエラーが起こる事があります。

Target class [config] does not exist
が起こる状態を色々見ていて、どうもdump()が怪しいと気が付いたのでした。
そこで、テスト時と実行時で切りわけるdumpもどきを作成してみました。

class MyFunctions
{

public static function mydump(...$d){
    //$_SERVER['APP_ENV'] は phpunit 実行時のみセットされるみたい
    if( isset($_SERVER['APP_ENV'])){
        foreach($d as $n){ var_dump($n); }
    }else{
        foreach($d as $n){ dump($n); }
    }
}

}

呼び出し可能な状態にしておいて、dump()と書いている部分を、MyFunctions::Mydump()に書き換えていけばどちらでも通るようになりました。
実運用する際にmydumpの中味書き換えてしまえばdump()が残ることもなさそうです。

1
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
1
0