LoginSignup
1
0

More than 1 year has passed since last update.

【Laravel + PHPUnit】parse_urlで受け取るヘッダー情報をPOSTする方法

Last updated at Posted at 2022-03-24

概要

テスト対象のビジネスロジックでparse_urlメソッドを利用し特定の値を取得したい場合につまづいたので指定方法をまとめる

<?php
$parentUrl = parse_url(url()->previous())['path'];
if (strpos($parentUrl, 'hoge')) {
    return 'hoge';
}

解決方法

fromを利用してヘッダー情報をカスタマイズします

public function test_OK()
{
    $id = Users::query()->first()->id;
    $response = $this
        ->from('hoge')
        ->actingAs($this->authUser)->get("admin/users/${id}");
    $response->assertViewIs('admin.users.show');
}
``
1
0
2

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