Skip to content

Instantly share code, notes, and snippets.

@devmsh
Created February 16, 2020 20:22
Show Gist options
  • Save devmsh/8761c360eeac8f4f15a42f6445ecad1a to your computer and use it in GitHub Desktop.
Save devmsh/8761c360eeac8f4f15a42f6445ecad1a to your computer and use it in GitHub Desktop.
Write better Laravel tests
<?php
class LoanTest extends TestCase
{
public function test_loan_generate_corresponding_transaction()
{
$wallet = factory(Wallet::class)->create();
$loan = Loan::log(factory(Loan::class)->make([
'wallet_id' => $wallet->id
])->toArray());
$transaction = $loan->transaction;
$this->assertEquals($loan->id, $transaction->causedby->id);
$this->assertEquals($loan->total, $transaction->amount);
$this->assertEquals($loan->user_id, $transaction->user_id);
}
public function test_loan_generate_corresponding_goal()
{
$wallet = factory(Wallet::class)->create();
$loan = Loan::log(factory(Loan::class)->make([
'wallet_id' => $wallet->id
])->toArray());
$goal = $loan->goal;
$this->assertEquals($loan->total, $goal->total);
$this->assertEquals($loan->user_id, $goal->user_id);
$this->assertEquals($loan->payoff_at, $goal->due_date);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment