Skip to content

Instantly share code, notes, and snippets.

@devmsh
Created February 16, 2020 19:49
Show Gist options
  • Select an option

  • Save devmsh/6376b4e6c030b3a9e0816ea2cb696b3e to your computer and use it in GitHub Desktop.

Select an option

Save devmsh/6376b4e6c030b3a9e0816ea2cb696b3e to your computer and use it in GitHub Desktop.
Write better Laravel tests
<?php
class LoanTest extends TestCase{
public function test_can_log_a_loan()
{
$user = factory(User::class)->create();
$wallet = factory(Wallet::class)->create([
'user_id' => $user->id
]);
$this->passportAs($user)
->post('api/loans', [
'total' => 1000,
'payoff_at' => Carbon::today()->addYear(),
'wallet_id' => $wallet->id,
])
->assertSuccessful()
->assertJson([
'id' => 1,
'total' => 1000,
'payoff_at' => Carbon::today()->addYear(),
'user_id' => $user->id,
]);
/** @var Transaction $transaction */
// ..
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment