-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbe2d1c
commit 89c9922
Showing
12 changed files
with
372 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Yireo\IntegrationTestHelper\Check; | ||
|
||
use Cm_Cache_Backend_Redis; | ||
use Yireo\IntegrationTestHelper\Utilities\CurrentInstallConfig; | ||
use Zend_Cache_Exception; | ||
|
||
class RedisCheck | ||
{ | ||
private CurrentInstallConfig $currentInstallConfig; | ||
|
||
/** | ||
* @param CurrentInstallConfig $currentInstallConfig | ||
*/ | ||
public function __construct( | ||
CurrentInstallConfig $currentInstallConfig | ||
) { | ||
$this->currentInstallConfig = $currentInstallConfig; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function checkRedisConnection(): bool | ||
{ | ||
$config = $this->currentInstallConfig->getValues(); | ||
$server = $config['cache-backend-redis-server']; | ||
$port = $config['cache-backend-redis-port']; | ||
$dbName = $config['cache-backend-redis-db']; | ||
|
||
try { | ||
$redis = new Cm_Cache_Backend_Redis([ | ||
'server' => $server, | ||
'port' => $port, | ||
'database' => $dbName | ||
]); | ||
} catch (Zend_Cache_Exception $e) { | ||
return false; | ||
} | ||
|
||
$info = $redis->getInfo(); | ||
return !empty($info); | ||
} | ||
} |
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,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Yireo\IntegrationTestHelper\Check; | ||
|
||
use GuzzleHttp\Client; | ||
use Yireo\IntegrationTestHelper\Utilities\CurrentInstallConfig; | ||
|
||
class SearchEngineCheck | ||
{ | ||
private CurrentInstallConfig $currentInstallConfig; | ||
private Client $httpClient; | ||
|
||
public function __construct( | ||
CurrentInstallConfig $currentInstallConfig, | ||
Client $httpClient | ||
) { | ||
$this->currentInstallConfig = $currentInstallConfig; | ||
$this->httpClient = $httpClient; | ||
} | ||
|
||
public function checkSearchEngineConnection(): bool | ||
{ | ||
$config = $this->currentInstallConfig->getValues(); | ||
$response = $this->httpClient->get($config['elasticsearch-host'].':'.$config['elasticsearch-port']); | ||
return $response->getStatusCode() === 200; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Yireo\IntegrationTestHelper\Utilities; | ||
|
||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\Console\Cli; | ||
use Magento\Framework\Filesystem; | ||
use Magento\Framework\Filesystem\DriverInterface; | ||
use Magento\Setup\Console\Command\InstallCommand; | ||
use Magento\Setup\Model\ConfigModel; | ||
use Magento\Setup\Model\SearchConfigOptionsList; | ||
|
||
class CurrentInstallConfig | ||
{ | ||
private DirectoryList $directoryList; | ||
private DefaultInstallConfig $defaultInstallConfig; | ||
private DriverInterface $fileDriver; | ||
|
||
public function __construct( | ||
DirectoryList $directoryList, | ||
DefaultInstallConfig $defaultInstallConfig, | ||
Filesystem $filesystem | ||
) { | ||
$this->directoryList = $directoryList; | ||
$this->defaultInstallConfig = $defaultInstallConfig; | ||
$this->fileDriver = $filesystem->getDirectoryWrite(DirectoryList::PUB)->getDriver(); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getValues(): array | ||
{ | ||
$integrationTestsDir = $this->directoryList->getRoot() . '/dev/tests/integration/'; | ||
|
||
$testsBaseDir = $integrationTestsDir; | ||
$autoloadWrapper = \Magento\Framework\Autoload\AutoloaderRegistry::getAutoloader(); | ||
|
||
$autoloadWrapper->addPsr4('Magento\\TestFramework\\', "{$testsBaseDir}/framework/Magento/TestFramework/"); | ||
$autoloadWrapper->addPsr4('Magento\\', "{$testsBaseDir}/testsuite/Magento/"); | ||
|
||
$installConfig = $integrationTestsDir . '/etc/install-config-mysql.php'; | ||
if (!$this->fileDriver->isExists($installConfig)) { | ||
$installConfig = $installConfig . '.dist'; | ||
} | ||
|
||
$values = $this->defaultInstallConfig->getValues(); | ||
$values = array_merge($values, include($installConfig)); | ||
return $values; | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* @return string|null | ||
*/ | ||
public function getValue(string $key) | ||
{ | ||
$values = $this->getValues(); | ||
if (isset($values[$key])) { | ||
return $values[$key]; | ||
} | ||
|
||
return null; | ||
} | ||
} |
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,33 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Yireo\IntegrationTestHelper\Utilities; | ||
|
||
use Magento\TestFramework\Bootstrap; | ||
|
||
class DefaultInstallConfig | ||
{ | ||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getValues(): array | ||
{ | ||
return [ | ||
'db-host' => 'localhost', | ||
'db-user' => 'root', | ||
'db-password' => 'root', | ||
'db-name' => 'magento', | ||
'db-prefix' => '', | ||
'search-engine' => 'elasticsearch7', | ||
'elasticsearch-host' => 'localhost', | ||
'elasticsearch-port' => '9200', | ||
'backend-frontname' => 'backend', | ||
'admin-user' => Bootstrap::ADMIN_NAME, | ||
'admin-password' => Bootstrap::ADMIN_PASSWORD, | ||
'admin-email' => Bootstrap::ADMIN_EMAIL, | ||
'admin-firstname' => Bootstrap::ADMIN_FIRSTNAME, | ||
'admin-lastname' => Bootstrap::ADMIN_LASTNAME, | ||
'allow-parallel-generation' => null, | ||
'skip-db-validation' => null | ||
]; | ||
} | ||
} |
Oops, something went wrong.