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条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