SubdomainServiceTest.php 23 KB

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