'https://api.example.test', 'filesystems.default' => 'public', 'filesystems.disks.public' => ['driver' => 'local', 'root' => $root, 'url' => 'https://api.example.test/storage', 'visibility' => 'public']]); $this->app->instance('filesystem', new FilesystemManager($this->app)); $png = tempnam(sys_get_temp_dir(), 'img'); file_put_contents($png, base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=')); try { $call = function (UploadedFile $file) { $request = Request::create('/agent/upload/image', 'POST', [], [], ['image' => $file]); $request->attributes->set('agent', $this->agent()); $this->app->instance('request', $request); return (new UploadController())->image($request)->getData(true); }; $ok = $call(new UploadedFile($png, 'proof.exe', 'image/png', null, true)); $this->assertSame(0, $ok['code'], (string) $ok['msg']); $this->assertMatchesRegularExpression('#^https://api\.example\.test/storage/images/[0-9a-f]{32}\.png$#', $ok['data']['path'], 'extension follows file content'); $this->assertFileExists($root . '/images/' . basename($ok['data']['path'])); $txt = tempnam(sys_get_temp_dir(), 'txt'); file_put_contents($txt, 'not an image'); $this->assertNotSame(0, $call(new UploadedFile($txt, 'a.png', 'image/png', null, true))['code']); } finally { @unlink($png); if (is_dir($root)) { array_map('unlink', glob($root . '/images/*') ?: []); @rmdir($root . '/images'); @rmdir($root); } } } }