|
|
@@ -1,47 +1,37 @@
|
|
|
-<?php
|
|
|
+<?php /** @noinspection PhpUnhandledExceptionInspection */
|
|
|
+
|
|
|
namespace App\Tests\Service\Network;
|
|
|
|
|
|
use App\Entity\Network\Network;
|
|
|
use App\Entity\Network\NetworkOrganization;
|
|
|
use App\Entity\Organization\Organization;
|
|
|
use App\Enum\Network\NetworkEnum;
|
|
|
+use DateTime;
|
|
|
+use Doctrine\Common\Collections\ArrayCollection;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
-use App\Service\Network\Utils;
|
|
|
+use App\Service\Network\Utils as NetworkUtils;
|
|
|
|
|
|
class UtilsTest extends TestCase
|
|
|
{
|
|
|
- private Utils $utils;
|
|
|
- private Organization $organizationCmf;
|
|
|
- private Organization $organizationFfec;
|
|
|
-
|
|
|
- public function setUp():void
|
|
|
- {
|
|
|
- $networkCmf = new Network();
|
|
|
- $networkCmf->setId(3);
|
|
|
- $networkCmf->setName('CMF');
|
|
|
- $networkOrganization = new NetworkOrganization();
|
|
|
- $networkOrganization->setNetwork($networkCmf);
|
|
|
- $networkOrganization->setStartDate(new \DateTime('2000-09-11'));
|
|
|
- $this->organizationCmf = new Organization();
|
|
|
- $this->organizationCmf->addNetworkOrganization($networkOrganization);
|
|
|
-
|
|
|
- $networkFfec = new Network();
|
|
|
- $networkFfec->setId(4);
|
|
|
- $networkFfec->setName('FFEC');
|
|
|
- $networkOrganization = new NetworkOrganization();
|
|
|
- $networkOrganization->setNetwork($networkFfec);
|
|
|
- $this->organizationFfec = new Organization();
|
|
|
- $this->organizationFfec->addNetworkOrganization($networkOrganization);
|
|
|
-
|
|
|
- $this->utils = new Utils();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* @see Utils::isCMF()
|
|
|
*/
|
|
|
public function testIsCmf():void
|
|
|
{
|
|
|
- $result = $this->utils->isCmf($this->organizationCmf);
|
|
|
+ $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);
|
|
|
}
|
|
|
|
|
|
@@ -50,53 +40,212 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testIsNotCmf():void
|
|
|
{
|
|
|
- $result = $this->utils->isCmf($this->organizationFfec);
|
|
|
+ $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::isCMFAndActiveNow()
|
|
|
+ * @see Utils::isCMF()
|
|
|
*/
|
|
|
public function testIsCmfAndActiveNow():void
|
|
|
{
|
|
|
- $result = $this->utils->isCMFAndActiveNow($this->organizationCmf);
|
|
|
- $this->assertTrue($result);
|
|
|
+ $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::isCMFAndActiveNow()
|
|
|
+ * @see Utils::doesOrganizationBelongToTheNetwork()
|
|
|
*/
|
|
|
- public function testIsCmfAndNotActiveNow():void
|
|
|
+ public function testDoesOrganizationBelongToTheNetwork():void
|
|
|
{
|
|
|
- $networkCmf = new Network();
|
|
|
- $networkCmf->setId(3);
|
|
|
- $networkCmf->setName('CMF');
|
|
|
- $networkOrganization = new NetworkOrganization();
|
|
|
- $networkOrganization->setNetwork($networkCmf);
|
|
|
- $networkOrganization->setStartDate(new \DateTime('2000-09-11'));
|
|
|
- $networkOrganization->setEndDate(new \DateTime('2020-09-11'));
|
|
|
- $organizationCmfNotActive = new Organization();
|
|
|
- $organizationCmfNotActive->addNetworkOrganization($networkOrganization);
|
|
|
-
|
|
|
- $result = $this->utils->isCMFAndActiveNow($organizationCmfNotActive);
|
|
|
- $this->assertFalse($result);
|
|
|
+ $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::isOrganizationBelongToTheNetwork()
|
|
|
+ * @see Utils::doesOrganizationBelongToTheNetwork()
|
|
|
*/
|
|
|
- public function testIsOrganizationBelongToTheNetwork():void
|
|
|
+ public function testDoesOrganizationBelongToTheNetworkAndActive():void
|
|
|
{
|
|
|
- $result = $this->utils->isOrganizationBelongToTheNetwork($this->organizationCmf, NetworkEnum::CMF());
|
|
|
+ $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::isOrganizationBelongToTheNetwork()
|
|
|
+ * @see Utils::doesOrganizationBelongToTheNetwork()
|
|
|
*/
|
|
|
- public function testIsOrganizationNotBelongToTheNetwork():void
|
|
|
+ public function testDoesOrganizationBelongToTheNetworkFalse():void
|
|
|
{
|
|
|
- $result = $this->utils->isOrganizationBelongToTheNetwork($this->organizationCmf, NetworkEnum::FFEC());
|
|
|
+ $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::doesOrganizationBelongToTheNetwork()
|
|
|
+ */
|
|
|
+ public function testIsOrganizationActiveNow():void
|
|
|
+ {
|
|
|
+ $networkUtils = $this
|
|
|
+ ->getMockBuilder(NetworkUtils::class)
|
|
|
+ ->setMethodsExcept(['isNetworkOrganizationActiveNow'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $date1 = new DateTime('now');
|
|
|
+ $date1->modify('-1 year');
|
|
|
+
|
|
|
+ $date2 = new DateTime('now');
|
|
|
+ $date2->modify('+1 year');
|
|
|
+
|
|
|
+ $networkOrganization = $this->getMockBuilder(NetworkOrganization::class)->getMock();
|
|
|
+ $networkOrganization
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('getStartDate')
|
|
|
+ ->willReturn($date1);
|
|
|
+
|
|
|
+ $networkOrganization
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('getEndDate')
|
|
|
+ ->willReturn($date2);
|
|
|
+
|
|
|
+ $this->assertTrue(
|
|
|
+ $networkUtils->isNetworkOrganizationActiveNow($networkOrganization)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see Utils::doesOrganizationBelongToTheNetwork()
|
|
|
+ */
|
|
|
+ public function testIsOrganizationActiveNowNotActive():void
|
|
|
+ {
|
|
|
+ $networkUtils = $this
|
|
|
+ ->getMockBuilder(NetworkUtils::class)
|
|
|
+ ->setMethodsExcept(['isNetworkOrganizationActiveNow'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $date1 = new DateTime('now');
|
|
|
+ $date1->modify('-3 year');
|
|
|
+
|
|
|
+ $date2 = new DateTime('now');
|
|
|
+ $date2->modify('-1 year');
|
|
|
+
|
|
|
+ $networkOrganization = $this->getMockBuilder(NetworkOrganization::class)->getMock();
|
|
|
+ $networkOrganization
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('getStartDate')
|
|
|
+ ->willReturn($date1);
|
|
|
+
|
|
|
+ $networkOrganization
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('getEndDate')
|
|
|
+ ->willReturn($date2);
|
|
|
+
|
|
|
+ $this->assertFalse(
|
|
|
+ $networkUtils->isNetworkOrganizationActiveNow($networkOrganization)
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|