|
|
@@ -6,10 +6,13 @@ use App\Entity\Access\Access;
|
|
|
use App\Entity\Organization\Organization;
|
|
|
use App\Entity\Organization\Subdomain;
|
|
|
use App\Message\Command\Typo3\Typo3UpdateCommand;
|
|
|
+use App\Service\Access\Utils as AccessUtils;
|
|
|
use App\Service\MailHub;
|
|
|
use App\Service\OnChange\OnChangeContext;
|
|
|
use App\Service\OnChange\Organization\OnSubdomainChange;
|
|
|
+use App\Service\Organization\Utils as OrganizationUtils;
|
|
|
use App\Service\Typo3\BindFileService;
|
|
|
+use Doctrine\Common\Collections\ArrayCollection;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
use Symfony\Component\Messenger\Envelope;
|
|
|
@@ -17,30 +20,27 @@ use Symfony\Component\Messenger\MessageBusInterface;
|
|
|
|
|
|
class OnSubdomainChangeTest extends TestCase
|
|
|
{
|
|
|
- private \App\Service\Organization\Utils $organizationUtils;
|
|
|
- private \App\Service\Access\Utils $accessUtils;
|
|
|
+ private OrganizationUtils $organizationUtils;
|
|
|
+ private AccessUtils $accessUtils;
|
|
|
private MailHub $mailHub;
|
|
|
private BindFileService $bindFileService;
|
|
|
private MessageBusInterface $messageBus;
|
|
|
- private EntityManagerInterface $entityManager;
|
|
|
private OnSubdomainChange $onSubdomainChange;
|
|
|
|
|
|
public function setUp():void
|
|
|
{
|
|
|
- $this->organizationUtils = $this->getMockBuilder(\App\Service\Organization\Utils::class)->disableOriginalConstructor()->getMock();
|
|
|
- $this->accessUtils = $this->getMockBuilder(\App\Service\Access\Utils::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->organizationUtils = $this->getMockBuilder(OrganizationUtils::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->accessUtils = $this->getMockBuilder(AccessUtils::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->mailHub = $this->getMockBuilder(MailHub::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->bindFileService = $this->getMockBuilder(BindFileService::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->messageBus = $this->getMockBuilder(MessageBusInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
- $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
$this->onSubdomainChange = new OnSubdomainChange(
|
|
|
$this->organizationUtils,
|
|
|
$this->accessUtils,
|
|
|
$this->mailHub,
|
|
|
$this->bindFileService,
|
|
|
- $this->messageBus,
|
|
|
- $this->entityManager
|
|
|
+ $this->messageBus
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -50,7 +50,7 @@ class OnSubdomainChangeTest extends TestCase
|
|
|
$context->method('isPostRequest')->willReturn(true);
|
|
|
|
|
|
$organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
- $organization->expects(self::once())->method('getSubdomains')->willReturn(new \Doctrine\Common\Collections\ArrayCollection([1,2]));
|
|
|
+ $organization->expects(self::once())->method('getSubdomains')->willReturn(new ArrayCollection([1,2]));
|
|
|
|
|
|
$subdomain = $this->getMockBuilder(Subdomain::class)->disableOriginalConstructor()->getMock();
|
|
|
$subdomain->expects(self::once())->method('getOrganization')->willReturn($organization);
|
|
|
@@ -75,15 +75,40 @@ class OnSubdomainChangeTest extends TestCase
|
|
|
$context->method('isPostRequest')->willReturn(true);
|
|
|
|
|
|
$organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
- $organization->expects(self::once())->method('getSubdomains')->willReturn(new \Doctrine\Common\Collections\ArrayCollection([1,2,3]));
|
|
|
+ $organization->expects(self::once())->method('getSubdomains')->willReturn(new ArrayCollection([1,2,3]));
|
|
|
|
|
|
$subdomain = $this->getMockBuilder(Subdomain::class)->disableOriginalConstructor()->getMock();
|
|
|
$subdomain->expects(self::once())->method('getOrganization')->willReturn($organization);
|
|
|
|
|
|
- try {
|
|
|
- $this->onSubdomainChange->validate($subdomain, $context);
|
|
|
- throw new \AssertionError('A validation error should have been thrown');
|
|
|
- } catch (\RuntimeException) {}
|
|
|
+ $this->expectException(\RuntimeException::class);
|
|
|
+ $this->onSubdomainChange->validate($subdomain, $context);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testBeforeChangeActivated() {
|
|
|
+ // Le sous-domaine qu'on vient d'activer
|
|
|
+ $subdomain = $this->getMockBuilder(Subdomain::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $subdomain->method('isActive')->willReturn(true);
|
|
|
+
|
|
|
+ // Son état précédent
|
|
|
+ $previousData = $this->getMockBuilder(Subdomain::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $previousData->method('isActive')->willReturn(false);
|
|
|
+
|
|
|
+ // Le sous domaine qui était actif jusqu'ici, et que le OnChange devrait désactiver
|
|
|
+ $otherSubdomain = $this->getMockBuilder(Subdomain::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $otherSubdomain->method('isActive')->willReturn(true);
|
|
|
+ $otherSubdomain->expects(self::once())->method('setActive')->with(false);
|
|
|
+
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $organization->expects(self::once())->method('getSubdomains')->willReturn(new ArrayCollection([$subdomain, $otherSubdomain]));
|
|
|
+
|
|
|
+ $subdomain->method('getOrganization')->willReturn($organization);
|
|
|
+
|
|
|
+ $context = $this->getMockBuilder(OnChangeContext::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $context->method('previousData')->willReturn($previousData);
|
|
|
+ $context->method('isPutRequest')->willReturn(true);
|
|
|
+ $context->method('isPostRequest')->willReturn(false);
|
|
|
+
|
|
|
+ $this->onSubdomainChange->beforeChange($subdomain, $context);
|
|
|
}
|
|
|
|
|
|
public function testOnChangeNoChange(): void
|
|
|
@@ -95,7 +120,6 @@ class OnSubdomainChangeTest extends TestCase
|
|
|
->getMock();
|
|
|
|
|
|
$this->bindFileService->expects(self::never())->method('registerSubdomain');
|
|
|
- $this->entityManager->expects(self::never())->method('flush');
|
|
|
$this->messageBus->expects(self::never())->method('dispatch');
|
|
|
$onChange->expects(self::never())->method('sendEmailAfterSubdomainChange');
|
|
|
|
|
|
@@ -107,7 +131,6 @@ class OnSubdomainChangeTest extends TestCase
|
|
|
|
|
|
public function testOnChangeActivated(): void {
|
|
|
$this->bindFileService->expects(self::never())->method('registerSubdomain');
|
|
|
- $this->entityManager->expects(self::once())->method('flush');
|
|
|
$this->messageBus
|
|
|
->expects(self::once())
|
|
|
->method('dispatch')
|
|
|
@@ -118,7 +141,7 @@ class OnSubdomainChangeTest extends TestCase
|
|
|
->getMockBuilder(OnSubdomainChange::class)
|
|
|
->onlyMethods(['sendEmailAfterSubdomainChange'])
|
|
|
->setConstructorArgs(
|
|
|
- [$this->organizationUtils, $this->accessUtils, $this->mailHub, $this->bindFileService, $this->messageBus, $this->entityManager]
|
|
|
+ [$this->organizationUtils, $this->accessUtils, $this->mailHub, $this->bindFileService, $this->messageBus]
|
|
|
)
|
|
|
->getMock();
|
|
|
$onChange->expects(self::once())->method('sendEmailAfterSubdomainChange');
|
|
|
@@ -131,16 +154,10 @@ class OnSubdomainChangeTest extends TestCase
|
|
|
$previousData = $this->getMockBuilder(Subdomain::class)->disableOriginalConstructor()->getMock();
|
|
|
$previousData->method('isActive')->willReturn(false);
|
|
|
|
|
|
- // Le sous domaine qui était actif jusqu'ici, et que le OnChange devrait désactiver
|
|
|
- $otherSubdomain = $this->getMockBuilder(Subdomain::class)->disableOriginalConstructor()->getMock();
|
|
|
- $otherSubdomain->method('isActive')->willReturn(true);
|
|
|
- $otherSubdomain->expects(self::once())->method('setActive')->with(false);
|
|
|
-
|
|
|
$organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
$organization->method('getId')->willReturn(1);
|
|
|
- $organization->expects(self::once())->method('getSubdomains')->willReturn(new \Doctrine\Common\Collections\ArrayCollection([$subdomain, $otherSubdomain]));
|
|
|
|
|
|
- $subdomain->expects(self::exactly(2))->method('getOrganization')->willReturn($organization);
|
|
|
+ $subdomain->method('getOrganization')->willReturn($organization);
|
|
|
|
|
|
$context = $this->getMockBuilder(OnChangeContext::class)->disableOriginalConstructor()->getMock();
|
|
|
$context->method('previousData')->willReturn($previousData);
|
|
|
@@ -152,7 +169,6 @@ class OnSubdomainChangeTest extends TestCase
|
|
|
|
|
|
public function testOnChangeCreated(): void {
|
|
|
$this->bindFileService->expects(self::once())->method('registerSubdomain');
|
|
|
- $this->entityManager->expects(self::once())->method('flush');
|
|
|
$this->messageBus
|
|
|
->expects(self::once())
|
|
|
->method('dispatch')
|
|
|
@@ -163,7 +179,7 @@ class OnSubdomainChangeTest extends TestCase
|
|
|
->getMockBuilder(OnSubdomainChange::class)
|
|
|
->onlyMethods(['sendEmailAfterSubdomainChange'])
|
|
|
->setConstructorArgs(
|
|
|
- [$this->organizationUtils, $this->accessUtils, $this->mailHub, $this->bindFileService, $this->messageBus, $this->entityManager]
|
|
|
+ [$this->organizationUtils, $this->accessUtils, $this->mailHub, $this->bindFileService, $this->messageBus]
|
|
|
)
|
|
|
->getMock();
|
|
|
$onChange->expects(self::once())->method('sendEmailAfterSubdomainChange');
|
|
|
@@ -172,16 +188,10 @@ class OnSubdomainChangeTest extends TestCase
|
|
|
$subdomain = $this->getMockBuilder(Subdomain::class)->disableOriginalConstructor()->getMock();
|
|
|
$subdomain->method('isActive')->willReturn(true);
|
|
|
|
|
|
- // Le sous domaine qui était actif jusqu'ici, et que le OnChange devrait désactiver
|
|
|
- $otherSubdomain = $this->getMockBuilder(Subdomain::class)->disableOriginalConstructor()->getMock();
|
|
|
- $otherSubdomain->method('isActive')->willReturn(true);
|
|
|
- $otherSubdomain->expects(self::once())->method('setActive')->with(false);
|
|
|
-
|
|
|
$organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
$organization->method('getId')->willReturn(1);
|
|
|
- $organization->expects(self::once())->method('getSubdomains')->willReturn(new \Doctrine\Common\Collections\ArrayCollection([$subdomain, $otherSubdomain]));
|
|
|
|
|
|
- $subdomain->expects(self::exactly(2))->method('getOrganization')->willReturn($organization);
|
|
|
+ $subdomain->method('getOrganization')->willReturn($organization);
|
|
|
|
|
|
$context = $this->getMockBuilder(OnChangeContext::class)->disableOriginalConstructor()->getMock();
|
|
|
$context->method('previousData')->willReturn(null);
|