1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

laravel テスト実行時にキャッシュを使わないようにする

Posted at

概要

  • テスト実行時にキャッシュを使わないようにする方法をまとめる。

前提

  • テストが実行できる状態になっており、.env.testingを用いてテスト環境の設定を行っている。

方法

  1. config/cache.phpを開き、storesキーの配列に下記を追記する。

    config/cache.php
    'none' => [
        'driver' => 'null',
    ],
    
  2. 追記後config/cache.phpstoresキーの配列は下記の様になる。

    config/cache.php
    'stores' => [
    
    // ~~ 中略 ~~
    
        'none' => [
            'driver' => 'null',
        ],
    
    ],
    
  3. 下記の内容を.env.testingに追記する。

    .env.testing
    CACHE_DRIVER=none
    
  4. 下記を実行してキャッシュをクリアする。

    php artisan cache:clear
    
  5. テストを実行するとキャッシュのドライバーが割り当てられない状態でテストが動く。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?