Lumen - 为资产 ex 图像生成完全合格的 url - 而 运行 测试 - phpunit tests/Controllers/FilesControllerTest.php

Lumen - Generate fully-qualified url for an asset ex image - While running tests - phpunit tests/Controllers/FilesControllerTest.php

我是 Lumen 的新手。

我有路径public/profile/pic.png

我想为这张照片生成 url 并将 url 保存到数据库中。

我尝试了函数 url(public/profile/pic.png)。其创建为 http://public/profile/pic.png。不正确 url.

我试过了asset(public/profile/pic.png)

错误 - Call to undefined function asset。 我尝试添加 UrlGenerator class。但它说 class 未找到。

我在这里被打动了。请任何人帮助我。

编辑: 对我来说,甚至 url() 也不能正常工作。它没有创建正确的 url。 http://public/profile/pic.png。域名没有被添加。 而且 - 我尝试添加 UrlGenerator class。但它说 class 未找到。

我发现,在Lumen上测试时,没有使用服务器域名。 这就是 url() 不起作用的原因。