Skip to content

Commit f171ed6

Browse files
committed
Replaced processRun with cmd in tests.
1 parent b27e87b commit f171ed6

14 files changed

Lines changed: 750 additions & 435 deletions

.vortex/CLAUDE.md

Lines changed: 517 additions & 110 deletions
Large diffs are not rendered by default.

.vortex/tests/phpunit/Functional/FunctionalTestCase.php

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,52 @@ public function processRun(
9595
return $this->traitProcessRun($command, $arguments, $inputs, $env, $timeout, $idle_timeout);
9696
}
9797

98-
public function processRunInContainer(
99-
string $command,
100-
array $arguments = [],
101-
array $inputs = [],
98+
public function cmd(
99+
string $cmd,
100+
array|string|null $out = NULL,
101+
?string $txt = NULL,
102+
array $arg = [],
103+
array $inp = [],
102104
array $env = [],
103-
int $timeout = 60,
104-
int $idle_timeout = 30,
105-
): Process {
106-
return $this->traitProcessRun('ahoy cli -- ' . $command, $arguments, $inputs, $env, $timeout, $idle_timeout);
105+
int $tio = 120,
106+
int $ito = 60,
107+
): ?Process {
108+
if ($txt) {
109+
$this->logNote($txt);
110+
}
111+
112+
$this->processRun($cmd, $arg, $inp, $env, $tio, $ito);
113+
$this->assertProcessSuccessful();
114+
115+
if ($out) {
116+
$this->assertProcessAnyOutputContainsOrNot($out);
117+
}
118+
119+
return $this->process;
120+
}
121+
122+
public function cmdFail(
123+
string $cmd,
124+
array|string|null $out = NULL,
125+
?string $txt = NULL,
126+
array $arg = [],
127+
array $inp = [],
128+
array $env = [],
129+
int $tio = 60,
130+
int $ito = 60,
131+
): ?Process {
132+
if ($txt) {
133+
$this->logNote($txt);
134+
}
135+
136+
$this->processRun($cmd, $arg, $inp, $env, $tio, $ito);
137+
$this->assertProcessFailed();
138+
139+
if ($out) {
140+
$this->assertProcessAnyOutputContainsOrNot($out);
141+
}
142+
143+
return $this->process;
107144
}
108145

109146
public function syncToHost(): void {

.vortex/tests/phpunit/Functional/WorkflowTest.php

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ protected function setUp(): void {
2323
public function testSmoke(): void {
2424
$this->assertDirectoryExists(static::$sut, 'SUT directory exists');
2525
$this->assertEquals(static::$sut, File::cwd(), 'SUT is the current working directory');
26-
27-
$this->processRunInContainer('rm', ['-rf', '/app/.logs/screenshots/*']);
2826
}
2927

3028
public function testIdempotence(): void {
@@ -55,10 +53,8 @@ public function testPackageToken(): void {
5553
if (file_exists('composer.lock')) {
5654
unlink('composer.lock');
5755
}
58-
$this->processRun('composer config repositories.test-private-package vcs git@github.com:drevops/test-private-package.git');
59-
$this->assertProcessSuccessful();
60-
$this->processRun('composer require --no-update drevops/test-private-package:^1');
61-
$this->assertProcessSuccessful();
56+
$this->cmd('composer config repositories.test-private-package vcs git@github.com:drevops/test-private-package.git');
57+
$this->cmd('composer require --no-update drevops/test-private-package:^1');
6258

6359
$this->logSubstep('Build without PACKAGE_TOKEN - should fail');
6460
$this->stepBuildFailure(env: ['PACKAGE_TOKEN' => '']);
@@ -72,38 +68,29 @@ public function testPackageToken(): void {
7268
*/
7369
public function testDockerComposeNoAhoy(): void {
7470
$this->logSubstep('Reset environment');
75-
$this->processRun('ahoy reset', inputs: ['y'], timeout: 5 * 60);
76-
$this->assertProcessSuccessful();
71+
$this->cmd('ahoy reset', inp: ['y'], tio: 5 * 60);
7772

7873
$this->logSubstep('Building stack with docker compose');
79-
$this->processRun('docker compose build --no-cache', timeout: 15 * 60);
80-
$this->assertProcessSuccessful();
81-
$this->processRun('docker compose up -d --force-recreate', timeout: 15 * 60);
82-
$this->assertProcessSuccessful();
74+
$this->cmd('docker compose build --no-cache', tio: 15 * 60);
75+
$this->cmd('docker compose up -d --force-recreate', tio: 15 * 60);
8376

8477
$this->syncToHost();
8578

8679
$this->logSubstep('Installing dependencies with composer');
87-
$this->processRun('docker compose exec -T cli composer install --prefer-dist', timeout: 10 * 60);
88-
$this->assertProcessSuccessful();
89-
$this->processRun('docker compose exec -T cli bash -lc "yarn --cwd=\${WEBROOT}/themes/custom/\${DRUPAL_THEME} install --frozen-lockfile"', timeout: 10 * 60);
90-
$this->assertProcessSuccessful();
80+
$this->cmd('docker compose exec -T cli composer install --prefer-dist', tio: 10 * 60);
81+
$this->cmd('docker compose exec -T cli bash -lc "yarn --cwd=\${WEBROOT}/themes/custom/\${DRUPAL_THEME} install --frozen-lockfile"', tio: 10 * 60);
9182

9283
$this->logSubstep('Provisioning with direct script execution');
9384

9485
if (!$this->volumesMounted() && file_exists('.data/db.sql')) {
9586
$this->logNote('Copying database file to container');
96-
$this->processRun('docker compose exec -T cli mkdir -p .data');
97-
$this->assertProcessSuccessful();
98-
$this->processRun('docker compose cp -L .data/db.sql cli:/app/.data/db.sql');
99-
$this->assertProcessSuccessful();
87+
$this->cmd('docker compose exec -T cli mkdir -p .data');
88+
$this->cmd('docker compose cp -L .data/db.sql cli:/app/.data/db.sql');
10089
$this->logNote('Building front-end assets in container');
101-
$this->processRun('docker compose exec -T cli bash -c "cd \${WEBROOT}/themes/custom/\${DRUPAL_THEME} && yarn run build"', timeout: 10 * 60);
102-
$this->assertProcessSuccessful();
90+
$this->cmd('docker compose exec -T cli bash -c "cd \${WEBROOT}/themes/custom/\${DRUPAL_THEME} && yarn run build"', tio: 10 * 60);
10391
}
10492

105-
$this->processRun('docker compose exec -T cli ./scripts/vortex/provision.sh', timeout: 10 * 60);
106-
$this->assertProcessSuccessful();
93+
$this->cmd('docker compose exec -T cli ./scripts/vortex/provision.sh', tio: 10 * 60);
10794

10895
$this->syncToHost();
10996

.vortex/tests/phpunit/Functional/WorkflowUtilitiesTest.php

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@ class WorkflowUtilitiesTest extends FunctionalTestCase {
1616
*/
1717
public function testLocalAhoyCommands(): void {
1818
$this->logSubstep('Assert calling local commands without local file does not throw error');
19-
$this->processRun('ahoy --version');
20-
$this->assertProcessSuccessful();
21-
$this->assertProcessOutputNotContains('[fatal]');
19+
$this->cmd('ahoy --version', '! [fatal]');
2220

2321
$this->logSubstep('Assert calling local commands with local file path specified and file is present works correctly');
2422
File::copy('.ahoy.local.example.yml', '.ahoy.local.yml');
25-
$this->processRun('ahoy local help');
26-
$this->assertProcessSuccessful();
27-
$this->assertProcessOutputContains('Custom local commands');
28-
$this->assertProcessOutputNotContains('[fatal]');
23+
$this->cmd('ahoy local help', ['* Custom local commands', '! [fatal]']);
2924

3025
$this->logSubstep('Assert calling local commands with local file path specified and file is present and file return non-zero exit code');
3126
$local_command_content = <<<YAML
@@ -40,25 +35,22 @@ public function testLocalAhoyCommands(): void {
4035

4136
File::dump('.ahoy.local.yml', $existing_content . $local_command_content);
4237

43-
$this->processRun('ahoy local mylocalcommand');
44-
$this->assertProcessFailed();
45-
$this->assertProcessOutputContains('expected failure');
46-
$this->assertProcessOutputNotContains('[fatal]');
38+
$this->cmdFail('ahoy local mylocalcommand', ['* expected failure', '! [fatal]']);
4739
}
4840

4941
/**
5042
* Test doctor info command.
5143
*/
5244
public function testDoctorInfo(): void {
5345
$this->logSubstep('Run ahoy doctor info');
54-
$this->processRun('ahoy doctor info');
55-
$this->assertProcessSuccessful();
56-
$this->assertProcessOutputContains('System information report');
57-
$this->assertProcessOutputContains('OPERATING SYSTEM');
58-
$this->assertProcessOutputContains('DOCKER');
59-
$this->assertProcessOutputContains('DOCKER COMPOSE');
60-
$this->assertProcessOutputContains('PYGMY');
61-
$this->assertProcessOutputContains('AHOY');
46+
$this->cmd('ahoy doctor info', [
47+
'System information report',
48+
'OPERATING SYSTEM',
49+
'DOCKER',
50+
'DOCKER COMPOSE',
51+
'PYGMY',
52+
'AHOY',
53+
]);
6254
}
6355

6456
}

.vortex/tests/phpunit/Traits/Steps/StepAhoyTrait.php

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,20 @@ protected function stepAhoyCli(): void {
1717
$this->logStepStart();
1818

1919
$this->logSubstep('Testing ahoy cli command');
20-
$this->processRun('ahoy cli "echo Test from inside of the container"');
21-
$this->assertProcessSuccessful();
22-
$this->assertProcessOutputNotContains('Containers are not running.');
23-
$this->assertProcessOutputContains('Test from inside of the container');
20+
$this->cmd('ahoy cli "echo Test from inside of the container"', [
21+
'! Containers are not running.',
22+
'* Test from inside of the container',
23+
]);
2424

2525
$this->logSubstep('Testing environment variable filtering');
2626
// Set test environment variables.
2727
putenv('DRUPAL_UNFILTERED_VAR=drupalvar');
2828
putenv('OTHER_FILTERED_VAR=othervar');
2929

30-
$this->processRun('ahoy cli "echo $DRUPAL_UNFILTERED_VAR"', env: [
30+
$this->cmd('ahoy cli "echo $DRUPAL_UNFILTERED_VAR"', ['* drupalvar', '! othervar'], env: [
3131
'DRUPAL_UNFILTERED_VAR' => 'drupalvar',
3232
'OTHER_FILTERED_VAR' => 'othervar',
3333
]);
34-
$this->assertProcessOutputContains('drupalvar');
35-
$this->assertProcessOutputNotContains('othervar');
3634

3735
$this->logStepFinish();
3836
}
@@ -41,10 +39,10 @@ protected function stepAhoyComposer(): void {
4139
$this->logStepStart();
4240

4341
$this->logSubstep('Testing ahoy composer command');
44-
$this->processRun('ahoy composer about');
45-
$this->assertProcessSuccessful();
46-
$this->assertProcessOutputContains('Composer - Dependency Manager for PHP - version 2.');
47-
$this->assertProcessOutputContains('Composer is a dependency manager tracking local dependencies of your projects and libraries.');
42+
$this->cmd('ahoy composer about', [
43+
'Composer - Dependency Manager for PHP - version 2.',
44+
'Composer is a dependency manager tracking local dependencies of your projects and libraries.',
45+
]);
4846

4947
$this->logStepFinish();
5048
}
@@ -53,9 +51,7 @@ protected function stepAhoyDrush(): void {
5351
$this->logStepStart();
5452

5553
$this->logSubstep('Testing ahoy drush command');
56-
$this->processRun('ahoy drush st');
57-
$this->assertProcessSuccessful();
58-
$this->assertProcessOutputNotContains('Containers are not running.');
54+
$this->cmd('ahoy drush st', '! Containers are not running.');
5955

6056
$this->logStepFinish();
6157
}
@@ -64,17 +60,22 @@ protected function stepAhoyInfo(string $webroot = 'web', string $db_image = ''):
6460
$this->logStepStart();
6561

6662
$this->logSubstep('Testing ahoy info command');
67-
$this->processRun('ahoy info');
68-
$this->assertProcessSuccessful();
69-
$this->assertProcessOutputContains('Project name : star_wars');
70-
$this->assertProcessOutputContains('Docker Compose project name : star_wars');
71-
$this->assertProcessOutputContains('Site local URL : http://star_wars.docker.amazee.io');
72-
$this->assertProcessOutputContains('Path to web root : /app/' . $webroot);
73-
$this->assertProcessOutputContains('DB host : database');
74-
$this->assertProcessOutputContains('DB username : drupal');
75-
$this->assertProcessOutputContains('DB password : drupal');
76-
$this->assertProcessOutputContains('DB port : 3306');
77-
$this->assertProcessOutputContains('DB port on host :');
63+
$this->cmd('ahoy info', [
64+
'* Project name : star_wars',
65+
'* Docker Compose project name : star_wars',
66+
'* Site local URL : http://star_wars.docker.amazee.io',
67+
'* Path to web root : /app/' . $webroot,
68+
'* DB host : database',
69+
'* DB username : drupal',
70+
'* DB password : drupal',
71+
'* DB port : 3306',
72+
'* DB port on host :',
73+
'* Solr URL on host :',
74+
'* Selenium VNC URL on host :',
75+
'* Mailhog URL : http://mailhog.docker.amazee.io/',
76+
"* Xdebug : Disabled ('ahoy debug' to enable)",
77+
'! Containers are not running.',
78+
]);
7879

7980
if (!empty($db_image)) {
8081
$this->assertProcessOutputContains('DB-in-image : ' . $db_image);
@@ -83,22 +84,14 @@ protected function stepAhoyInfo(string $webroot = 'web', string $db_image = ''):
8384
$this->assertProcessOutputNotContains('DB-in-image : ' . $db_image);
8485
}
8586

86-
$this->assertProcessOutputContains('Solr URL on host :');
87-
$this->assertProcessOutputContains('Selenium VNC URL on host :');
88-
$this->assertProcessOutputContains('Mailhog URL : http://mailhog.docker.amazee.io/');
89-
$this->assertProcessOutputContains("Xdebug : Disabled ('ahoy debug' to enable)");
90-
$this->assertProcessOutputNotContains('Containers are not running.');
91-
9287
$this->logStepFinish();
9388
}
9489

9590
protected function stepAhoyContainerLogs(): void {
9691
$this->logStepStart();
9792

9893
$this->logSubstep('Testing ahoy logs command');
99-
$this->processRun('ahoy logs');
100-
$this->assertProcessSuccessful();
101-
$this->assertProcessOutputNotContains('Containers are not running.');
94+
$this->cmd('ahoy logs', '! Containers are not running.');
10295

10396
$this->logStepFinish();
10497
}
@@ -107,9 +100,7 @@ protected function stepAhoyLogin(): void {
107100
$this->logStepStart();
108101

109102
$this->logSubstep('Testing ahoy login command');
110-
$this->processRun('ahoy login');
111-
$this->assertProcessSuccessful();
112-
$this->assertProcessOutputNotContains('Containers are not running.');
103+
$this->cmd('ahoy login', '! Containers are not running.');
113104

114105
$this->logStepFinish();
115106
}

.vortex/tests/phpunit/Traits/Steps/StepBuildTrait.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@ protected function stepBuild(string $webroot = 'web', array $env = []): void {
2121

2222
$this->logSubstep('Starting ahoy build');
2323

24-
$this->processRun(
25-
'ahoy build',
26-
inputs: ['y'],
27-
env: array_merge($this->getDefaultBuildEnv(), $env),
28-
timeout: 10 * 60,
29-
idle_timeout: 60
30-
);
31-
$this->logSubstep('Finished ahoy build');
32-
$this->assertProcessSuccessful();
24+
$this->cmd('ahoy build', txt: 'Finished ahoy build', inp: ['y'], env: array_merge($this->getDefaultBuildEnv(), $env), tio: 10 * 60, ito: 60);
3325
$this->syncToHost();
3426

3527
$this->logSubstep('Assert that lock files were created');
@@ -67,15 +59,14 @@ protected function stepBuildFailure(string $webroot = 'web', array $env = []): v
6759

6860
$this->logSubstep('Starting ahoy build (expecting failure)');
6961

70-
$this->processRun(
62+
$this->cmdFail(
7163
'ahoy build',
72-
inputs: ['y'],
64+
txt: 'Finished ahoy build (expected to fail)',
65+
inp: ['y'],
7366
env: array_merge($this->getDefaultBuildEnv(), $env),
74-
timeout: 10 * 60,
75-
idle_timeout: 60
67+
tio: 10 * 60,
68+
ito: 60
7669
);
77-
$this->logSubstep('Finished ahoy build (expected to fail)');
78-
$this->assertProcessFailed();
7970

8071
$this->logStepFinish();
8172
}

0 commit comments

Comments
 (0)