Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Tests\Unit\Services;
use App\Models\Department;
use App\Models\Taxe;
use App\Services\TaxeStatService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class TaxeStatServiceTest extends TestCase
{
use RefreshDatabase;
private TaxeStatService $service;
protected function setUp(): void
{
parent::setUp();
$this->service = new TaxeStatService();
}
public function test_calculate_sum_returns_correct_value(): void
{
$dept = Department::create(['department_code' => '76', 'department_name' => 'Seine-Maritime', 'region_name' => 'Normandie']);
Taxe::factory()->create([
'department_id' => $dept->id,
'tfpnb_amount' => 1000,
'year' => 2022
]);
Taxe::factory()->create([
'department_id' => $dept->id,
'tfpnb_amount' => 2000,
'year' => 2022
]);
$sum = $this->service->calculateSum(Taxe::FIELD_TFPNB, null, 2022);
$this->assertEquals(3000, $sum);
}
public function test_validate_field_throws_exception_for_invalid_field(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->service->calculateSum('invalid_field');
}
}