88use AlexSkrypnyk \PhpunitHelpers \Traits \AssertArrayTrait ;
99use AlexSkrypnyk \PhpunitHelpers \Traits \EnvTrait ;
1010use AlexSkrypnyk \PhpunitHelpers \Traits \LocationsTrait ;
11+ use AlexSkrypnyk \PhpunitHelpers \Traits \LoggerTrait ;
1112use AlexSkrypnyk \PhpunitHelpers \Traits \ProcessTrait ;
1213use AlexSkrypnyk \PhpunitHelpers \UnitTestCase ;
1314use DrevOps \Vortex \Tests \Traits \AssertProjectFilesTrait ;
1415use DrevOps \Vortex \Tests \Traits \GitTrait ;
15- use AlexSkrypnyk \PhpunitHelpers \Traits \LoggerTrait ;
1616use DrevOps \Vortex \Tests \Traits \Steps \StepBuildTrait ;
17- use DrevOps \Vortex \Tests \Traits \Steps \StepDownloadDbTrait ;
17+ use DrevOps \Vortex \Tests \Traits \Steps \StepDatabaseTrait ;
1818use 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 ;
2120use Symfony \Component \Process \Process ;
2221
2322/**
2423 * Base class for functional tests.
2524 */
2625class 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}
0 commit comments