public function testUpload()
 {
     Photo::shouldReceive('validateMimeType')->once()->andReturn(true);
     Photo::shouldReceive('validateFileSize')->once()->andReturn(true);
     Photo::shouldReceive('upload')->once()->andReturn(['type' => 'cloudinary', 'url' => 'http://res.cloudinary.com/huytbt-test/image/upload/v1438591244/pfpkrfwadonc7hvvt6a6.jpg', 'extra' => ['public_id' => 'pfpkrfwadonc7hvvt6a6', 'version' => 1438591244, 'signature' => 'e2082315dd0f5ba4660aa40f8ee2f51abe17e53b', 'width' => 241, 'height' => 209, 'format' => 'jpg', 'resource_type' => 'image', 'created_at' => '2015-08-03T08:40:44Z', 'tags' => [], 'bytes' => 9427, 'type' => 'upload', 'etag' => '4c8abc0ae31ef40f95a50e2c39ddba7d', 'url' => 'http://res.cloudinary.com/huytbt-test/image/upload/v1438591244/pfpkrfwadonc7hvvt6a6.jpg', 'secure_url' => 'https://res.cloudinary.com/huytbt-test/image/upload/v1438591244/pfpkrfwadonc7hvvt6a6.jpg', 'original_filename' => 'image']]);
     $uploadedFile = new UploadedFile(__DIR__ . '/../../resources/image.jpg', 'image.jpg');
     $res = $this->call('POST', '/photos', [], [], ['image' => $uploadedFile]);
     $this->assertEquals(201, $res->getStatusCode());
     $results = json_decode($res->getContent());
     $this->assertEquals('cloudinary', $results->entities[0]->type);
     $this->assertEquals('http://res.cloudinary.com/huytbt-test/image/upload/v1438591244/pfpkrfwadonc7hvvt6a6.jpg', $results->entities[0]->url);
 }
 /**
  * Get a validator
  *
  * @param  array  $data
  * @return \Illuminate\Contracts\Validation\Validator
  */
 protected function validator(array $data)
 {
     Validator::extend('mimetype', function ($attribute, $value, $parameters) {
         return Photo::validateMimeType($value->getMimeType());
     });
     Validator::extend('filesize', function ($attribute, $value, $parameters) {
         return Photo::validateFileSize($value->getSize());
     });
     Validator::replacer('mimetype', function ($message, $attribute, $rule, $parameters) {
         return 'Not allow upload this file type.';
     });
     Validator::replacer('filesize', function ($message, $attribute, $rule, $parameters) {
         return 'File size too large.';
     });
     return Validator::make($data, ['image' => 'required|mimetype|filesize']);
 }