1212use Robo \Exception \TaskException ;
1313
1414/**
15+ * Tests ActiveMQ Artemis functionality in Docker environment
16+ *
1517 * @group php84
1618 */
17- class ActivemqArtemisCest extends AbstractCest
19+ abstract class ActivemqArtemisCest extends AbstractCest
1820{
1921 /**
2022 * Template version for testing
2123 */
22- protected const TEMPLATE_VERSION = '2.4.9 ' ;
24+ protected const TEMPLATE_VERSION = '2.4.9-alpha-opensearch3.0 ' ;
2325
2426 /**
27+ * Builds build:compose command from given test data
28+ *
29+ * @param Example $data
30+ * @return string
31+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
32+ */
33+ private function buildCommand (Example $ data ): string
34+ {
35+ // Note: $data is not used as ActiveMQ Artemis is configured via services.yaml
36+ // rather than CLI options, but parameter is kept for consistency with other tests
37+ return '--mode=production --no-es --no-os --no-redis --no-valkey ' ;
38+ }
39+
40+ /**
41+ * Data provider for basic functionality test
42+ *
43+ * @return array
44+ */
45+ abstract protected function basicFunctionalityDataProvider (): array ;
46+
47+ /**
48+ * Data provider for custom configuration test
49+ *
50+ * @return array
51+ */
52+ abstract protected function customConfigurationDataProvider (): array ;
53+
54+ /**
55+ * Data provider for error scenarios test
56+ *
57+ * @return array
58+ */
59+ abstract protected function errorScenariosDataProvider (): array ;
60+
61+ /**
62+ * Test basic ActiveMQ Artemis functionality
63+ *
2564 * @param CliTester $I
2665 * @param Example $data
27- * @dataProvider dataProvider
66+ * @dataProvider basicFunctionalityDataProvider
2867 * @return void
2968 * @throws TaskException
3069 */
31- public function testActivemqArtemis (CliTester $ I , Example $ data ): void
70+ public function testBasicFunctionality (CliTester $ I , Example $ data ): void
3271 {
3372 // Create services.yaml with activemq-artemis configuration
3473 $ servicesConfig = [
@@ -47,6 +86,97 @@ public function testActivemqArtemis(CliTester $I, Example $data): void
4786 $ I ->seeInOutput ('activemq-artemis ' );
4887 $ I ->seeInOutput ('(healthy) ' );
4988
89+ // Test network connectivity
90+ $ this ->testNetworkConnectivity ($ I );
91+
92+ // Test ActiveMQ Artemis CLI functionality
93+ $ this ->testArtemisCLI ($ I );
94+
95+ // Test message producer/consumer functionality
96+ $ this ->testMessageQueuing ($ I );
97+
98+ // Test environment variables
99+ $ this ->testEnvironmentVariables ($ I );
100+ }
101+
102+ /**
103+ * Test ActiveMQ Artemis with custom configuration
104+ *
105+ * @param CliTester $I
106+ * @param Example $data
107+ * @dataProvider customConfigurationDataProvider
108+ * @return void
109+ * @throws TaskException
110+ */
111+ public function testCustomConfiguration (CliTester $ I , Example $ data ): void
112+ {
113+ // Create services.yaml with custom activemq-artemis configuration
114+ $ I ->writeServicesYaml ($ data ['servicesConfig ' ]);
115+
116+ $ I ->generateDockerCompose ($ this ->buildCommand ($ data ));
117+ $ I ->replaceImagesWithCustom ();
118+ $ I ->startEnvironment ();
119+
120+ // Verify container is running
121+ $ I ->runDockerComposeCommand ('ps ' );
122+ $ I ->seeInOutput ('activemq-artemis ' );
123+ $ I ->seeInOutput ('(healthy) ' );
124+
125+ // Test basic connectivity with custom settings
126+ $ this ->testNetworkConnectivity ($ I );
127+
128+ // Verify custom environment variables if specified
129+ if (isset ($ data ['expectedEnvVars ' ])) {
130+ foreach ($ data ['expectedEnvVars ' ] as $ envVar => $ expectedValue ) {
131+ $ I ->runDockerComposeCommand ("exec -T activemq-artemis env | grep {$ envVar }" );
132+ $ I ->seeInOutput ("{$ envVar }= {$ expectedValue }" );
133+ }
134+ }
135+ }
136+
137+ /**
138+ * Test ActiveMQ Artemis error scenarios
139+ *
140+ * @param CliTester $I
141+ * @param Example $data
142+ * @dataProvider errorScenariosDataProvider
143+ * @return void
144+ * @throws TaskException
145+ */
146+ public function testErrorScenarios (CliTester $ I , Example $ data ): void
147+ {
148+ // Create services.yaml with problematic configuration
149+ $ I ->writeServicesYaml ($ data ['servicesConfig ' ]);
150+
151+ $ generateResult = $ I ->generateDockerCompose ($ this ->buildCommand ($ data ));
152+
153+ if ($ data ['expectGenerationFailure ' ]) {
154+ $ I ->assertFalse ($ generateResult , 'Docker compose generation should have failed ' );
155+ if (isset ($ data ['expectedErrorMessage ' ])) {
156+ $ I ->seeInOutput ($ data ['expectedErrorMessage ' ]);
157+ }
158+ return ;
159+ }
160+
161+ $ I ->assertTrue ($ generateResult , 'Docker compose generation should succeed ' );
162+ $ I ->replaceImagesWithCustom ();
163+
164+ $ startResult = $ I ->startEnvironment ();
165+ if ($ data ['expectStartFailure ' ]) {
166+ $ I ->assertFalse ($ startResult , 'Environment start should have failed ' );
167+ return ;
168+ }
169+
170+ $ I ->assertTrue ($ startResult , 'Environment should start successfully ' );
171+ }
172+
173+ /**
174+ * Test network connectivity to ActiveMQ Artemis ports
175+ *
176+ * @param CliTester $I
177+ */
178+ private function testNetworkConnectivity (CliTester $ I ): void
179+ {
50180 // Test ActiveMQ Artemis web console accessibility (port 8161)
51181 $ I ->runDockerComposeCommand ('exec -T fpm nc -z activemq-artemis.magento2.docker 8161 ' );
52182 $ I ->seeInOutput ('' ); // nc returns empty output on success
@@ -62,7 +192,15 @@ public function testActivemqArtemis(CliTester $I, Example $data): void
62192 // Test that ActiveMQ Artemis is accessible through direct host name
63193 $ I ->runDockerComposeCommand ('exec -T fpm nc -z activemq-artemis 61616 ' );
64194 $ I ->seeInOutput ('' );
65-
195+ }
196+
197+ /**
198+ * Test ActiveMQ Artemis CLI functionality
199+ *
200+ * @param CliTester $I
201+ */
202+ private function testArtemisCLI (CliTester $ I ): void
203+ {
66204 // Test ActiveMQ Artemis broker status using artemis CLI
67205 $ I ->runDockerComposeCommand (
68206 'exec -T activemq-artemis /opt/activemq-artemis/bin/artemis queue stat --user admin --password admin '
@@ -81,7 +219,15 @@ public function testActivemqArtemis(CliTester $I, Example $data): void
81219 'exec -T activemq-artemis /opt/activemq-artemis/bin/artemis queue stat --user admin --password admin '
82220 );
83221 $ I ->seeInOutput ('test.queue ' );
84-
222+ }
223+
224+ /**
225+ * Test message producer/consumer functionality
226+ *
227+ * @param CliTester $I
228+ */
229+ private function testMessageQueuing (CliTester $ I ): void
230+ {
85231 // Test sending a message to the queue
86232 $ I ->runDockerComposeCommand (
87233 'exec -T activemq-artemis /opt/activemq-artemis/bin/artemis producer ' .
@@ -102,7 +248,15 @@ public function testActivemqArtemis(CliTester $I, Example $data): void
102248 'exec -T activemq-artemis /opt/activemq-artemis/bin/artemis queue stat --user admin --password admin '
103249 );
104250 $ I ->seeInOutput ('CONNECTION_COUNT ' );
105-
251+ }
252+
253+ /**
254+ * Test environment variables
255+ *
256+ * @param CliTester $I
257+ */
258+ private function testEnvironmentVariables (CliTester $ I ): void
259+ {
106260 // Test that environment variables are properly set
107261 $ I ->runDockerComposeCommand ('exec -T activemq-artemis env | grep ARTEMIS ' );
108262 $ I ->seeInOutput ('ARTEMIS_USER=admin ' );
@@ -123,15 +277,4 @@ private function buildCommand(Example $data): string
123277 return '--mode=production --no-es --no-os --no-redis --no-valkey ' ;
124278 }
125279
126- /**
127- * @return array
128- */
129- protected function dataProvider (): array
130- {
131- return [
132- [
133- 'version ' => '2.17 ' ,
134- ],
135- ];
136- }
137280}
0 commit comments