route
Route::get('/admin/test/form', [App\Http\Controllers\AdminController::class, 'testForm']);
controller
public function testForm(){ return view('admin.test'); }
testCase
public function testExample() { $this->visit('/admin/test/form')->see('名前'); }
$ vendor/bin/phpunit tests/Feature/AdminTest.php
PHPUnit 9.4.2 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 00:01.715, Memory: 32.00 MB
There was 1 error:
1) Tests\Feature\AdminTest::testExample
Error: Call to undefined method Tests\Feature\AdminTest::visit()
/home/vagrant/dev/testApp/tests/Feature/AdminTest.php:26
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
ん? visitを使うにはduskを入れないと駄目らしい。
と言うことで、公式を見ます。
https://laravel.com/docs/8.x/dusk
$ composer require –dev laravel/dusk
$ php artisan dusk:install
$ php artisan dusk:chrome-driver
1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\UnknownErrorException: unknown error: cannot find Chrome binary
/home/vagrant/dev/testApp/vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:139
/home/vagrant/dev/testApp/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:371
/home/vagrant/dev/testApp/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:136
/home/vagrant/dev/testApp/tests/DuskTestCase.php:43
/home/vagrant/dev/testApp/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:218
/home/vagrant/dev/testApp/vendor/laravel/framework/src/Illuminate/Support/helpers.php:234
/home/vagrant/dev/testApp/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:219
/home/vagrant/dev/testApp/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:97
/home/vagrant/dev/testApp/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:65
/home/vagrant/dev/testApp/tests/Browser/ExampleTest.php:22
うーん、なんでやろ。。ちょっとよくわからんな。