| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- namespace App\Tests\Unit\Service\Network;
- use App\Entity\Network\Network;
- use App\Entity\Network\NetworkOrganization;
- use App\Entity\Organization\Organization;
- use App\Enum\Network\NetworkEnum;
- use App\Service\Network\Utils as NetworkUtils;
- use DateTime;
- use Doctrine\Common\Collections\ArrayCollection;
- use PHPUnit\Framework\TestCase;
- use App\Service\Utils\DatesUtils;
- class UtilsTest extends TestCase
- {
- /**
- * @see Utils::isCMF()
- */
- public function testIsCmf():void
- {
- $networkUtils = $this
- ->getMockBuilder(NetworkUtils::class)
- ->setMethodsExcept(['isCMF'])
- ->getMock();
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $networkUtils
- ->expects(self::once())
- ->method('doesOrganizationBelongToTheNetwork')
- ->with($organization, NetworkEnum::CMF())
- ->willReturn(true);
- $result = $networkUtils->isCmf($organization);
- $this->assertTrue($result);
- }
- /**
- * @see Utils::isCMF()
- */
- public function testIsNotCmf():void
- {
- $networkUtils = $this
- ->getMockBuilder(NetworkUtils::class)
- ->setMethodsExcept(['isCMF'])
- ->getMock();
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $networkUtils
- ->expects(self::once())
- ->method('doesOrganizationBelongToTheNetwork')
- ->with($organization, NetworkEnum::CMF())
- ->willReturn(false);
- $result = $networkUtils->isCmf($organization);
- $this->assertFalse($result);
- }
- /**
- * @see Utils::isCMF()
- */
- public function testIsCmfAndActiveNow():void
- {
- $networkUtils = $this
- ->getMockBuilder(NetworkUtils::class)
- ->setMethodsExcept(['isCMFAndActiveNow'])
- ->getMock();
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $networkUtils
- ->expects(self::once())
- ->method('doesOrganizationBelongToTheNetwork')
- ->with($organization, NetworkEnum::CMF(), true)
- ->willReturn(false);
- $result = $networkUtils->isCMFAndActiveNow($organization);
- $this->assertFalse($result);
- }
- /**
- * @see Utils::doesOrganizationBelongToTheNetwork()
- */
- public function testDoesOrganizationBelongToTheNetwork():void
- {
- $networkUtils = $this
- ->getMockBuilder(NetworkUtils::class)
- ->setMethodsExcept(['doesOrganizationBelongToTheNetwork'])
- ->getMock();
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $network1 = $this->getMockBuilder(Network::class)->getMock();
- $network1->method('getId')->willReturn(NetworkEnum::CMF()->getValue());
- $networkOrganization1 = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization1->method('getNetwork')->willReturn($network1);
- $network2 = $this->getMockBuilder(Network::class)->getMock();
- $network2->method('getId')->willReturn(NetworkEnum::FFEC()->getValue());
- $networkOrganization2 = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization2->method('getNetwork')->willReturn($network2);
- $organization
- ->expects(self::once())
- ->method('getNetworkOrganizations')
- ->willReturn(new ArrayCollection([$networkOrganization1, $networkOrganization2]));
- $networkUtils->expects(self::never())->method('isNetworkOrganizationActiveNow');
- $result = $networkUtils->doesOrganizationBelongToTheNetwork($organization, NetworkEnum::FFEC());
- $this->assertTrue($result);
- }
- /**
- * @see Utils::doesOrganizationBelongToTheNetwork()
- */
- public function testDoesOrganizationBelongToTheNetworkAndActive():void
- {
- $networkUtils = $this
- ->getMockBuilder(NetworkUtils::class)
- ->setMethodsExcept(['doesOrganizationBelongToTheNetwork'])
- ->getMock();
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $network1 = $this->getMockBuilder(Network::class)->getMock();
- $network1->method('getId')->willReturn(NetworkEnum::CMF()->getValue());
- $networkOrganization1 = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization1->method('getNetwork')->willReturn($network1);
- $network2 = $this->getMockBuilder(Network::class)->getMock();
- $network2->method('getId')->willReturn(NetworkEnum::FFEC()->getValue());
- $networkOrganization2 = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization2->method('getNetwork')->willReturn($network2);
- $organization
- ->expects(self::once())
- ->method('getNetworkOrganizations')
- ->willReturn(new ArrayCollection([$networkOrganization1, $networkOrganization2]));
- $networkUtils->expects(self::once())->method('isNetworkOrganizationActiveNow')->with($networkOrganization2)->willReturn(true);
- $result = $networkUtils->doesOrganizationBelongToTheNetwork($organization, NetworkEnum::FFEC(), true);
- $this->assertTrue($result);
- }
- /**
- * @see Utils::doesOrganizationBelongToTheNetwork()
- */
- public function testDoesOrganizationBelongToTheNetworkFalse():void
- {
- $networkUtils = $this
- ->getMockBuilder(NetworkUtils::class)
- ->setMethodsExcept(['doesOrganizationBelongToTheNetwork'])
- ->getMock();
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $network1 = $this->getMockBuilder(Network::class)->getMock();
- $network1->method('getId')->willReturn(NetworkEnum::CMF()->getValue());
- $networkOrganization1 = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization1->method('getNetwork')->willReturn($network1);
- $network2 = $this->getMockBuilder(Network::class)->getMock();
- $network2->method('getId')->willReturn(NetworkEnum::FFEC()->getValue());
- $networkOrganization2 = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization2->method('getNetwork')->willReturn($network2);
- $organization
- ->expects(self::once())
- ->method('getNetworkOrganizations')
- ->willReturn(new ArrayCollection([$networkOrganization1, $networkOrganization2]));
- $networkUtils->expects(self::never())->method('isNetworkOrganizationActiveNow');
- $result = $networkUtils->doesOrganizationBelongToTheNetwork($organization, NetworkEnum::CFBF());
- $this->assertFalse($result);
- }
- /**
- * @see Utils::isNetworkOrganizationActiveNow()
- */
- public function testIsOrganizationActiveNow():void
- {
- $networkUtils = $this
- ->getMockBuilder(NetworkUtils::class)
- ->setMethodsExcept(['isNetworkOrganizationActiveNow'])
- ->getMock();
- DatesUtils::setFakeDatetime('2023-01-01');
- $dateNow = DatesUtils::new();
- $startDate = DatesUtils::new('2022-01-01');
- $endDate = DatesUtils::new('2024-01-01');
- $networkOrganization = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization
- ->expects(self::exactly(2))
- ->method('getStartDate')
- ->willReturn($startDate);
- $networkOrganization
- ->expects(self::once())
- ->method('getEndDate')
- ->willReturn($endDate);
- $this->assertTrue(
- $networkUtils->isNetworkOrganizationActiveNow($networkOrganization)
- );
- }
- /**
- * @see Utils::isNetworkOrganizationActiveNow()
- */
- public function testIsOrganizationActiveNowNotActive():void
- {
- $networkUtils = $this
- ->getMockBuilder(NetworkUtils::class)
- ->setMethodsExcept(['isNetworkOrganizationActiveNow'])
- ->getMock();
- DatesUtils::setFakeDatetime('2023-01-01');
- $dateNow = DatesUtils::new();
- $startDate = DatesUtils::new('2021-01-01');
- $endDate = DatesUtils::new('2022-01-01');
- $networkOrganization = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization
- ->expects(self::exactly(2))
- ->method('getStartDate')
- ->willReturn($startDate);
- $networkOrganization
- ->expects(self::once())
- ->method('getEndDate')
- ->willReturn($endDate);
- $this->assertFalse(
- $networkUtils->isNetworkOrganizationActiveNow($networkOrganization)
- );
- }
- }
|