LoginSignup
0
0

More than 3 years have passed since last update.

【PHPUnit】Test code or tested code did not (only) close its own output buffers【laravel】

Posted at

概要

laravelでHTTPテストを行うとリスキーなテストという判定を受けることがある

黄色で言われるのでドキッとする
Test code or tested code did not (only) close its own output buffers

OK, but incomplete, skipped, or risky tests!
Tests: 12, Assertions: 18, Risky: 1.

環境

laravel 6.7.0
PHPUnit 8.5.0

原因

@section ディレクティブに文字列以外が入っているため。
第二引数には文字列以外を入れるとエラーになる。

XXX.blade.php
@section('title', $title)

例えばこのように動的プロパティで求めた値を入れていて、 null が入ってしまっていたりする。

XXX.blade.php
@section('name', $user->name)

解決

@endsectionで囲む

XXX.blade.php
@section('name')
    {{ $user->name}}
@endsection

記述が長くなるので少し嫌ですね。

空文字にしてしまう

XXX.blade.php
@section('name', $user->name ?? '')

こちらの方がスッキリします。

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