| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Tests\Service\Cotisation;
- use App\Entity\Organization\Organization;
- 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('foo');
- $cotisation = $cotisationCreator->getCotisation(1);
- $this->assertEquals(1, $cotisation->getOrganizationId());
- $this->assertEquals(2000, $cotisation->getCotisationYear());
- $this->assertEquals('foo', $cotisation->getAlertState());
- }
- }
|