-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #425 from range-of-motion/424-use-upgraded-definit…
…ion-of-accessors-in-models Use upgraded definition of accessors in models
- Loading branch information
Showing
16 changed files
with
265 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Models; | ||
|
||
use App\Models\Budget; | ||
use App\Models\Space; | ||
use App\Models\Spending; | ||
use App\Models\Tag; | ||
use Tests\TestCase; | ||
|
||
class BudgetTest extends TestCase | ||
{ | ||
public function testFormattedAmountAttribute(): void | ||
{ | ||
$budget = Budget::factory() | ||
->create(['amount' => 750]); | ||
|
||
$this->assertEquals('7.50', $budget->formatted_amount); | ||
} | ||
|
||
public function testSpentAttribute(): void | ||
{ | ||
$space = Space::factory() | ||
->create(); | ||
|
||
$tag = Tag::factory() | ||
->create([ | ||
'space_id' => $space->id, | ||
]); | ||
|
||
$budget = Budget::factory() | ||
->create([ | ||
'tag_id' => $tag->id, | ||
'period' => 'monthly', | ||
'amount' => 750, | ||
]); | ||
|
||
Spending::factory() | ||
->create([ | ||
'space_id' => $space->id, | ||
'tag_id' => $tag->id, | ||
'happened_on' => date('Y-m-d'), | ||
'amount' => 100, | ||
]); | ||
|
||
// Set session accordingly | ||
$this->withSession(['space_id' => $space->id]); | ||
|
||
$this->assertEquals(100, $budget->spent); | ||
} | ||
|
||
public function testFormattedSpentAttribute(): void | ||
{ | ||
$space = Space::factory() | ||
->create(); | ||
|
||
$tag = Tag::factory() | ||
->create([ | ||
'space_id' => $space->id, | ||
]); | ||
|
||
$budget = Budget::factory() | ||
->create([ | ||
'tag_id' => $tag->id, | ||
'period' => 'monthly', | ||
'amount' => 750, | ||
]); | ||
|
||
Spending::factory() | ||
->create([ | ||
'space_id' => $space->id, | ||
'tag_id' => $tag->id, | ||
'happened_on' => date('Y-m-d'), | ||
'amount' => 100, | ||
]); | ||
|
||
// Set session accordingly | ||
$this->withSession(['space_id' => $space->id]); | ||
|
||
$this->assertEquals('1.00', $budget->formatted_spent); | ||
} | ||
} |
Oops, something went wrong.