mirror of
https://github.com/e107inc/e107.git
synced 2025-04-13 17:12:07 +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:
parent
ffadc38a96
commit
495145df61
@ -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.
|
||||
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.
|
||||
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:
|
||||
enabled:
|
||||
- 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
@ -1 +1 @@
|
||||
Subproject commit 986aabb062762638258215d30957dc0984de0923
|
||||
Subproject commit e045c6c91c6fc8c8e760ff501a2a7fe6c10404d3
|
@ -9,6 +9,8 @@ class cPanelDeployer
|
||||
protected $cPanel;
|
||||
protected $run_id;
|
||||
|
||||
protected $db_id;
|
||||
|
||||
protected $homedir;
|
||||
protected $docroot;
|
||||
protected $domain;
|
||||
@ -27,6 +29,23 @@ class cPanelDeployer
|
||||
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)
|
||||
{
|
||||
self::println();
|
||||
@ -124,7 +143,7 @@ class cPanelDeployer
|
||||
$cPanel = $this->cPanel;
|
||||
$username = &$this->credentials['username'];
|
||||
$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}\"…");
|
||||
$cPanel->uapi->Mysql->create_database(['name' => $db_id]);
|
||||
|
||||
|
@ -1,31 +1,20 @@
|
||||
<?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
|
||||
|
||||
class Acceptance extends \Codeception\Module
|
||||
class Acceptance extends Base
|
||||
{
|
||||
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();
|
||||
if ($retcode === true)
|
||||
{
|
||||
$url = $this->deployer->getUrl();
|
||||
$this->getModule('PhpBrowser')->_reconfigure(array('url' => $url));
|
||||
}
|
||||
}
|
||||
return parent::_beforeSuite($settings);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user