Help us understand the problem. What is going on with this article?

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

概要

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 ?? '')

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした