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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