mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 20:30:39 +02:00
Added automatic database support to all suites
Refactored by extracting code common to all suites to \Helper\Base New \Helper\DelayedDb helper to delay initialization so that a new DSN, username, and password can be loaded in dynamically for automatic database provisioning. Should still be compatible with manual database information in codeception.yml
This commit is contained in:
@@ -48,4 +48,4 @@ If you do not have a cPanel account that meets the requirements, you can run acc
|
|||||||
4. Grant the MySQL/MariaDB user `ALL PRIVILEGES` on the MySQL/MariaDB database.
|
4. Grant the MySQL/MariaDB user `ALL PRIVILEGES` on the MySQL/MariaDB database.
|
||||||
5. Put the app on the web server and note its URL.
|
5. Put the app on the web server and note its URL.
|
||||||
6. Write the URL to `tests/acceptance.suite.yml` in your copy of this repository where the `url` setting for the `PhpBrowser` module is.
|
6. Write the URL to `tests/acceptance.suite.yml` in your copy of this repository where the `url` setting for the `PhpBrowser` module is.
|
||||||
7. **TODO:** Manual database credentials are not supported yet.
|
7. Write the database configuration to `codeception.yml` in your copy of this repository under the `\Helper\DelayedDb` module.
|
||||||
|
@@ -12,3 +12,9 @@ params:
|
|||||||
extensions:
|
extensions:
|
||||||
enabled:
|
enabled:
|
||||||
- Codeception\Extension\RunFailed
|
- Codeception\Extension\RunFailed
|
||||||
|
modules:
|
||||||
|
enabled:
|
||||||
|
- \Helper\DelayedDb:
|
||||||
|
dsn: 'mysql:host=set-this-if-running-tests-manually.local;dbname=e107'
|
||||||
|
user: 'root'
|
||||||
|
password: ''
|
||||||
|
2
e107
2
e107
Submodule e107 updated: 986aabb062...e045c6c91c
@@ -9,6 +9,8 @@ class cPanelDeployer
|
|||||||
protected $cPanel;
|
protected $cPanel;
|
||||||
protected $run_id;
|
protected $run_id;
|
||||||
|
|
||||||
|
protected $db_id;
|
||||||
|
|
||||||
protected $homedir;
|
protected $homedir;
|
||||||
protected $docroot;
|
protected $docroot;
|
||||||
protected $domain;
|
protected $domain;
|
||||||
@@ -27,6 +29,23 @@ class cPanelDeployer
|
|||||||
return "http://".$this->domain."/".$this->run_id."/";
|
return "http://".$this->domain."/".$this->run_id."/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDsn()
|
||||||
|
{
|
||||||
|
$hostname = $this->credentials['hostname'];
|
||||||
|
$db_id = $this->db_id;
|
||||||
|
return "mysql:host=${hostname};dbname=${db_id}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDbUsername()
|
||||||
|
{
|
||||||
|
return $this->db_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDbPassword()
|
||||||
|
{
|
||||||
|
return $this->run_id;
|
||||||
|
}
|
||||||
|
|
||||||
public function start($components = self::DEFAULT_COMPONENTS)
|
public function start($components = self::DEFAULT_COMPONENTS)
|
||||||
{
|
{
|
||||||
self::println();
|
self::println();
|
||||||
@@ -124,7 +143,7 @@ class cPanelDeployer
|
|||||||
$cPanel = $this->cPanel;
|
$cPanel = $this->cPanel;
|
||||||
$username = &$this->credentials['username'];
|
$username = &$this->credentials['username'];
|
||||||
$run_id = &$this->run_id;
|
$run_id = &$this->run_id;
|
||||||
$db_id = "${username}_${run_id}";
|
$this->db_id = $db_id = "${username}_${run_id}";
|
||||||
self::println("Creating new MySQL database \"${db_id}\"…");
|
self::println("Creating new MySQL database \"${db_id}\"…");
|
||||||
$cPanel->uapi->Mysql->create_database(['name' => $db_id]);
|
$cPanel->uapi->Mysql->create_database(['name' => $db_id]);
|
||||||
|
|
||||||
|
@@ -1,31 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Helper;
|
namespace Helper;
|
||||||
include_once(__DIR__ . "/../../../lib/deployers/cpanel_deployer.php");
|
|
||||||
|
|
||||||
// here you can define custom actions
|
// here you can define custom actions
|
||||||
// all public methods declared in helper class will be available in $I
|
// all public methods declared in helper class will be available in $I
|
||||||
|
|
||||||
class Acceptance extends \Codeception\Module
|
class Acceptance extends Base
|
||||||
{
|
{
|
||||||
protected $deployer;
|
protected $deployer_components = ['db', 'fs'];
|
||||||
|
|
||||||
public function _beforeSuite($settings = array())
|
public function _beforeSuite($settings = array())
|
||||||
{
|
{
|
||||||
$secrets = $settings['secrets'];
|
return parent::_beforeSuite($settings);
|
||||||
if ($secrets['cpanel']['enabled'] === '1')
|
|
||||||
{
|
|
||||||
$this->deployer = new \cPanelDeployer($secrets['cpanel']);
|
|
||||||
$retcode = $this->deployer->start();
|
|
||||||
if ($retcode === true)
|
|
||||||
{
|
|
||||||
$url = $this->deployer->getUrl();
|
|
||||||
$this->getModule('PhpBrowser')->_reconfigure(array('url' => $url));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function _afterSuite()
|
public function _afterSuite()
|
||||||
{
|
{
|
||||||
$this->deployer->stop();
|
return parent::_afterSuite();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
56
tests/_support/Helper/Base.php
Normal file
56
tests/_support/Helper/Base.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
namespace Helper;
|
||||||
|
include_once(__DIR__ . "/../../../lib/deployers/cpanel_deployer.php");
|
||||||
|
|
||||||
|
// here you can define custom actions
|
||||||
|
// all public methods declared in helper class will be available in $I
|
||||||
|
|
||||||
|
abstract class Base extends \Codeception\Module
|
||||||
|
{
|
||||||
|
protected $deployer;
|
||||||
|
protected $deployer_components = ['db', 'fs'];
|
||||||
|
|
||||||
|
public function _beforeSuite($settings = array())
|
||||||
|
{
|
||||||
|
$secrets = $settings['secrets'];
|
||||||
|
if ($secrets['cpanel']['enabled'] === '1')
|
||||||
|
{
|
||||||
|
$this->deployer = new \cPanelDeployer($secrets['cpanel']);
|
||||||
|
$retcode = $this->deployer->start($this->deployer_components);
|
||||||
|
if ($retcode === true)
|
||||||
|
{
|
||||||
|
$this->_callbackDeployerStarted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function _afterSuite()
|
||||||
|
{
|
||||||
|
$this->deployer->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _callbackDeployerStarted()
|
||||||
|
{
|
||||||
|
foreach ($this->deployer_components as $component)
|
||||||
|
{
|
||||||
|
$method = "_reconfigure_${component}";
|
||||||
|
$this->$method();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _reconfigure_fs()
|
||||||
|
{
|
||||||
|
$url = $this->deployer->getUrl();
|
||||||
|
$this->getModule('PhpBrowser')->_reconfigure(array('url' => $url));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _reconfigure_db()
|
||||||
|
{
|
||||||
|
$Db_config = array();
|
||||||
|
$Db_config['dsn'] = $this->deployer->getDsn();
|
||||||
|
$Db_config['user'] = $this->deployer->getDbUsername();
|
||||||
|
$Db_config['password'] = $this->deployer->getDbPassword();
|
||||||
|
$this->getModule('\Helper\DelayedDb')->_reconfigure($Db_config);
|
||||||
|
$this->getModule('\Helper\DelayedDb')->_delayedInitialize();
|
||||||
|
}
|
||||||
|
}
|
20
tests/_support/Helper/DelayedDb.php
Normal file
20
tests/_support/Helper/DelayedDb.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace Helper;
|
||||||
|
|
||||||
|
// here you can define custom actions
|
||||||
|
// all public methods declared in helper class will be available in $I
|
||||||
|
|
||||||
|
class DelayedDb extends \Codeception\Module\Db
|
||||||
|
{
|
||||||
|
protected $requiredFields = [];
|
||||||
|
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
// Noop
|
||||||
|
}
|
||||||
|
|
||||||
|
public function _delayedInitialize()
|
||||||
|
{
|
||||||
|
return parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user