tomriddle1403's avatar

Test Upload Image

Hello everyone, I am trying to test the function uploadImage of my controller. I run into this error when trying to Mockery an Uploadedfile. Exception: Serialization of 'Mockery_0_Symfony_Component_HttpFoundation_File_UploadedFile' is not allowed

Below is my test case.

@test **/ public function a_user_can_upload_an_image() {
    //$this->app->instance(Request::class, $request);

   $file = Mockery::mock(UploadedFile::class, [
        'getClientOriginalName' => 'test',
        'getClientOriginalExtension' => 'jpg'
    ]);

   $file->shouldReceive('move')->once();

    $files = ['image' => $file];
    $response = $this->action('POST', 'Admin\Pages@uploadImage', ['id' => 3], ['file' => $files]);
    print_r (Session::all());
    $this->assertEquals(302, $response->status());
    $this->assertRedirectedTo(URL::previous());
    $this->assertSessionHas('tab_active', '#tab-images');

    //$this->assertSessionHas('errors.');
   $this->assertSessionHas('status', 'Images has been uploaded successfully');
}
0 likes
0 replies

Please or to participate in this conversation.