-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OXDEV-7248 Update tests to run with shop 8.0.x
- Loading branch information
Showing
19 changed files
with
241 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
tests/Codeception/Config/CodeceptionParametersProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\ModuleTemplate\Tests\Codeception\Config; | ||
|
||
|
||
use OxidEsales\Codeception\Module\Database; | ||
use OxidEsales\EshopCommunity\Internal\Framework\Configuration\DataObject\DatabaseConfiguration; | ||
use OxidEsales\EshopCommunity\Internal\Framework\Edition\Edition; | ||
use OxidEsales\EshopCommunity\Internal\Framework\Edition\EditionDirectoriesLocator; | ||
use OxidEsales\EshopCommunity\Internal\Framework\Env\DotenvLoader; | ||
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\DirectoryNotExistentException; | ||
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\ProjectDirectoriesLocator; | ||
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\ProjectRootLocator; | ||
use Symfony\Component\Filesystem\Path; | ||
|
||
class CodeceptionParametersProvider | ||
{ | ||
private DatabaseConfiguration $dbConfig; | ||
|
||
public function getParameters(): array | ||
{ | ||
$this->loadEnvironmentVariables(); | ||
|
||
$this->dbConfig = (new DatabaseConfiguration(getenv('OXID_DB_URL'))); | ||
return [ | ||
'SHOP_URL' => getenv('OXID_SHOP_BASE_URL'), | ||
'PROJECT_ROOT' => $this->getProjectRoot(), | ||
'VENDOR_PATH' => (new ProjectDirectoriesLocator())->getVendorPath(), | ||
'SOURCE_RELATIVE_PACKAGE_PATH' => $this->getSourceRelativePackagePath(), | ||
'DB_NAME' => $this->getDbName(), | ||
'DB_USERNAME' => $this->getDbUser(), | ||
'DB_PASSWORD' => $this->getDbPass(), | ||
'DB_HOST' => $this->getDbHost(), | ||
'DB_PORT' => $this->getDbPort(), | ||
'DUMP_PATH' => $this->getTestDataDumpFilePath(), | ||
'MODULE_DUMP_PATH' => $this->getCodeceptionSpecificFixtureFilePath(), | ||
'FIXTURES_PATH' => $this->getTestFixtureSqlFilePath(), | ||
'OUT_DIRECTORY' => (new ProjectDirectoriesLocator())->getOutPath(), | ||
'OUT_DIRECTORY_FIXTURES' => $this->getOutDirectoryFixturesPath(), | ||
'MYSQL_CONFIG_PATH' => $this->generateMysqlStarUpConfigurationFile(), | ||
'SELENIUM_SERVER_PORT' => getenv('SELENIUM_SERVER_PORT') ?: '4444', | ||
'SELENIUM_SERVER_HOST' => getenv('SELENIUM_SERVER_HOST') ?: 'selenium', | ||
'PHP_BIN' => (getenv('PHPBIN')) ?: 'php', | ||
'SCREEN_SHOT_URL' => getenv('CC_SCREEN_SHOTS_URL') ?: '', | ||
'BROWSER' => getenv('BROWSER_NAME') ?: 'chrome', | ||
'THEME_ID' => getenv('THEME_ID') ?: 'apex', | ||
'MAIL_HOST' => getenv('MAIL_HOST') ?: 'mailpit', | ||
'MAIL_WEB_PORT' => getenv('MAIL_WEB_PORT') ?: '8025', | ||
]; | ||
} | ||
|
||
private function getSourceRelativePackagePath(): string | ||
{ | ||
return(str_replace($this->getProjectRoot(), '..', __DIR__) . '/../../../'); | ||
} | ||
|
||
private function getCodeceptionSpecificFixtureFilePath(): string | ||
{ | ||
return Path::join(__DIR__, '../Support/Data', 'fixtures.sql'); | ||
} | ||
|
||
private function getTestDataDumpFilePath(): string | ||
{ | ||
return Path::join( | ||
$this->getShopTestPath(), | ||
'/Codeception/Support/_generated/shop-dump.sql' | ||
); | ||
} | ||
|
||
private function getTestFixtureSqlFilePath(): string | ||
{ | ||
return Path::join( | ||
$this->getShopTestPath(), | ||
'/Codeception/Support/Data/dump.sql', | ||
); | ||
} | ||
|
||
private function getOutDirectoryFixturesPath(): string | ||
{ | ||
return Path::join( | ||
$this->getShopTestPath(), | ||
'/Codeception/Support/Data/out', | ||
); | ||
} | ||
|
||
private function getShopTestPath(): string | ||
{ | ||
try { | ||
$testsPath = Path::join( | ||
(new EditionDirectoriesLocator())->getEditionRootPath(Edition::Enterprise), | ||
'Tests' | ||
); | ||
} catch (DirectoryNotExistentException) { | ||
$testsPath = Path::join( | ||
$this->getProjectRoot(), | ||
'tests' | ||
); | ||
} | ||
return $testsPath; | ||
} | ||
|
||
private function generateMysqlStarUpConfigurationFile(): string | ||
{ | ||
return Database::generateStartupOptionsFile( | ||
$this->getDbUser(), | ||
$this->getDbPass(), | ||
$this->getDbHost(), | ||
$this->getDbPort(), | ||
); | ||
} | ||
|
||
private function getDbName(): string | ||
{ | ||
return getenv('DB_NAME') ?: $this->dbConfig->getName(); | ||
} | ||
|
||
private function getDbUser(): string | ||
{ | ||
return getenv('DB_USERNAME') ?: $this->dbConfig->getUser(); | ||
} | ||
|
||
private function getDbPass(): string | ||
{ | ||
return getenv('DB_PASSWORD') ?: $this->dbConfig->getPass(); | ||
} | ||
|
||
private function getDbHost(): string | ||
{ | ||
return getenv('DB_HOST') ?: $this->dbConfig->getHost(); | ||
} | ||
|
||
private function getDbPort(): int | ||
{ | ||
return (int) getenv('DB_PORT') ?: $this->dbConfig->getPort(); | ||
} | ||
|
||
private function loadEnvironmentVariables(): void | ||
{ | ||
(new DotenvLoader($this->getProjectRoot()))->loadEnvironmentVariables(); | ||
} | ||
|
||
private function getProjectRoot(): string | ||
{ | ||
return (new ProjectRootLocator())->getProjectRoot(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.