Skip to content

Commit 9a35a53

Browse files
committed
MCLOUD-6898: Add option to customize port for MailHog
1 parent 942796c commit 9a35a53

File tree

12 files changed

+129
-3
lines changed

12 files changed

+129
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
/composer.lock
66
/auth.json
77
/_workdir
8+
/_workdir_cache
89
.phpunit.result.cache

codeception.dist.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ modules:
3434
printOutput: false
3535
PhpBrowser:
3636
url: "%Magento.docker.settings.env.url.base%"
37+
REST:
38+
depends: PhpBrowser
39+
url: "%Magento.docker.settings.env.url.base%"
40+
shortDebugResponse: 300
3741
Magento\CloudDocker\Test\Functional\Codeception\MagentoDb:
3842
dsn: "mysql:host=%Magento.docker.settings.db.host%;port=%Magento.docker.settings.db.port%;dbname=%Magento.docker.settings.db.path%"
3943
user: "%Magento.docker.settings.db.username%"

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"codeception/module-asserts": "^1.2",
2424
"codeception/module-db": "^1.0",
2525
"codeception/module-phpbrowser": "^1.0",
26+
"codeception/module-rest": "^1.2",
2627
"consolidation/robo": "^1.2",
2728
"phpmd/phpmd": "@stable",
2829
"phpstan/phpstan": "^0.11",

src/Command/BuildCompose.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ protected function configure(): void
171171
null,
172172
InputOption::VALUE_NONE,
173173
'Disable mailhog'
174+
)->addOption(
175+
Source\CliSource::OPTION_MAILHOG_SMTP_PORT,
176+
null,
177+
InputOption::VALUE_REQUIRED,
178+
'MailHog SMTP port'
179+
)->addOption(
180+
Source\CliSource::OPTION_MAILHOG_HTTP_PORT,
181+
null,
182+
InputOption::VALUE_REQUIRED,
183+
'MailHog HTTP port'
174184
)->addOption(
175185
Source\CliSource::OPTION_SET_DOCKER_HOST_XDEBUG,
176186
null,

src/Compose/ProductionBuilder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,13 @@ public function build(Config $config): Manager
402402
self::SERVICE_MAILHOG,
403403
$this->serviceFactory->create(
404404
ServiceInterface::SERVICE_MAILHOG,
405-
$this->serviceFactory->getDefaultVersion(ServiceInterface::SERVICE_MAILHOG)
405+
$this->serviceFactory->getDefaultVersion(ServiceInterface::SERVICE_MAILHOG),
406+
[
407+
'ports' => [
408+
($config->getMailHogSmtpPort() ?: '1025').':1025',
409+
($config->getMailHogHttpPort() ?: '8025').':8025',
410+
]
411+
]
406412
),
407413
[self::NETWORK_MAGENTO],
408414
[]

src/Config/Config.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,22 @@ public function getDbIncrementOffset(): int
454454
1
455455
);
456456
}
457+
458+
/**
459+
* @return string|null
460+
* @throws ConfigurationMismatchException
461+
*/
462+
public function getMailHogSmtpPort(): ?string
463+
{
464+
return $this->all()->get(SourceInterface::SYSTEM_MAILHOG_SMTP_PORT);
465+
}
466+
467+
/**
468+
* @return string|null
469+
* @throws ConfigurationMismatchException
470+
*/
471+
public function getMailHogHttpPort(): ?string
472+
{
473+
return $this->all()->get(SourceInterface::SYSTEM_MAILHOG_HTTP_PORT);
474+
}
457475
}

src/Config/Source/CliSource.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class CliSource implements SourceInterface
3434
public const OPTION_NO_ES = 'no-es';
3535
public const OPTION_NO_MAILHOG = 'no-mailhog';
3636

