環境
- windows10
- PHP 7.2.10
- Laravel 5.8.30
質問
Laravelで初めてテストを書こうと、コントローラーテストを簡単に書いてみたらコケてしまいます。
しかしその原因がわかりません。
質問詳細
以下の図のように、とりあえずコントローラーのテストを作成します。
コードは以下です。
<?php namespace Tests\Unit; use Tests\TestCase; class HogeControllerTest extends TestCase { public function testIndex() { $response = $this->get(action('HogeController@index')); $response->assertStatus(200); } public function testTop() { $response = $this->get(action('HogeController@top')); $response->assertStatus(200); } }
実行します。
以下、実行コマンド
"./vendor/bin/phpunit"
エラーが発生します。
PHPUnit 6.5.14 by Sebastian Bergmann and contributors. E. 2 / 2 (100%) Time: 258 ms, Memory: 12.00MB There was 1 error: 1) Tests\Unit\HogeControllerTest::testIndex ErrorException: Declaration of Illuminate\Foundation\Testing\Assert::assertArraySubset($subset, $array, bool $checkForObjectIdentity = false, string $message = ''): void should be compatible with PHPUnit\Framework\Assert::assertArra ySubset($subset, $array, $strict = false, $message = '') D:\project\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Assert.php:42 D:\project\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:149 D:\project\tests\Feature\HogeControllerTest.php:15 ERRORS! Tests: 2, Assertions: 1, Errors: 1.
assertArraySubset
メソッドが~~と書かれていますが、ご覧の通り、上記テストコード内ではそのメソッドを使っておりません……
しかもなぜか、testIndex
メソッドでコケて、ほぼ同じコードのtestTop
メソッドではコケていないという謎現象も…
以下の記事を見つけました。
https://laracasts.com/discuss/channels/testing/assertstatus-giving-errors
「古いものを使っているのではないか」とのことだったので、
「composer update」を叩いてみましたが、特に落ちてくることはなく……
以上試してみたのですが、自分ではお手上げで……
解決策をご存じの方がいらっしゃいましたら、ご教示いただけますと幸いです。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/31 15:17