| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace App\Tests\Unit\Service\Cotisation;
- use App\Entity\Organization\Organization;
- use App\Enum\Cotisation\AlertStateEnum;
- use App\Repository\Organization\OrganizationRepository;
- use App\Service\Cotisation\CotisationCreator;
- use App\Service\Cotisation\Utils;
- use PHPUnit\Framework\MockObject\MockObject;
- use PHPUnit\Framework\TestCase;
- class CotisationCreatorTest extends TestCase
- {
- private MockObject|OrganizationRepository $organizationRepository;
- private MockObject|Utils $cotisationUtils;
- public function setUp(): void
- {
- $this->organizationRepository = $this->getMockBuilder(OrganizationRepository::class)->disableOriginalConstructor()->getMock();
- $this->cotisationUtils = $this->getMockBuilder(Utils::class)->disableOriginalConstructor()->getMock();
- }
- /**
- * @see CotisationCreator::getCotisation()
- */
- public function testGetCotisation(): void
- {
- $cotisationCreator = $this->getMockBuilder(CotisationCreator::class)
- ->setConstructorArgs([$this->organizationRepository, $this->cotisationUtils])
- ->setMethodsExcept(['getCotisation'])
- ->getMock();
- $this->cotisationUtils->expects(self::once())->method('getCurrentCotisationYear')->willReturn(2000);
- $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
- $this->organizationRepository->expects(self::once())->method('find')->willReturn($organization);
- $this->cotisationUtils->expects(self::once())->method('getAlertState')->with($organization, 2000)->willReturn(AlertStateEnum::ADVERTISINGINSURANCE);
- $cotisation = $cotisationCreator->getCotisation(1);
- $this->assertEquals(1, $cotisation->getOrganizationId());
- $this->assertEquals(2000, $cotisation->getCotisationYear());
- $this->assertEquals(AlertStateEnum::ADVERTISINGINSURANCE, $cotisation->getAlertState());
- }
- }
|