【问题标题】:Laravel dependency injection does not find the classLaravel 依赖注入找不到类
【发布时间】:2017-04-10 21:23:02
【问题描述】:

我正在使用 PHPUnit 来测试我的应用程序,在这种情况下,我正在测试一个 API 调用(我正在通过它执行 GET、POST、PUT 和 DELETE)。 index 方法响应 GET(/api) 路由,在这个方法中我有一个自定义请求:

public function index(\Api\User\Requests\IndexRequest $request)
{
    // do some stuff...
}

Api\User\Requests\IndexRequest 类如下所示:

class Request extends IndexApiRequest
{
    // some methods in here
}

当我通过 PHPUnit 执行测试时,它会提示:

Class Api\User\Requests\IndexRequest does not exist

检查它在 Illuminate\Routing\RouteDependencyResolverTrait 中死亡的跟踪路由。我不知道如何干预执行,因为它似乎发生在 PHPUnit 和 Laravel 之间。

有人有想法吗?我正在使用在 Ubuntu 16.04、PHP 7.0 和 nginx 上运行的 Laravel 5.3、PHPUnit 5.6.5。

谢谢!

【问题讨论】:

    标签: php dependency-injection phpunit laravel-5.3


    【解决方案1】:

    class Request extends IndexApiRequest 更改为class IndexRequest extends IndexApiRequest

    【讨论】:

      猜你喜欢
      • 2014-02-02
      • 2017-09-04
      • 2022-01-16
      • 2016-07-19
      • 1970-01-01
      • 1970-01-01
      • 2018-10-22
      • 1970-01-01
      • 2023-03-23
      相关资源
      最近更新 更多