phpunitを使用したテストしていますが、ローカル環境ではすべてのテストに合格するのにCircleCIでのテストでは以下のエラーが出てしまいます。
環境 :Laravel Framework 6.18.20
**
CircleCIでのエラー
PHPUnit 8.5.8 by Sebastian Bergmann and contributors. E.F... 6 / 6 (100%) Time: 476 ms, Memory: 30.00 MB There was 1 error: 1) Tests\Feature\ArticleControllerTest::testIndex Illuminate\Auth\Access\AuthorizationException: This action is unauthorized. /home/circleci/project/vendor/laravel/framework/src/Illuminate/Auth/Access/Response.php:119 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Auth/Access/Gate.php:318 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authorize.php:43 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:77 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 /home/circleci/project/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:56 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:67 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:105 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:683 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:658 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:624 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:613 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:170 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:130 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:63 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 /home/circleci/project/vendor/fideloper/proxy/src/TrustProxies.php:57 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:105 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:145 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:110 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:469 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:259 /home/circleci/project/tests/Feature/ArticleControllerTest.php:17 -- There was 1 failure:
エラーの内容を解釈するになんらかの認証が通っていないのかなと思いますが皆目分かりません。
どうかよろしくお願いします。
ArticleControllerTest.php
<?php namespace Tests\Feature; use App\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Tests\TestCase; class ArticleControllerTest extends TestCase { use RefreshDatabase; public function testIndex() // ここのテストが通らない { $this->withoutExceptionHandling(); $response = $this->get(route('articles.index')); $response->assertStatus(200) ->assertViewIs('articles.index'); } public function testGuestCreate() { $responce = $this->get(route('articles.create')); $responce->assertRedirect(route('login')); } public function testAuthCreate() { $user = factory(User::class)->create(); $response = $this->actingAs($user) ->get(route('articles.create')); $response->assertStatus(200) ->assertViewIs('articles.create'); } }
ArticleTest.php
<?php namespace Tests\Feature; use App\Article; use App\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Tests\TestCase; class ArticleTest extends TestCase { use RefreshDatabase; public function testIsLikeByNull() { $article = factory(Article::class)->create(); $result = $article->isLikedBy(null); $this->assertFalse($result); } public function testIsLikedByTheUser() { $article = factory(Article::class)->create(); $user = factory(User::class)->create(); $article->likes()->attach($user); $result = $article->isLikedBy($user); $this->assertTrue($result); } public function testIsLikedByAnother() { $article = factory(Article::class)->create(); $user = factory(User::class)->create(); $another = factory(User::class)->create(); $article->likes()->attach($another); $result = $article->isLikedBy($user); $this->assertFalse($result); } }
あなたの回答
tips
プレビュー