【问题标题】:Named Routes Not Recognised in Method When Called From PHPUnit Test从 PHPUnit 测试调用时,方法中无法识别命名路由
【发布时间】:2019-08-06 01:23:07
【问题描述】:

当从另一个包含命名路由的类调用方法时,无法识别该路由

这个PHPUnit测试是为了检查系统的功能是否仍然满足要求,因为系统很复杂。

从本地环境(宅基地流浪者)运行测试

我在这里调用方法表单:

$orderLines = (new EDIProcessController())->getChanges($order['ediOrder'], $order['partnerId']);

以及导致问题的命名路由:

$orderLine->item_url = route('warehouse.products.view', $itemDetails->id);

我收到以下错误:

InvalidArgumentException: Route [warehouse.products.view] not defined.

/home/vagrant/vr/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:305
/home/vagrant/vr/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:790
/home/vagrant/vr/app/Http/Controllers/Warehouse/EDI/SPS/EDIProcessController.php:1575
/home/vagrant/vr/vendor/laravel/framework/src/Illuminate/Support/Collection.php:861
/home/vagrant/vr/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Collection.php:139
/home/vagrant/vr/app/Http/Controllers/Warehouse/EDI/SPS/EDIProcessController.php:1746

路由文件中定义的路由:

Route::get('/view/{id}', 'Warehouse\ProductController@viewProduct')->name('warehouse.products.view');

当从 Laravel 应用程序中调用时,此路由工作正常,但在 PHPUnit 测试中不起作用

【问题讨论】:

    标签: laravel-5 phpunit


    【解决方案1】:

    终于找到答案了

    将require_once 用于子路由文件时会出现问题,这是由于路由文件的多个实例未全部获取所需文件而导致的。

    Here is a dicussion here that I eventually found

    在我们的路由文件的各个级别将require_once 切换为require 可以解决问题

    【讨论】:

      猜你喜欢
      • 2015-11-13
      • 2013-04-14
      • 2018-10-23
      • 2017-07-03
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 2015-01-20
      相关资源
      最近更新 更多