| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- declare(strict_types=1);
- namespace App\Tests\Unit\Service\Organization;
- use App\Service\Organization\Trial;
- use App\Service\Utils\DatesUtils;
- use PHPUnit\Framework\TestCase;
- /**
- * Unit tests for Trial class
- * @see Trial
- */
- class TrialTest extends TestCase
- {
- private DatesUtils $datesUtils;
- private Trial $trial;
- public function setUp(): void
- {
- $this->datesUtils = new DatesUtils();
- $this->trial = new Trial($this->datesUtils);
- }
- public function tearDown(): void
- {
- DatesUtils::clearFakeDatetime();
- }
- /**
- * @see Trial::getTrialCountdown()
- */
- public function testGetTrialCountdownWithNullStartDate(): void
- {
- $result = $this->trial->getTrialCountdown(null);
- $this->assertEquals(0, $result);
- }
- /**
- * @see Trial::getTrialCountdown()
- */
- public function testGetTrialCountdownWithRecentStartDate(): void
- {
- // Set up a trial start date
- $trialStartDate = new \DateTime('2023-01-01');
- // Set the current date to be 10 days after the trial start date
- DatesUtils::setFakeDatetime('2023-01-11');
- $result = $this->trial->getTrialCountdown($trialStartDate);
- // Should return 30 - 10 = 20 days remaining
- $this->assertEquals(20, $result);
- }
- /**
- * @see Trial::getTrialCountdown()
- */
- public function testGetTrialCountdownWithExactly30DaysAgo(): void
- {
- // Set up a trial start date
- $trialStartDate = new \DateTime('2023-01-01');
- // Set the current date to be 30 days after the trial start date
- DatesUtils::setFakeDatetime('2023-01-31');
- $result = $this->trial->getTrialCountdown($trialStartDate);
- // Should return 30 - 30 = 0 days remaining
- $this->assertEquals(0, $result);
- }
- /**
- * @see Trial::getTrialCountdown()
- */
- public function testGetTrialCountdownWithOldStartDate(): void
- {
- // Set up a trial start date
- $trialStartDate = new \DateTime('2023-01-01');
- // Set the current date to be 40 days after the trial start date
- DatesUtils::setFakeDatetime('2023-02-10');
- $result = $this->trial->getTrialCountdown($trialStartDate);
- // Should return 0 days remaining since the trial has expired
- $this->assertEquals(0, $result);
- }
- }
|