Latest

Monday, July 10, 2017

Image Mime Type Issue in BDD Testing

Asked by: Misagh Laghaee


I use Laravel and Behat and Mink for behavior testing and I have issue in one of the scenarios for testing image uploading.

My Scenario :

Scenario: Upload image
    When I attach the file "/images/pic.png" to "img"
    And I press "Upload"
    Then I should see "The image uploaded successfully"

And I have a validation in my controller like this :

$this->validate($this->request, [
    'img' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:1024',
]);

When I print the response, the uploaded file has application/octet-stream mime type. So the validation fails.

How can I fix it?


dd(request()) :

array:3 [
  "img" => Illuminate\Http\UploadedFile {#4871
    -test: false
    -originalName: "pic.png"
    -mimeType: "application/octet-stream"
    -size: "55916"
    -error: 0
    path: "/tmp"
    filename: "619efa338a3efe391405e269b61543bfb3b88322.png"
    basename: "619efa338a3efe391405e269b61543bfb3b88322.png"
    pathname: "/tmp/619efa338a3efe391405e269b61543bfb3b88322.png"
    extension: "png"
    realPath: "/tmp/619efa338a3efe391405e269b61543bfb3b88322.png"
    aTime: 2017-07-11 05:03:25
    mTime: 2017-07-11 05:03:25
    cTime: 2017-07-11 05:03:25
    inode: 538181
    size: 55916
    perms: 0100644
    owner: 1000
    group: 1000
    type: "file"
    writable: true
    readable: true
    executable: false
    file: true
    dir: false
    link: false
  }
]


Source

No comments:

Post a Comment

Adbox