Skip to content

Commit 0aa4a6e

Browse files
committed
Removed duplicated BDD tests.
1 parent 48b6ff7 commit 0aa4a6e

11 files changed

Lines changed: 207 additions & 269 deletions

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

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,30 @@
88
use AlexSkrypnyk\PhpunitHelpers\Traits\AssertArrayTrait;
99
use AlexSkrypnyk\PhpunitHelpers\Traits\EnvTrait;
1010
use AlexSkrypnyk\PhpunitHelpers\Traits\LocationsTrait;
11+
use AlexSkrypnyk\PhpunitHelpers\Traits\LoggerTrait;
1112
use AlexSkrypnyk\PhpunitHelpers\Traits\ProcessTrait;
1213
use AlexSkrypnyk\PhpunitHelpers\UnitTestCase;
1314
use DrevOps\Vortex\Tests\Traits\AssertProjectFilesTrait;
1415
use DrevOps\Vortex\Tests\Traits\GitTrait;
15-
use AlexSkrypnyk\PhpunitHelpers\Traits\LoggerTrait;
1616
use DrevOps\Vortex\Tests\Traits\Steps\StepBuildTrait;
17-
use DrevOps\Vortex\Tests\Traits\Steps\StepDownloadDbTrait;
17+
use DrevOps\Vortex\Tests\Traits\Steps\StepDatabaseTrait;
1818
use DrevOps\Vortex\Tests\Traits\Steps\StepPrepareSutTrait;
19-
use DrevOps\Vortex\Tests\Traits\Steps\StepTestBddAllTrait;
20-
use DrevOps\Vortex\Tests\Traits\Steps\StepTestBddTrait;
19+
use DrevOps\Vortex\Tests\Traits\Steps\StepTestTrait;
2120
use Symfony\Component\Process\Process;
2221

