– laravel 6系ではmake:authが無くなりました
$ php artisan –version
Laravel Framework 6.9.0
– unit test -> feature testの順番
$ php artisan make:test BookCheckoutTest
use RefreshDatabase; public function test_a_book_can_be_check_out(){ $this->withoutExceptionHandling(); $book = factory(Book::class)->create(); $this->actingAs($user = Factory(User::class)->create()) ->post('/checkout/' . $book->id); $this->assertCount(1, Reservation::all()); $this->assertEquals($user->id, Reservation::first()->user_id); $this->assertEquals($book->id, Reservation::first()->book_id); $this->assertEquals(now(), Reservation::first()->checked_out_at); }
route
Route::post('/checkout/{book}', 'CheckoutBookController@store');
$ php artisan make:controller CheckoutBookController
public function __construct(){ $this->middleware('auth'); } public function store(Book $book){ $book->checkout(auth()->user()); }
$ phpunit –filter test_a_book_can_be_check_out
OK (1 test, 4 assertions)
$ php artisan make:auth
Command “make:auth” is not defined.
### make:auth
$ composer require laravel/ui –dev
$ php artisan ui vue –auth
$ php artisan migrate:refresh
$ npm install
$ phpunit –filter test_only_signed_in_users_can_be_checkout_book
OK (1 test, 3 assertions)
$ php artisan make:controller CheckinBookController
public function __construct(){ $this->middleware('auth'); } public function store(Book $book){ $book->checkin(auth()->user()); }
public function test_404_is_thrown_if_a_book_is_not_checked_out(){ $book = factory(Book::class)->create(); $user = factory(User::class)->create(); $this->actingAs($user) ->post('/checkin/' . $book->id) ->assertStatus(404); $this->assertCount(0, Reservation::all()); }
public function __construct(){ $this->middleware('auth'); } public function store(Book $book){ try { $book->checkin(auth()->user()); } catch(\Exception $e){ return response([], 404); } }
make:authがvueのコンポーネントになったということは、LaravelはReactよりvueを支持しているってこと?フロントエンドは確実にvue.jsが必須になってきました。
それと、テストエンジニアってなんか敬遠されがちだが、そもそもtestはフレームワークの仕組みを深く理解してないとできないから、テストエンジニアを下に見るのは偏見がかなり入っている