113 lines
3.5 KiB
PHP
113 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Directories\EloquentEmployeeDirectory;
|
|
use App\Models\Employee;
|
|
use Carbon\CarbonImmutable;
|
|
use Domain\Models\ValueObjects\Code;
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
|
|
describe('EloquentEmployeeDirectory', function () {
|
|
it('finds an employee by id', function () {
|
|
// GIVEN
|
|
$directory = new EloquentEmployeeDirectory();
|
|
$employee = Employee::forceCreate([
|
|
'id' => 100,
|
|
'customer_id' => null,
|
|
'matricule' => new Matricule('1000100'),
|
|
'code' => new Code('C1111115'),
|
|
'nom' => 'Doe',
|
|
'prenom' => 'John',
|
|
'etablissement' => 'E',
|
|
'site' => 'S',
|
|
'service' => 'S',
|
|
'created_at' => CarbonImmutable::now(),
|
|
'updated_at' => CarbonImmutable::now(),
|
|
]);
|
|
|
|
// WHEN
|
|
$result = $directory->find(100);
|
|
|
|
// THEN
|
|
expect($result)->not->toBeNull();
|
|
expect($result->id)->toBe($employee->id);
|
|
});
|
|
|
|
it('returns null if employee not found', function () {
|
|
// GIVEN
|
|
$directory = new EloquentEmployeeDirectory();
|
|
|
|
// WHEN
|
|
$result = $directory->find(9999);
|
|
|
|
// THEN
|
|
expect($result)->toBeNull();
|
|
});
|
|
|
|
it('gets the number of salaries in date range', function () {
|
|
// GIVEN
|
|
$directory = new EloquentEmployeeDirectory();
|
|
|
|
Employee::forceCreate([
|
|
'id' => 101,
|
|
'customer_id' => null,
|
|
'matricule' => new Matricule('1000101'),
|
|
'code' => new Code('C1111116'),
|
|
'nom' => 'Doe',
|
|
'prenom' => 'John',
|
|
'etablissement' => 'E',
|
|
'site' => 'S',
|
|
'service' => 'S',
|
|
'created_at' => CarbonImmutable::now()->subDays(5),
|
|
'updated_at' => CarbonImmutable::now()->subDays(5),
|
|
]);
|
|
|
|
Employee::forceCreate([
|
|
'id' => 102,
|
|
'customer_id' => null,
|
|
'matricule' => new Matricule('1000102'),
|
|
'code' => new Code('C1111117'),
|
|
'nom' => 'Doe',
|
|
'prenom' => 'John',
|
|
'etablissement' => 'E',
|
|
'site' => 'S',
|
|
'service' => 'S',
|
|
'created_at' => CarbonImmutable::now()->subDays(15),
|
|
'updated_at' => CarbonImmutable::now()->subDays(15),
|
|
]);
|
|
|
|
// WHEN
|
|
$start = CarbonImmutable::now()->subDays(10);
|
|
$end = CarbonImmutable::now();
|
|
$count = $directory->getNbSalarie($start, $end);
|
|
|
|
// THEN
|
|
expect($count)->toBeGreaterThanOrEqual(1);
|
|
});
|
|
|
|
it('gets total employees', function () {
|
|
// GIVEN
|
|
$directory = new EloquentEmployeeDirectory();
|
|
|
|
Employee::forceCreate([
|
|
'id' => 103,
|
|
'customer_id' => null,
|
|
'matricule' => new Matricule('1000103'),
|
|
'code' => new Code('C1111118'),
|
|
'nom' => 'Doe',
|
|
'prenom' => 'John',
|
|
'etablissement' => 'E',
|
|
'site' => 'S',
|
|
'service' => 'S',
|
|
'created_at' => CarbonImmutable::now(),
|
|
'updated_at' => CarbonImmutable::now(),
|
|
]);
|
|
|
|
// WHEN
|
|
$count = $directory->getTotalEmployees();
|
|
|
|
// THEN
|
|
expect($count)->toBeGreaterThanOrEqual(1);
|
|
});
|
|
});
|