Laravel 5でDBのテスト
Testing: Getting Started - Laravel - The PHP Framework For Web Artisans(テスト: テストの準備 5.7 Laravel)
テスト用の環境変数
テスト実行時の環境変数はphpunit.xmlに設定されるtestingになる
.env.testingを設定しても良い
In addition, you may create a .env.testing file in the root of your project. This file will override the .env file when running PHPUnit tests or executing Artisan commands with the --env=testing option.
phpunit.xmlに<env name="DB_CONNECTION" value="testing"/>のように設定しても良い
phpunit.xmlに定義したもののほうが.env.testingに定義したものより優先されるのでハマることがあるかも
テスト用DBのマイグレーション
前提
Laravel 5のDBのmigrationができた
MySQLでCREATE DATABASE testing;をした
.env.testingでDBの接続設定を記述した
やり方
php artisan migrate:refresh --seed --env=testing
--env=testingをつけるとtesting環境に対して実行できる
#Laravel_5
#ソフトウェアテスト