Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@_mmmm_

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

More than 1 year has passed since last update.

概要

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
Help us understand the problem. What is going on with this article?
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
_mmmm_
サーバーサイドのエンジニアです!
wiz_inc
Wizは、最新のIoTやICTサービスをお客様に届ける「ITの総合商社」です

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?