‘Class Tests\TestCase not found’というエラーが出た。
autoloadが効いていないっぽい?
もくじ
環境
- Mac
- Docker
app/tests/ExampleTest.php
<?php use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; class ExampleTest extends TestCase { /** * A basic functional test example. * * @return void */ public function testBasicExample() { $this->assertTrue(true); } }
vendor/composer/autoload_classmap.php
<?php // autoload_classmap.php @generated by Composer $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( ・・・ 'TestCase' => $baseDir . '/tests/TestCase.php', 'Text_Template' => $vendorDir . '/phpunit/php-text-template/src/Template.php', 'TestCase' => $baseDir . '/app/tests/TestCase.php' ←●追加 );
これが必要なのかはわからないががが。消えるしな。
PHPが動いているコンテナに入る
$ docker exec -it web bash
# composer dump-autoload Generating autoload files Generated autoload files
# ./vendor/bin/phpunit PHPUnit 4.8.36 by Sebastian Bergmann and contributors. . Time: 5.86 seconds, Memory: 11.50MB OK (1 test, 1 assertion)