第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

Laravel 路由上的 PHPunit 測試總是返回 404

Laravel 路由上的 PHPunit 測試總是返回 404

PHP
犯罪嫌疑人X 2023-08-19 16:50:52
我剛剛開始在我的 laravel 應(yīng)用程序上編寫 PHPUnit 路由測試,它通過瀏覽器和 Postman 運(yùn)行良好,但不是通過 PHPunit。示例:在本次測試中public function test_getAll(){    $this->withoutExceptionHandling(); // If i comment this line I get the 404 and not the error shown below    $response = $this->get('/api/users');    $response->assertStatus(401);}我得到:PHPUnit 8.5.3 by Sebastian Bergmann and contributors..E                                                                  2 / 2 (100%)Time: 1.89 seconds, Memory: 8.00 MBThere was 1 error:1) Tests\Feature\Users\UserRoute_SuperAdminTest::test_getAllSymfony\Component\HttpKernel\Exception\NotFoundHttpException: GET http://localhost/cms/api/usersE:\www\projects\cms-php\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithExceptionHandling.php:126E:\www\projects\cms-php\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:415E:\www\projects\cms-php\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:113E:\www\projects\cms-php\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\MakesHttpRequests.php:468E:\www\projects\cms-php\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\MakesHttpRequests.php:258E:\www\projects\cms-php\tests\Feature\Users\UsersRoute-SuperAdmin_Test.php:45奇怪的是:如果我將 URL 更改為:$response = $this->get('http://anythingatallinhere/api/users');我得到了我應(yīng)該得到的 401 響應(yīng)。更多上下文信息來解決問題。我的 env APP_URL 是APP_URL=http://localhost/cms,我正在以這種方式動態(tài)注冊路由:我有一個(gè) CoreServiceProvider ,其啟動過程如下:public function boot()    {       [...]        $moduleController = app()->make(ModuleController::class);        $moduleController->registerCoreRoutes();       [...]如果我使用php artisan route:list它們,它們也都已正確注冊。
查看完整描述

2 回答

?
翻過高山走不出你

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超3個(gè)贊

我最近遇到了類似的問題,但運(yùn)行這些后它起作用了:

php artisan config:clear
php artisan config:cache

特別是如果您更改了 .env 文件中剛剛更改的 APP_URL。

您還可以嘗試在 phpunit.xml 文件中processIsolation設(shè)置:true

<phpunit backupGlobals="false"
 backupStaticAttributes="false"
 bootstrap="bootstrap/autoload.php"
 colors="true"
 convertErrorsToExceptions="true"
 convertNoticesToExceptions="true"
 convertWarningsToExceptions="true"
 processIsolation="true"
 stopOnFailure="false">

編輯: 如果上述方法都不起作用,您還可以創(chuàng)建另一個(gè).env.testing并將您的設(shè)置APP_URLhttp://localhost. PHPUnit 將使用該文件中的變量。無論您的應(yīng)用程序的實(shí)際 URL 是什么,這都有效


查看完整回答
反對 回復(fù) 2023-08-19
?
蕪湖不蕪

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊

最簡單的方法是通過添加以下行來http://localhostphpunit.xml文件中設(shè)置 APP_URL:

<server name="APP_URL" value="http://localhost"/>

如果您希望變量在.env測試期間仍然可用,則此方法是最好的。創(chuàng)建您自己的.env.testing文件將覆蓋所有.env變量。


查看完整回答
反對 回復(fù) 2023-08-19
  • 2 回答
  • 0 關(guān)注
  • 153 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號