在创建记录时,PHP单元测试失败

时间:2018-05-02 15:46:28

标签: php laravel phpunit

我在php中有一个测试,现在我使用create方法失败了。在线使用此控制器功能时工作正常,但测试失败。这是测试

public function testSendContactMail()
{
    $response = $this->call('POST','/contact-us',[
        'name' => '',
        'phone' => '',
        'email' => '',
        'message' => '',
        'contact'  => '',
        'help' => '$request->input()',
        'list' => '$request->input()'
    ]);

    $response->assertStatus(201);
}

这是使用路径

调用的控制器功能
public function sendMail(Request $request){
    $contact = EmailMessage::create([
        'first_name' => $request->input('firstName'),
        'last_name' => $request->input('lastName'),
        'phone_number' => $request->input('phone'),
        'email' => $request->input('email'),
        'message' => $request->input('message'),
        'contact_preference'  => $request->input('contact'),
        'help_you_with' => $request->input('help'),
        'email_list' => ($request->input('toList'))? true : false,
    ]);

    if($contact){
        Mail::to('test@test.com')
            ->queue(new ContactUs($contact));
        Mail::to($contact->email)
            ->queue(new ContactUs($contact));
        return Response::json([], 201); // Status code here
    }else{
        return Response::json([], 500);
    }
}

这是我传递给控制器​​的数据:

{
    firstName: this.contactForm.firstName,
    lastName: this.contactForm.lastName,
    phone: this.contactForm.phoneNunber,
    email: this.contactForm.email,
    message: this.contactForm.message,
    help: this.contactForm.help,
    list: this.contactForm.mailingList,
    contact: this.contactForm.contact
}

不确定发生了什么

0 个答案:

没有答案