Adjust unit tests for Earning and Spending models to use factories
MODIFY
tests/Unit/EarningTest.php
tests/Unit/EarningTest.php
@@ -10,14 +10,9 @@ use App\Earning;
class EarningTest extends TestCase {
public function testFormattedAmount() {
- $earning = new Earning;
-
- $earning->user_id = 1;
- $earning->happened_on = date('Y-m-d');
- $earning->description = 'EarningTest testFormattedAmount';
- $earning->amount = 39;
-
- $earning->save();
+ $earning = factory(Earning::class)->make([
+ 'amount' => (int) ('39' * 100)
+ ]);
$this->assertEquals('39.00', $earning->formatted_amount);
}

MODIFY
tests/Unit/SpendingTest.php
tests/Unit/SpendingTest.php
@@ -10,16 +10,10 @@ use App\Spending;
class SpendingTest extends TestCase {
public function testFormattedAmount() {
- $spending = new Spending;
+ $spending = factory(Spending::class)->make([
+ 'amount' => (int) ('92.35' * 100)
+ ]);
- $spending->user_id = 1;
- // $spending->tag_id = null;
- $spending->happened_on = date('Y-m-d');
- $spending->description = 'SpendingTest testFormattedAmount';
- $spending->amount = 92;
-
- $spending->save();
-
- $this->assertEquals('92.00', $spending->formatted_amount);
+ $this->assertEquals('92.35', $spending->formatted_amount);
}
}

Adjust unit tests for Earning and Spending models to use factories