diff --git a/src/Request.php b/src/Request.php index 31dcb85..1e8aed2 100755 --- a/src/Request.php +++ b/src/Request.php @@ -878,7 +878,8 @@ public static function errors() return array_merge( static::$errors, static::$validator ? static::$validator->errors() : [], - class_exists('\Leaf\Auth') ? static::auth()->errors() : [] + class_exists('\Leaf\Auth') ? static::auth()->errors() : [], + \Leaf\FS\File::errors() ); } } diff --git a/tests/request.test.php b/tests/request.test.php index 0929dd1..634399f 100644 --- a/tests/request.test.php +++ b/tests/request.test.php @@ -121,3 +121,32 @@ expect(Request::files(['avatar', 'missing']))->toBe(['avatar' => ['name' => 'me.png'], 'missing' => null]); expect(Request::files())->toHaveKeys(['avatar', 'doc']); }); + +test('errors includes failures recorded by the file system on upload', function () { + fakeRequest(); + + $errors = new ReflectionProperty(\Leaf\FS\File::class, 'errorsArray'); + $errors->setValue(null, []); + + $_FILES = ['avatar' => [ + 'name' => 'big.png', + 'type' => 'image/png', + 'tmp_name' => '/tmp/does-not-matter', + 'error' => 0, + 'size' => 5000, + ]]; + + expect(Request::upload('avatar', sys_get_temp_dir(), ['maxSize' => 100]))->toBeFalse(); + expect(Request::errors())->toHaveKey('upload'); + + $errors->setValue(null, []); +}); + +test('errors includes the extension failure raised by Request::upload itself', function () { + fakeRequest(); + + $_FILES = ['doc' => ['name' => 'run.exe', 'type' => 'application/x-msdownload', 'tmp_name' => '/tmp/x', 'error' => 0, 'size' => 10]]; + + expect(Request::upload('doc', sys_get_temp_dir(), ['extensions' => ['pdf']]))->toBeFalse(); + expect(Request::errors())->toHaveKey('upload'); +});