CotisationCreatorTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. public function testGetCotisation() {
  19. $cotisationCreator = $this->getMockBuilder(CotisationCreator::class)
  20. ->setConstructorArgs([$this->organizationRepository, $this->cotisationUtils])
  21. ->setMethodsExcept(['getCotisation'])
  22. ->getMock();
  23. $this->cotisationUtils->expects(self::once())->method('getCurrentCotisationYear')->willReturn(2000);
  24. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  25. $this->organizationRepository->expects(self::once())->method('find')->willReturn($organization);
  26. $this->cotisationUtils->expects(self::once())->method('getAlertState')->with($organization, 2000)->willReturn('foo');
  27. $cotisation = $cotisationCreator->getCotisation(1);
  28. $this->assertEquals(1, $cotisation->getOrganizationId());
  29. $this->assertEquals(2000, $cotisation->getCotisationYear());
  30. $this->assertEquals('foo', $cotisation->getAlertState());
  31. }
  32. }