从包含命名路由的另一个类调用方法时,无法识别该路由
此PHPUnit测试是为了检查系统的功能是否仍然满足要求,因为系统很复杂。
测试是从本地环境运行的(homestead vagrant)
我在这里调用方法form:
$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
在routes文件中定义的路由:
Route::get('/view/{id}', 'Warehouse\ProductController@viewProduct')->name('warehouse.products.view');
此路由在Laravel应用程序中调用时运行良好,但在PHPUnit测试中不起作用
发布于 2019-05-29 08:05:05
终于找到了答案
对子路由文件使用require_once
时会出现问题,这是由于路由文件的多个实例并不都获取所需文件而导致的。
Here is a dicussion here that I eventually found
在我们的路由文件的所有级别将require_once
切换到require
可以解决这个问题
https://stackoverflow.com/questions/55174545
复制相似问题