feat: ajout des commentaires à la semaine (#15)
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [x] Pas de régression - [ ] TU/TI/TF rédigée - [x] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #15 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #15.
This commit is contained in:
76
tests/State/EmployeeWeekCommentWriteProcessorTest.php
Normal file
76
tests/State/EmployeeWeekCommentWriteProcessorTest.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\State;
|
||||
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Entity\Employee;
|
||||
use App\Entity\EmployeeWeekComment;
|
||||
use App\Service\AuditLogger;
|
||||
use App\State\EmployeeWeekCommentWriteProcessor;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\UnitOfWork;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class EmployeeWeekCommentWriteProcessorTest extends TestCase
|
||||
{
|
||||
public function testRejectsNonMondayWeekStart(): void
|
||||
{
|
||||
$processor = new EmployeeWeekCommentWriteProcessor(
|
||||
$this->createStub(ProcessorInterface::class),
|
||||
$this->createStub(ProcessorInterface::class),
|
||||
$this->createStub(EntityManagerInterface::class),
|
||||
$this->createStub(AuditLogger::class),
|
||||
);
|
||||
|
||||
$comment = new EmployeeWeekComment()
|
||||
->setEmployee(new Employee()->setFirstName('A')->setLastName('B'))
|
||||
->setWeekStartDate(new DateTimeImmutable('2026-04-14'))
|
||||
->setContent('test')
|
||||
;
|
||||
|
||||
$this->expectException(UnprocessableEntityHttpException::class);
|
||||
$processor->process($comment, new Post());
|
||||
}
|
||||
|
||||
public function testAcceptsMondayAndAuditsCreate(): void
|
||||
{
|
||||
$persist = $this->createMock(ProcessorInterface::class);
|
||||
$persist->expects(self::once())->method('process');
|
||||
$em = $this->createMock(EntityManagerInterface::class);
|
||||
$em->method('getUnitOfWork')->willReturn($this->createStub(UnitOfWork::class));
|
||||
$em->expects(self::once())->method('flush');
|
||||
$auditor = $this->createMock(AuditLogger::class);
|
||||
$auditor->expects(self::once())->method('log')->with(self::anything(), 'create', 'week_comment');
|
||||
|
||||
$processor = new EmployeeWeekCommentWriteProcessor($persist, $this->createStub(ProcessorInterface::class), $em, $auditor);
|
||||
$processor->process(
|
||||
new EmployeeWeekComment()->setEmployee(new Employee()->setFirstName('A')->setLastName('B'))->setWeekStartDate(new DateTimeImmutable('2026-04-13'))->setContent('x'),
|
||||
new Post()
|
||||
);
|
||||
}
|
||||
|
||||
public function testDeleteAudits(): void
|
||||
{
|
||||
$remove = $this->createMock(ProcessorInterface::class);
|
||||
$remove->expects(self::once())->method('process');
|
||||
$em = $this->createMock(EntityManagerInterface::class);
|
||||
$em->expects(self::once())->method('flush');
|
||||
$auditor = $this->createMock(AuditLogger::class);
|
||||
$auditor->expects(self::once())->method('log')->with(self::anything(), 'delete', 'week_comment');
|
||||
|
||||
$processor = new EmployeeWeekCommentWriteProcessor($this->createStub(ProcessorInterface::class), $remove, $em, $auditor);
|
||||
$processor->process(
|
||||
new EmployeeWeekComment()->setEmployee(new Employee()->setFirstName('A')->setLastName('B'))->setWeekStartDate(new DateTimeImmutable('2026-04-13'))->setContent('x'),
|
||||
new Delete()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ use App\Enum\HalfDay;
|
||||
use App\Repository\Contract\AbsenceReadRepositoryInterface;
|
||||
use App\Repository\Contract\EmployeeScopedRepositoryInterface;
|
||||
use App\Repository\Contract\WorkHourReadRepositoryInterface;
|
||||
use App\Repository\EmployeeWeekCommentRepository;
|
||||
use App\Service\Contracts\EmployeeContractResolver;
|
||||
use App\Service\PublicHolidayServiceInterface;
|
||||
use App\Service\WorkHours\AbsenceSegmentsResolver;
|
||||
@@ -67,6 +68,7 @@ final class WorkHourWeeklySummaryProviderTest extends TestCase
|
||||
new DailyReferenceMinutesResolver(),
|
||||
$this->buildHolidayResolver(),
|
||||
$this->buildHolidayService(),
|
||||
$this->buildWeekCommentRepoStub(),
|
||||
);
|
||||
|
||||
$this->expectException(AccessDeniedHttpException::class);
|
||||
@@ -130,6 +132,7 @@ final class WorkHourWeeklySummaryProviderTest extends TestCase
|
||||
new DailyReferenceMinutesResolver(),
|
||||
$this->buildHolidayResolver(),
|
||||
$this->buildHolidayService(),
|
||||
$this->buildWeekCommentRepoStub(),
|
||||
);
|
||||
|
||||
$result = $provider->provide(new Get());
|
||||
@@ -180,6 +183,14 @@ final class WorkHourWeeklySummaryProviderTest extends TestCase
|
||||
$property->setValue($entity, $id);
|
||||
}
|
||||
|
||||
private function buildWeekCommentRepoStub(): EmployeeWeekCommentRepository
|
||||
{
|
||||
$r = $this->createStub(EmployeeWeekCommentRepository::class);
|
||||
$r->method('findByWeekAndEmployees')->willReturn([]);
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
private function buildHolidayResolver(array $holidayMap = []): HolidayVirtualHoursResolver
|
||||
{
|
||||
return new HolidayVirtualHoursResolver(
|
||||
|
||||
Reference in New Issue
Block a user