SubdomainServiceTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <?php
  2. namespace App\Tests\Unit\Service\Typo3;
  3. use App\Entity\Access\Access;
  4. use App\Entity\Organization\Organization;
  5. use App\Entity\Organization\Parameters;
  6. use App\Entity\Organization\Subdomain;
  7. use App\Entity\Person\Person;
  8. use App\Message\Message\MailerCommand;
  9. use App\Message\Message\Typo3\Typo3Update;
  10. use App\Repository\Access\AccessRepository;
  11. use App\Repository\Organization\SubdomainRepository;
  12. use App\Service\Mailer\Model\SubdomainChangeModel;
  13. use App\Service\Organization\Utils as OrganizationUtils;
  14. use App\Service\Typo3\BindFileService;
  15. use App\Service\Typo3\SubdomainService;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\ORM\EntityManagerInterface;
  18. use PHPUnit\Framework\MockObject\MockObject;
  19. use PHPUnit\Framework\TestCase;
  20. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  21. use Symfony\Component\Messenger\Envelope;
  22. use Symfony\Component\Messenger\MessageBusInterface;
  23. class TestableSubdomainService extends SubdomainService
  24. {
  25. public function setOrganizationActiveSubdomain(Subdomain $subdomain): Subdomain
  26. {
  27. return parent::setOrganizationActiveSubdomain($subdomain);
  28. }
  29. public function renameAdminUserToMatchSubdomain(Subdomain $subdomain): void
  30. {
  31. parent::renameAdminUserToMatchSubdomain($subdomain);
  32. }
  33. public function updateTypo3Website($organization): void
  34. {
  35. parent::updateTypo3Website($organization);
  36. }
  37. public function getMailModel(Subdomain $subdomain): SubdomainChangeModel
  38. {
  39. return parent::getMailModel($subdomain);
  40. }
  41. public function sendConfirmationEmail(Subdomain $subdomain): void
  42. {
  43. parent::sendConfirmationEmail($subdomain);
  44. }
  45. }
  46. class SubdomainServiceTest extends TestCase
  47. {
  48. private MockObject|SubdomainRepository $subdomainRepository;
  49. private MockObject|OrganizationUtils $organizationUtils;
  50. private MockObject|BindFileService $bindFileService;
  51. private MockObject|MessageBusInterface $messageBus;
  52. private MockObject|EntityManagerInterface $entityManager;
  53. private MockObject|AccessRepository $accessRepository;
  54. private MockObject|ParameterBagInterface $parameterBag;
  55. public function setUp(): void
  56. {
  57. $this->subdomainRepository = $this->getMockBuilder(SubdomainRepository::class)->disableOriginalConstructor()->getMock();
  58. $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
  59. $this->messageBus = $this->getMockBuilder(MessageBusInterface::class)->disableOriginalConstructor()->getMock();
  60. $this->organizationUtils = $this->getMockBuilder(OrganizationUtils::class)->disableOriginalConstructor()->getMock();
  61. $this->bindFileService = $this->getMockBuilder(BindFileService::class)->disableOriginalConstructor()->getMock();
  62. $this->accessRepository = $this->getMockBuilder(AccessRepository::class)->disableOriginalConstructor()->getMock();
  63. $this->parameterBag = $this->getMockBuilder(ParameterBagInterface::class)->disableOriginalConstructor()->getMock();
  64. }
  65. private function makeSubdomainServiceMockFor(string $methodName): MockObject|TestableSubdomainService
  66. {
  67. return $this->getMockBuilder(TestableSubdomainService::class)
  68. ->setConstructorArgs([
  69. $this->subdomainRepository,
  70. $this->entityManager,
  71. $this->messageBus,
  72. $this->organizationUtils,
  73. $this->bindFileService,
  74. $this->accessRepository,
  75. $this->parameterBag,
  76. ])
  77. ->setMethodsExcept([$methodName])
  78. ->getMock();
  79. }
  80. /**
  81. * @see SubdomainService::canRegisterNewSubdomain()
  82. */
  83. public function testCanRegisterNewSubdomainTrue(): void
  84. {
  85. $subdomainService = $this->makeSubdomainServiceMockFor('canRegisterNewSubdomain');
  86. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  87. $organization->expects(self::once())->method('getSubdomains')->willReturn(new ArrayCollection([1, 2]));
  88. $this->assertTrue($subdomainService->canRegisterNewSubdomain($organization));
  89. }
  90. /**
  91. * @see SubdomainService::canRegisterNewSubdomain()
  92. */
  93. public function testCanRegisterNewSubdomainFalse(): void
  94. {
  95. $subdomainService = $this->makeSubdomainServiceMockFor('canRegisterNewSubdomain');
  96. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  97. $organization->expects(self::once())->method('getSubdomains')->willReturn(new ArrayCollection([1, 2, 3]));
  98. $this->assertFalse($subdomainService->canRegisterNewSubdomain($organization));
  99. }
  100. /**
  101. * @see SubdomainService::isValidSubdomain()
  102. */
  103. public function testIsValidSubdomain(): void
  104. {
  105. $subdomainService = $this->makeSubdomainServiceMockFor('isValidSubdomain');
  106. $this->assertTrue($subdomainService->isValidSubdomain('abcd'));
  107. $this->assertTrue($subdomainService->isValidSubdomain('abcdefgh'));
  108. $this->assertTrue($subdomainService->isValidSubdomain('abcd-efgh'));
  109. $this->assertTrue($subdomainService->isValidSubdomain('123'));
  110. $this->assertTrue($subdomainService->isValidSubdomain('a'));
  111. $this->assertFalse($subdomainService->isValidSubdomain('_abc'));
  112. $this->assertFalse($subdomainService->isValidSubdomain('abc-'));
  113. $this->assertFalse($subdomainService->isValidSubdomain(str_repeat('abcdef', 20)));
  114. }
  115. public function testIsReservedSubdomain(): void
  116. {
  117. $subdomainService = $this->makeSubdomainServiceMockFor('isReservedSubdomain');
  118. $this->parameterBag
  119. ->method('get')
  120. ->with('opentalent.subdomains')
  121. ->willReturn([
  122. 'reserved' => [
  123. 'abcd',
  124. 'abc\d+',
  125. ],
  126. ]);
  127. $this->assertTrue($subdomainService->isReservedSubdomain('abcd'));
  128. $this->assertTrue($subdomainService->isReservedSubdomain('abc123'));
  129. $this->assertFalse($subdomainService->isReservedSubdomain('abcde'));
  130. $this->assertFalse($subdomainService->isReservedSubdomain('abc'));
  131. $this->assertFalse($subdomainService->isReservedSubdomain('foo'));
  132. }
  133. public function testIsRegisteredSubdomain(): void
  134. {
  135. $subdomainService = $this->makeSubdomainServiceMockFor('isRegistered');
  136. $this->subdomainRepository->method('findBy')->willReturnCallback(function ($args) {
  137. if ($args === ['subdomain' => 'sub']) {
  138. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  139. return [$subdomain];
  140. }
  141. return [];
  142. });
  143. $this->assertTrue($subdomainService->isRegistered('sub'));
  144. $this->assertFalse($subdomainService->isRegistered('foo'));
  145. }
  146. public function testAddNewSubdomain(): void
  147. {
  148. $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
  149. $parameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
  150. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  151. $organization->method('getParameters')->willReturn($parameters);
  152. $subdomainService->expects(self::once())->method('isValidSubdomain')->with('sub')->willReturn(true);
  153. $subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
  154. $subdomainService->expects(self::once())->method('isReservedSubdomain')->with('sub')->willReturn(false);
  155. $subdomainService->expects(self::once())->method('isRegistered')->with('sub')->willReturn(false);
  156. $this->entityManager->expects(self::once())->method('persist');
  157. $this->entityManager->expects(self::once())->method('flush');
  158. $this->bindFileService->expects(self::once())->method('registerSubdomain')->with('sub');
  159. // Subdomain is not activated by default
  160. $subdomainService->expects(self::never())->method('activateSubdomain');
  161. $subdomain = $subdomainService->addNewSubdomain($organization, 'sub');
  162. $this->assertEquals($subdomain->getOrganization(), $organization);
  163. $this->assertEquals($subdomain->getSubdomain(), 'sub');
  164. $this->assertFalse($subdomain->isActive());
  165. }
  166. public function testAddNewSubdomainInvalid(): void
  167. {
  168. $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
  169. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  170. $subdomainService->expects(self::once())->method('isValidSubdomain')->with('_sub')->willReturn(false);
  171. $subdomainService->expects(self::never())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
  172. $subdomainService->expects(self::never())->method('isReservedSubdomain')->with($organization)->willReturn(false);
  173. $subdomainService->expects(self::never())->method('isRegistered')->with('sub')->willReturn(false);
  174. $this->entityManager->expects(self::never())->method('persist');
  175. $this->entityManager->expects(self::never())->method('flush');
  176. $this->bindFileService->expects(self::never())->method('registerSubdomain')->with('_sub');
  177. $subdomainService->expects(self::never())->method('activateSubdomain');
  178. $this->expectException(\RuntimeException::class);
  179. $this->expectExceptionMessage('Not a valid subdomain');
  180. $subdomainService->addNewSubdomain($organization, '_sub');
  181. }
  182. public function testAddNewSubdomainMaxReached(): void
  183. {
  184. $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
  185. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  186. $subdomainService->expects(self::once())->method('isValidSubdomain')->with('_sub')->willReturn(true);
  187. $subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(false);
  188. $subdomainService->expects(self::never())->method('isReservedSubdomain')->with($organization)->willReturn(false);
  189. $subdomainService->expects(self::never())->method('isRegistered')->with('sub')->willReturn(false);
  190. $this->entityManager->expects(self::never())->method('persist');
  191. $this->entityManager->expects(self::never())->method('flush');
  192. $this->bindFileService->expects(self::never())->method('registerSubdomain')->with('_sub');
  193. $subdomainService->expects(self::never())->method('activateSubdomain');
  194. $this->expectException(\RuntimeException::class);
  195. $this->expectExceptionMessage('This organization can not register new subdomains');
  196. $subdomainService->addNewSubdomain($organization, '_sub');
  197. }
  198. public function testAddNewSubdomainIsReserved(): void
  199. {
  200. $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
  201. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  202. $subdomainService->expects(self::once())->method('isValidSubdomain')->with('_sub')->willReturn(true);
  203. $subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
  204. $subdomainService->expects(self::once())->method('isReservedSubdomain')->with('_sub')->willReturn(true);
  205. $subdomainService->expects(self::never())->method('isRegistered')->with('sub')->willReturn(false);
  206. $this->entityManager->expects(self::never())->method('persist');
  207. $this->entityManager->expects(self::never())->method('flush');
  208. $this->bindFileService->expects(self::never())->method('registerSubdomain')->with('_sub');
  209. $subdomainService->expects(self::never())->method('activateSubdomain');
  210. $this->expectException(\RuntimeException::class);
  211. $this->expectExceptionMessage('This subdomain is not available');
  212. $subdomainService->addNewSubdomain($organization, '_sub');
  213. }
  214. public function testAddNewSubdomainExisting(): void
  215. {
  216. $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
  217. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  218. $subdomainService->expects(self::once())->method('isValidSubdomain')->with('sub')->willReturn(true);
  219. $subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
  220. $subdomainService->expects(self::once())->method('isReservedSubdomain')->with('sub')->willReturn(false);
  221. $subdomainService->expects(self::once())->method('isRegistered')->with('sub')->willReturn(true);
  222. $this->entityManager->expects(self::never())->method('persist');
  223. $this->entityManager->expects(self::never())->method('flush');
  224. $this->bindFileService->expects(self::never())->method('registerSubdomain')->with('sub');
  225. $subdomainService->expects(self::never())->method('activateSubdomain');
  226. $this->expectException(\RuntimeException::class);
  227. $this->expectExceptionMessage('This subdomain is already registered');
  228. $subdomainService->addNewSubdomain($organization, 'sub');
  229. }
  230. public function testAddNewSubdomainAndActivate(): void
  231. {
  232. $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
  233. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  234. $subdomainService->expects(self::once())->method('isValidSubdomain')->with('sub')->willReturn(true);
  235. $subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
  236. $subdomainService->expects(self::once())->method('isReservedSubdomain')->with('sub')->willReturn(false);
  237. $subdomainService->expects(self::once())->method('isRegistered')->with('sub')->willReturn(false);
  238. $subdomainService->expects(self::once())->method('activateSubdomain');
  239. $subdomainService->addNewSubdomain($organization, 'sub', true);
  240. }
  241. public function testActivateSubdomain(): void
  242. {
  243. $subdomainService = $this->makeSubdomainServiceMockFor('activateSubdomain');
  244. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  245. $previousActiveSubdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  246. $previousActiveSubdomain->method('getId')->willReturn(1);
  247. $previousActiveSubdomain->method('isActive')->willReturn(false);
  248. $this->subdomainRepository->method('getActiveSubdomainOf')->with($organization)->willReturn($previousActiveSubdomain);
  249. $initialSubdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  250. $initialSubdomain->method('getId')->willReturn(2);
  251. $initialSubdomain->method('isActive')->willReturn(false);
  252. $initialSubdomain->method('getOrganization')->willReturn($organization);
  253. $activatedSubdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  254. $activatedSubdomain->method('getId')->willReturn(2);
  255. $activatedSubdomain->method('isActive')->willReturn(true);
  256. $activatedSubdomain->method('getOrganization')->willReturn($organization);
  257. $subdomainService
  258. ->expects(self::once())
  259. ->method('setOrganizationActiveSubdomain')
  260. ->with($initialSubdomain)
  261. ->willReturn($activatedSubdomain);
  262. $subdomainService
  263. ->expects(self::once())
  264. ->method('renameAdminUserToMatchSubdomain')
  265. ->with($activatedSubdomain);
  266. $subdomainService
  267. ->expects(self::once())
  268. ->method('updateTypo3Website')
  269. ->with($organization);
  270. $subdomainService
  271. ->expects(self::once())
  272. ->method('sendConfirmationEmail')
  273. ->with($activatedSubdomain);
  274. $result = $subdomainService->activateSubdomain($initialSubdomain);
  275. $this->assertEquals($result, $activatedSubdomain);
  276. }
  277. public function testActivateSubdomainAlreadyActive(): void
  278. {
  279. $subdomainService = $this->makeSubdomainServiceMockFor('activateSubdomain');
  280. $organization = $this->getMockBuilder(Organization::class)->getMock();
  281. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  282. $subdomain->method('getOrganization')->willReturn($organization);
  283. $subdomain->method('getId')->willReturn(1);
  284. $subdomain->method('isActive')->willReturn(true);
  285. $this->subdomainRepository->method('getActiveSubdomainOf')->with($organization)->willReturn($subdomain);
  286. $subdomainService->expects(self::never())->method('setOrganizationActiveSubdomain');
  287. $subdomainService->expects(self::never())->method('renameAdminUserToMatchSubdomain');
  288. $subdomainService->expects(self::never())->method('updateTypo3Website');
  289. $subdomainService->expects(self::never())->method('sendConfirmationEmail');
  290. $this->expectException(\RuntimeException::class);
  291. $this->expectExceptionMessage('The subdomain is already active');
  292. $subdomainService->activateSubdomain($subdomain);
  293. }
  294. public function testActivateSubdomainNotPersisted(): void
  295. {
  296. $subdomainService = $this->makeSubdomainServiceMockFor('activateSubdomain');
  297. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  298. $subdomain->method('getId')->willReturn(null);
  299. $subdomain->method('isActive')->willReturn(false);
  300. $subdomainService->expects(self::never())->method('setOrganizationActiveSubdomain');
  301. $subdomainService->expects(self::never())->method('renameAdminUserToMatchSubdomain');
  302. $subdomainService->expects(self::never())->method('updateTypo3Website');
  303. $subdomainService->expects(self::never())->method('sendConfirmationEmail');
  304. // $parameters->expects(self::once())->method('setSubDomain')->with('sub');
  305. // $parameters->expects(self::once())->method('setOtherWebsite')->with('https://sub.opentalent.fr');
  306. $this->expectException(\RuntimeException::class);
  307. $this->expectExceptionMessage('Can not activate a non-persisted subdomain');
  308. $subdomainService->activateSubdomain($subdomain);
  309. }
  310. public function testSetOrganizationActiveSubdomain(): void
  311. {
  312. $subdomainService = $this->makeSubdomainServiceMockFor('setOrganizationActiveSubdomain');
  313. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  314. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  315. $subdomain->method('getId')->willReturn(1);
  316. $subdomain->method('isActive')->willReturn(false);
  317. $otherSubdomain1 = $this->getMockBuilder(Subdomain::class)->getMock();
  318. $otherSubdomain1->method('getId')->willReturn(2);
  319. $otherSubdomain1->method('isActive')->willReturn(true);
  320. $otherSubdomain2 = $this->getMockBuilder(Subdomain::class)->getMock();
  321. $otherSubdomain2->method('getId')->willReturn(3);
  322. $otherSubdomain2->method('isActive')->willReturn(false);
  323. $organization->method('getSubdomains')->willReturn(new ArrayCollection([$otherSubdomain1, $otherSubdomain2]));
  324. $subdomain->method('getOrganization')->willReturn($organization);
  325. // The active subdomain is deactivated
  326. $otherSubdomain1->expects(self::once())->method('setActive')->with(false);
  327. // The inactive subdomain is not modified
  328. $otherSubdomain2->expects(self::never())->method('setActive');
  329. // The new subdomain is activated
  330. $subdomain->expects(self::once())->method('setActive')->with(true);
  331. $this->entityManager->expects(self::once())->method('flush');
  332. $this->entityManager->expects(self::once())->method('refresh')->with($organization);
  333. $result = $subdomainService->setOrganizationActiveSubdomain($subdomain);
  334. $this->assertEquals($result, $subdomain);
  335. }
  336. public function testRenameAdminUserToMatchSubdomain(): void
  337. {
  338. $subdomainService = $this->makeSubdomainServiceMockFor('renameAdminUserToMatchSubdomain');
  339. $organization = $this->getMockBuilder(Organization::class)->getMock();
  340. $person = $this->getMockBuilder(Person::class)->getMock();
  341. $access = $this->getMockBuilder(Access::class)->getMock();
  342. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  343. $this->accessRepository
  344. ->method('findAdminAccess')
  345. ->with($organization)
  346. ->willReturn($access);
  347. $subdomain->method('getSubdomain')->willReturn('sub');
  348. $subdomain->method('getOrganization')->willReturn($organization);
  349. $access->method('getPerson')->willReturn($person);
  350. $person->expects(self::once())->method('setUsername')->with('adminsub');
  351. $this->entityManager->expects(self::once())->method('flush');
  352. $subdomainService->renameAdminUserToMatchSubdomain($subdomain);
  353. }
  354. public function testUpdateTypo3Website(): void
  355. {
  356. $subdomainService = $this->makeSubdomainServiceMockFor('updateTypo3Website');
  357. $organization = $this->getMockBuilder(Organization::class)->getMock();
  358. $organization->method('getId')->willReturn(1);
  359. $this->messageBus
  360. ->expects(self::once())
  361. ->method('dispatch')
  362. ->with(self::isInstanceOf(Typo3Update::class))
  363. ->willReturn(new Envelope(new Typo3Update(1)));
  364. $subdomainService->updateTypo3Website($organization);
  365. }
  366. public function testGetMailModel(): void
  367. {
  368. $subdomainService = $this->makeSubdomainServiceMockFor('getMailModel');
  369. $access = $this->getMockBuilder(Access::class)->getMock();
  370. $access->method('getId')->willReturn(1);
  371. $organization = $this->getMockBuilder(Organization::class)->getMock();
  372. $organization->method('getId')->willReturn(1);
  373. $subdomain = $this->getMockBuilder(Subdomain::class)->disableOriginalConstructor()->getMock();
  374. $subdomain->method('getOrganization')->willReturn($organization);
  375. $subdomain->method('getId')->willReturn(1);
  376. $this->accessRepository
  377. ->method('findAdminAccess')
  378. ->with($organization)
  379. ->willReturn($access);
  380. $this->organizationUtils
  381. ->expects(self::once())
  382. ->method('getOrganizationWebsite')
  383. ->with($organization)
  384. ->willReturn('mysubdomain.opentalent.fr');
  385. $mailerModel = $subdomainService->getMailModel($subdomain);
  386. $this->assertInstanceOf(SubdomainChangeModel::class, $mailerModel);
  387. $this->assertEquals(1, $mailerModel->getSenderId());
  388. $this->assertEquals(1, $mailerModel->getOrganizationId());
  389. $this->assertEquals(1, $mailerModel->getSubdomainId());
  390. $this->assertEquals('mysubdomain.opentalent.fr', $mailerModel->getUrl());
  391. }
  392. public function testSendConfirmationEmail(): void
  393. {
  394. $subdomainService = $this->makeSubdomainServiceMockFor('sendConfirmationEmail');
  395. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  396. $subdomainChangeModel = $this->getMockBuilder(SubdomainChangeModel::class)->getMock();
  397. $subdomainService->method('getMailModel')->willReturn($subdomainChangeModel);
  398. $this->messageBus
  399. ->expects(self::once())
  400. ->method('dispatch')
  401. ->with(self::isInstanceOf(MailerCommand::class))
  402. ->willReturn(new Envelope(new MailerCommand($subdomainChangeModel)));
  403. $subdomainService->sendConfirmationEmail($subdomain);
  404. }
  405. }