douxia3505 2015-10-01 21:05
浏览 42
已采纳

Laravel 5.1不允许你传入url params(有配置)

Consider the following test:

public function it_should_contain_a_list_of_investors_who_belong_to_one_or_more_investment() {
    $this->createInvestment();

    $investor = factory(User::class)->create([
        'role_id' => 4
    ]);

    $response = $this->actingAs($investor)
                     ->call('GET', 'api/v1/investors?include=investments');

    dd(json_decode($response->getContent()));
    $this->assertNotEmpty(json_decode($response->getContent()));
}

Now consider the following action this test is calling:

public function getAllInvestorsForCompany($slug)
{
    $users = $this->investorEntity->usersForCompany($slug);

    $resource = new Collection($users, new InvestorTransformer, 'investor');
    dd($_GET);
    if (isset($_GET['include'])) {
        $usersData = $this->manager->parseIncludes($_GET['include'])->createData($resource)->toArray();
    } else {
        $usersData = $this->manager->createData($resource)->toArray();
    }

    return response()->json($usersData);
}

Note the dd, the $_GET returns []

Lets do the same test in the browser:

array:1 [▼
  "include" => "investments.offering.company"
]

Ok so in the browser I get back investments.offering.company, because that is what I am passing in as the ?include= But in the test its like laravel ignores the ?include and moves on.

is this a default behaviour of laravel 5.1 tests and if so how do I shut it off?

  • 写回答

2条回答 默认 最新

  • douzen1896 2015-10-01 21:21
    关注

    The 3rd argument for call is for parameters.

    $response = $this->actingAs($investor)
        ->call('GET', 'api/v1/investors', ['include' => 'investments']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源