2322
/**
2423
* Base class for functional tests.
2524
*/
2625
class FunctionalTestCase extends UnitTestCase {
2726

27+
/**
28+
* URL to the test demo database.
29+
*
30+
* Tests use demo database and 'ahoy download-db' command, so we need
31+
* to set the CURL DB to test DB.
32+
*/
33+
const VORTEX_INSTALLER_DEMO_DB_TEST = 'https://github.com/drevops/vortex/releases/download/25.4.0/db_d11_2.test.sql';
34+
2835
use AssertArrayTrait;
2936
use AssertProjectFilesTrait;
3037
use EnvTrait;
@@ -35,10 +42,9 @@ class FunctionalTestCase extends UnitTestCase {
3542
ProcessTrait::processRun as traitProcessRun;
3643
}
3744
use StepBuildTrait;
38-
use StepDownloadDbTrait;
3945
use StepPrepareSutTrait;
40-
use StepTestBddAllTrait;
41-
use StepTestBddTrait;
46+
use StepTestTrait;
47+
use StepDatabaseTrait;
4248

4349
protected function setUp(): void {
4450
self::locationsInit(File::cwd() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..');
@@ -165,4 +171,70 @@ public function volumesMounted(): bool {
165171
return getenv('VORTEX_DEV_VOLUMES_SKIP_MOUNT') != 1;
166172
}
167173

174+
protected function trimFile(string $file): void {
175+
$content = File::read($file);
176+
$lines = explode("\n", $content);
177+
// Remove last line.
178+
array_pop($lines);
179+
File::dump($file, implode("\n", $lines));
180+
}
181+
182+
protected function stepWarmCaches(): void {
183+
$this->logSubstep('Warming up caches');
184+
$this->cmd('ahoy drush cr');
185+
$this->cmd('ahoy cli curl -- -sSL -o /dev/null -w "%{http_code}" http://nginx:8080 | grep -q 200');
186+
}
187+
188+
protected function addVarToFile(string $file, string $var, string $value): void {
189+
// Backup original file first.
190+
$this->backupFile($file);
191+
$content = File::read($file);
192+
$content .= sprintf('%s%s=%s%s', PHP_EOL, $var, $value, PHP_EOL);
193+
File::dump($file, $content);
194+
}
195+
196+
protected function backupFile(string $file): void {
197+
$backup_dir = '/tmp/bkp';
198+
if (!is_dir($backup_dir)) {
199+
mkdir($backup_dir, 0755, TRUE);
200+
}
201+
File::copy($file, $backup_dir . '/' . basename($file));
202+
}
203+
204+
protected function restoreFile(string $file): void {
205+
$backup_file = '/tmp/bkp/' . basename($file);
206+
if (file_exists($backup_file)) {
207+
File::copy($backup_file, $file);
208+
}
209+
}
210+
211+
protected function createDevelopmentSettings(string $webroot = 'web'): void {
212+
File::copy($webroot . '/sites/default/example.settings.local.php', $webroot . '/sites/default/settings.local.php');
213+
// Assert manually created local settings file exists.
214+
$this->assertFileExists($webroot . '/sites/default/settings.local.php');
215+
216+
File::copy($webroot . '/sites/default/example.services.local.yml', $webroot . '/sites/default/services.local.yml');
217+
// Assert manually created local services file exists.
218+
$this->assertFileExists($webroot . '/sites/default/services.local.yml');
219+
}
220+
221+
protected function removeDevelopmentSettings(string $webroot = 'web'): void {
222+
File::remove([
223+
$webroot . '/sites/default/settings.local.php',
224+
$webroot . '/sites/default/services.local.yml',
225+
]);
226+
$this->assertFileDoesNotExist($webroot . '/sites/default/settings.local.php');
227+
$this->assertFileDoesNotExist($webroot . '/sites/default/services.local.yml');
228+
}
229+
230+
protected function assertFilesPresent(string $webroot): void {
231+
// Use existing method from base class with correct signature.
232+
$this->assertCommonFilesPresent($webroot);
233+
}
234+
235+
protected function assertGitRepo(): void {
236+
// @todp Use gitAssertIsRepository().
237+
$this->assertDirectoryExists('.git');
238+
}
239+
168240
}

.vortex/tests/phpunit/Functional/WorkflowInstallDbTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
use DrevOps\Vortex\Tests\Traits\Steps\StepEnvironmentTrait;
1010
use DrevOps\Vortex\Tests\Traits\Steps\StepFrontendTrait;
1111
use DrevOps\Vortex\Tests\Traits\Steps\StepServicesTrait;
12-
use DrevOps\Vortex\Tests\Traits\Steps\StepTestingTrait;
12+
use DrevOps\Vortex\Tests\Traits\Steps\StepTestTrait;
13+
use DrevOps\Vortex\Tests\Traits\Steps\StepLintTrait;
1314

1415
/**
1516
* Tests DB-driven workflow.
@@ -20,8 +21,9 @@ class WorkflowInstallDbTest extends FunctionalTestCase {
2021
use StepDatabaseTrait;
2122
use StepEnvironmentTrait;
2223
use StepFrontendTrait;
24+
use StepLintTrait;
2325
use StepServicesTrait;
24-
use StepTestingTrait;
26+
use StepTestTrait;
2527

2628
protected function setUp(): void {
2729
parent::setUp();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public function testIdempotence(): void {
3434
$this->stepBuild();
3535
$this->assertFilesTrackedInGit();
3636

37-
$this->stepTestBdd();
37+
$this->stepAhoyTestBddFast();
3838

3939
$this->logSubstep('Re-build project to check that the results are identical.');
4040
$this->stepBuild();
4141
$this->assertFilesTrackedInGit(skip_commit: TRUE);
4242

4343
$this->logSubstep('Run BDD tests again on re-built project');
44-
$this->stepTestBdd();
44+
$this->stepAhoyTestBddFast();
4545
}
4646

4747
/**
@@ -101,7 +101,7 @@ public function testDockerComposeNoAhoy(): void {
101101

102102
$this->assertFilesTrackedInGit();
103103

104-
$this->stepTestBdd();
104+
$this->stepAhoyTestBdd();
105105
}
106106

107107
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111
*/
1212
trait StepDatabaseTrait {
1313

14+
protected function stepDownloadDb(): void {
15+
$this->logStepStart();
16+
17+
File::remove('.data/db.sql');
18+
$this->assertFileDoesNotExist('.data/db.sql', 'File .data/db.sql should not exist before downloading the database.');
19+
20+
$this->logSubstep('Downloading demo database from ' . static::VORTEX_INSTALLER_DEMO_DB_TEST);
21+
$this->cmd('ahoy download-db', env: [
22+
'VORTEX_DB_DOWNLOAD_URL' => static::VORTEX_INSTALLER_DEMO_DB_TEST,
23+
]);
24+
25+
$this->assertFileExists('.data/db.sql', 'File .data/db.sql should exist after downloading the database.');
26+
27+
$this->logStepFinish();
28+
}
29+
1430
protected function stepAhoyExportDb(string $filename = ''): void {
1531
$this->logStepStart();
1632

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

Lines changed: 0 additions & 38 deletions
This file was deleted.

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

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -202,55 +202,4 @@ protected function stepAhoyResetHard(string $webroot = 'web'): void {
202202
$this->logStepFinish();
203203
}
204204

205-
protected function addVarToFile(string $file, string $var, string $value): void {
206-
// Backup original file first.
207-
$this->backupFile($file);
208-
$content = File::read($file);
209-
$content .= sprintf('%s%s=%s%s', PHP_EOL, $var, $value, PHP_EOL);
210-
File::dump($file, $content);
211-
}
212-
213-
protected function backupFile(string $file): void {
214-
$backup_dir = '/tmp/bkp';
215-
if (!is_dir($backup_dir)) {
216-
mkdir($backup_dir, 0755, TRUE);
217-
}
218-
File::copy($file, $backup_dir . '/' . basename($file));
219-
}
220-
221-
protected function restoreFile(string $file): void {
222-
$backup_file = '/tmp/bkp/' . basename($file);
223-
if (file_exists($backup_file)) {
224-
File::copy($backup_file, $file);
225-
}
226-
}
227-
228-
protected function createDevelopmentSettings(string $webroot = 'web'): void {
229-
File::copy($webroot . '/sites/default/example.settings.local.php', $webroot . '/sites/default/settings.local.php');
230-
// Assert manually created local settings file exists.
231-
$this->assertFileExists($webroot . '/sites/default/settings.local.php');
232-
233-
File::copy($webroot . '/sites/default/example.services.local.yml', $webroot . '/sites/default/services.local.yml');
234-
// Assert manually created local services file exists.
235-
$this->assertFileExists($webroot . '/sites/default/services.local.yml');
236-
}
237-
238-
protected function removeDevelopmentSettings(string $webroot = 'web'): void {
239-
File::remove([
240-
$webroot . '/sites/default/settings.local.php',
241-
$webroot . '/sites/default/services.local.yml',
242-
]);
243-
$this->assertFileDoesNotExist($webroot . '/sites/default/settings.local.php');
244-
$this->assertFileDoesNotExist($webroot . '/sites/default/services.local.yml');
245-
}
246-
247-
protected function assertFilesPresent(string $webroot): void {
248-
// Use existing method from base class with correct signature.
249-
$this->assertCommonFilesPresent($webroot);
250-
}
251-
252-
protected function assertGitRepo(): void {
253-
$this->assertDirectoryExists('.git');
254-
}
255-
256205
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DrevOps\Vortex\Tests\Traits\Steps;
6+
7+
use AlexSkrypnyk\File\File;
8+
9+
/**
10+
* Provides lint operation steps.
11+
*/
12+
trait StepLintTrait {
13+
14+
protected function stepAhoyLint(string $webroot = 'web'): void {
15+
$this->logStepStart();
16+
17+
$this->logSubstep('Assert that lint works');
18+
$this->cmd('ahoy lint', tio: 120, ito: 90);
19+
20+
$this->stepAhoyLintBe($webroot);
21+
$this->stepAhoyLintFe($webroot);
22+
$this->stepAhoyLintTest();
23+
24+
$this->logStepFinish();
25+
}
26+
27+
protected function stepAhoyLintBe(string $webroot = 'web'): void {
28+
$this->logStepStart();
29+
30+
$this->logSubstep('Assert that BE lint failure works');
31+
File::dump($webroot . '/modules/custom/sw_base/sw_base.module', File::read($webroot . '/modules/custom/sw_base/sw_base.module') . '$a=1;');
32+
$this->syncToContainer();
33+
$this->cmdFail('ahoy lint-be', tio: 120, ito: 90);
34+
35+
$this->logSubstep('Assert that BE lint tool disabling works');
36+
// Replace with some valid XML element to avoid XML parsing errors.
37+
File::replaceContentInFile('phpcs.xml', '<file>' . $webroot . '/modules/custom</file>', '<exclude-pattern>somefile</exclude-pattern>');
38+
$this->syncToContainer();
39+
$this->cmd('ahoy lint-be', tio: 120, ito: 90);
40+
41+
// @todo Add restoring of the file.
42+
$this->logStepFinish();
43+
}
44+
45+
protected function stepAhoyLintFe(string $webroot = 'web'): void {
46+
$this->logStepStart();
47+
48+
$this->logSubstep('Assert that FE lint failure works for npm lint');
49+
File::dump($webroot . '/themes/custom/star_wars/scss/components/_test.scss', '.abc{margin: 0px;}');
50+
$this->syncToContainer();
51+
$this->cmdFail('ahoy lint-fe', tio: 120, ito: 90);
52+
File::remove($webroot . '/themes/custom/star_wars/scss/components/_test.scss');
53+
$this->cmd('ahoy cli rm -f ' . $webroot . '/themes/custom/star_wars/scss/components/_test.scss');
54+
$this->syncToContainer();
55+
56+
$this->logSubstep('Assert that FE lint failure works for Twig CS Fixer');
57+
File::dump($webroot . '/modules/custom/sw_base/templates/block/test1.twig', "{{ set a='a' }}");
58+
File::dump($webroot . '/themes/custom/star_wars/templates/block/test2.twig', "{{ set b='b' }}");
59+
$this->syncToContainer();
60+
61+
$this->cmdFail('ahoy lint-fe', tio: 120, ito: 90);
62+
63+
File::remove([
64+
$webroot . '/modules/custom/sw_base/templates/block/test1.twig',
65+
$webroot . '/themes/custom/star_wars/templates/block/test2.twig',
66+
]);
67+
$this->cmd('ahoy cli rm -f ' . $webroot . '/modules/custom/sw_base/templates/block/test1.twig');
68+
$this->cmd('ahoy cli rm -f ' . $webroot . '/themes/custom/star_wars/templates/block/test2.twig');
69+
$this->syncToContainer();
70+
71+
$this->logStepFinish();
72+
}
73+
74+
protected function stepAhoyLintTest(): void {
75+
$this->logStepStart();
76+
77+
$this->logSubstep('Assert that Test lint works for Gherkin Lint');
78+
$this->cmd('ahoy lint-tests');
79+
80+
$this->logSubstep('Assert that Test lint failure works for Gherkin Lint');
81+
File::dump('tests/behat/features/test.feature', 'Feature:');
82+
$this->syncToContainer();
83+
$this->cmdFail('ahoy lint-tests');
84+
File::remove('tests/behat/features/test.feature');
85+
$this->cmd('ahoy cli rm -f tests/behat/features/test.feature');
86+
$this->syncToContainer();
87+
88+
$this->logStepFinish();
89+
}
90+
91+
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
*/
1212
trait StepPrepareSutTrait {
1313

14-
15-
use StepDownloadDbTrait;
16-
1714
protected function stepPrepareSut(): void {
1815
$this->logStepStart();
1916

0 commit comments

Comments
 (0)