CotisationCreatorTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Tests\Service\Cotisation;
  3. use App\Entity\Organization\Organization;
  4. use App\Repository\Organization\OrganizationRepository;
  5. use App\Service\Cotisation\CotisationCreator;
  6. use App\Service\Cotisation\Utils;
  7. use PHPUnit\Framework\MockObject\MockObject;
  8. use PHPUnit\Framework\TestCase;
  9. class CotisationCreatorTest extends TestCase
  10. {
  11. private MockObject | OrganizationRepository $organizationRepository;
  12. private MockObject | Utils $cotisationUtils;
  13. public function setUp():void
  14. {
  15. $this->organizationRepository = $this->getMockBuilder(OrganizationRepository::class)->disableOriginalConstructor()->getMock();
  16. $this->cotisationUtils = $this->getMockBuilder(Utils::class)->disableOriginalConstructor()->getMock();
  17. }
  18. /**
  19. * @see CotisationCreator::getCotisation()
  20. */
  21. public function testGetCotisation(): void
  22. {
  23. $cotisationCreator = $this->getMockBuilder(CotisationCreator::class)
  24. ->setConstructorArgs([$this->organizationRepository, $this->cotisationUtils])
  25. ->setMethodsExcept(['getCotisation'])
  26. ->getMock();
  27. $this->cotisationUtils->expects(self::once())->method('getCurrentCotisationYear')->willReturn(2000);
  28. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  29. $this->organizationRepository->expects(self::once())->method('find')->willReturn($organization);
  30. $this->cotisationUtils->expects(self::once())->method('getAlertState')->with($organization, 2000)->willReturn('foo');
  31. $cotisation = $cotisationCreator->getCotisation(1);
  32. $this->assertEquals(1, $cotisation->getOrganizationId());
  33. $this->assertEquals(2000, $cotisation->getCotisationYear());
  34. $this->assertEquals('foo', $cotisation->getAlertState());
  35. }
  36. }