37+
/**
38+
* MailHog configuration
39+
*/
40+
public const OPTION_MAILHOG_SMTP_PORT = 'mailhog-smtp-port';
41+
public const OPTION_MAILHOG_HTTP_PORT = 'mailhog-http-port';
42+
3743
/**
3844
* State modifiers.
3945
*/
@@ -277,6 +283,14 @@ public function read(): Repository
277283
$repository->set(SourceInterface::SYSTEM_MARIADB_CONF, true);
278284
}
279285

286+
if ($port = $this->input->getOption(self::OPTION_MAILHOG_SMTP_PORT)) {
287+
$repository->set(self::SYSTEM_MAILHOG_SMTP_PORT, $port);
288+
}
289+
290+
if ($port = $this->input->getOption(self::OPTION_MAILHOG_HTTP_PORT)) {
291+
$repository->set(self::SYSTEM_MAILHOG_HTTP_PORT, $port);
292+
}
293+
280294
return $repository;
281295
}
282296
}

src/Config/Source/SourceInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ interface SourceInterface
143143
public const SYSTEM_DB_ENTRYPOINT = 'system.db_entrypoint';
144144
public const SYSTEM_MARIADB_CONF = 'system.mariadb_conf';
145145
public const SYSTEM_SET_DOCKER_HOST = 'system.set_docker_host';
146+
public const SYSTEM_MAILHOG_SMTP_PORT = 'system.mailhog.smtp_port';
147+
public const SYSTEM_MAILHOG_HTTP_PORT = 'system.mailhog.http_port';
146148

147149
public const SYSTEM_DB_INCREMENT_INCREMENT = 'system.db.increment_increment';
148150
public const SYSTEM_DB_INCREMENT_OFFSET = 'system.db.increment_offset';

src/Test/Functional/Acceptance.suite.dist.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ modules:
66
- Magento\CloudDocker\Test\Functional\Codeception\MagentoDb
77
- PhpBrowser
88
- Asserts
9+
- REST
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CloudDocker\Test\Functional\Acceptance;
9+
10+
/**
11+
* @group php74
12+
*/
13+
class MailHogCest extends AbstractCest
14+
{
15+
/**
16+
* @param \CliTester $I
17+
* @throws \Exception
18+
*/
19+
public function testDefaultPorts(\CliTester $I): void
20+
{
21+
$I->updateBaseUrl('http://magento2.docker:8025/');
22+
$I->assertTrue(
23+
$I->runEceDockerCommand('build:compose'),
24+
'Command build:compose failed'
25+
);
26+
$this->runAndAssert($I);
27+
}
28+
29+
/**
30+
* @param \CliTester $I
31+
* @throws \Exception
32+
*/
33+
public function testCustomPorts(\CliTester $I): void
34+
{
35+
$I->updateBaseUrl('http://magento2.docker:8026/');
36+
$I->assertTrue(
37+
$I->runEceDockerCommand('build:compose --mailhog-http-port=8026 --mailhog-smtp-port=1026'),
38+
'Command build:compose failed'
39+
);
40+
$this->runAndAssert($I);
41+
}
42+
43+
/**
44+
* @param \CliTester $I
45+
* @throws \Exception
46+
*/
47+
private function runAndAssert(\CliTester $I): void
48+
{
49+
$I->replaceImagesWithGenerated();
50+
$I->startEnvironment();
51+
$I->amOnPage('/');
52+
$I->see('MailHog');
53+
54+
$I->sendAjaxGetRequest('/api/v2/messages', ['limit' => 10]);
55+
$I->seeResponseIsJson();
56+
$I->assertSame([0], $I->grabDataFromResponseByJsonPath('$.total'));
57+
58+
$I->assertTrue(
59+
$I->runDockerComposeCommand('run deploy bash -c "php -r \"mail(\'[email protected]\',\'test\',\'test\');\""')
60+
);
61+
$I->sendAjaxGetRequest('/api/v2/messages', ['limit' => 10]);
62+
$I->seeResponseIsJson();
63+
$I->assertSame([1], $I->grabDataFromResponseByJsonPath('$.total'));
64+
}
65+
}

0 commit comments

Comments
 (0)