Skip to content

Commit

Permalink
fix gentle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelien-riv committed May 17, 2018
1 parent 9b34b27 commit 03216f3
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 26 deletions.
14 changes: 2 additions & 12 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace DBChecker;

use DBChecker\InputModules\AbstractDBAL;
use DBChecker\InputModules\InputModuleManager;
use DBChecker\modules\DataBase\DatabasesModule;
use DBChecker\modules\ModuleManager;
use Symfony\Component\Yaml\Yaml;

Expand All @@ -14,15 +11,8 @@ class Config

public function __construct($yamlPath)
{
$settings = Yaml::parseFile($yamlPath);

$this->moduleManager = new ModuleManager();

$this->moduleManager->loadModule(new InputModuleManager(), $settings);
foreach (ModuleManager::ENABLED_MODULES as $module)
{
$this->moduleManager->loadModule(new $module(), $settings);
}
$this->moduleManager->loadModules(Yaml::parseFile($yamlPath));
}

/**
Expand All @@ -35,6 +25,6 @@ public function getModuleWorkers()

public function getDBALs() : \Generator
{
return $this->moduleManager->getDatabaseModule()->getDBALs();
yield from $this->moduleManager->getDatabaseModule()->getDBALs();
}
}
1 change: 1 addition & 0 deletions src/InputModules/InputModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function getConfigTreeBuilder()
->addDefaultsIfNotSet()
->children()
->arrayNode('connections')
->isRequired()
->requiresAtLeastOneElement()
->arrayPrototype()
->ignoreExtraKeys(false)
Expand Down
4 changes: 4 additions & 0 deletions src/modules/DataIntegrityCheck/DataIntegrityCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class DataIntegrityCheck implements ModuleWorkerInterface
{
private $config;

/**
* DataIntegrityCheck constructor.
* @param ModuleInterface|DataIntegrityCheckModule $module
*/
public function __construct(ModuleInterface $module)
{
$this->config = $module->getConfig();
Expand Down
16 changes: 13 additions & 3 deletions src/modules/ModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
namespace DBChecker\modules;

use DBChecker\BaseModuleInterface;
use DBChecker\InputModules\InputModuleInterface;
use DBChecker\InputModules\InputModuleManager;
use DBChecker\ModuleInterface;
use DBChecker\modules\AnalyzeTableCheck\AnalyzeTableCheckModule;
use DBChecker\modules\DataBase\DatabasesModule;
use DBChecker\modules\DataIntegrityCheck\DataIntegrityCheckModule;
use DBChecker\modules\FileCheck\FileCheckModule;
use DBChecker\modules\FragmentationCheck\FragmentationCheckModule;
Expand Down Expand Up @@ -37,6 +35,14 @@ class ModuleManager
PwnedAccountsDetectModule::class
];

public function loadModules($settings)
{
foreach (static::ENABLED_MODULES as $module)
{
$this->loadModule(new $module(), $settings);
}
}

public function loadModule(BaseModuleInterface $module, $settings)
{
$moduleName = $module->getName();
Expand All @@ -50,6 +56,10 @@ public function loadModule(BaseModuleInterface $module, $settings)
$module->loadConfig($moduleSettings);
$this->modules[] = $module;
}
else if ($module instanceof InputModuleManager)
{
throw new \InvalidArgumentException("No input module has been defined");
}
}

public function getDatabaseModule() : InputModuleManager
Expand All @@ -61,7 +71,7 @@ public function getDatabaseModule() : InputModuleManager
return $module;
}
}
return null;
throw new \LogicException("This code shouldn't be reached");
}

public function getWorkers() : \Generator
Expand Down
5 changes: 5 additions & 0 deletions src/modules/SchemaIntegrityCheck/SchemaIntegrityCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

use DBChecker\InputModules\AbstractDBAL;
use DBChecker\ModuleInterface;
use DBChecker\modules\DataIntegrityCheck\DataIntegrityCheckModule;
use DBChecker\ModuleWorkerInterface;

class SchemaIntegrityCheck implements ModuleWorkerInterface
{
private $config;

/**
* SchemaIntegrityCheck constructor.
* @param ModuleInterface|DataIntegrityCheckModule $module
*/
public function __construct(ModuleInterface $module)
{
$this->config = $module->getConfig();
Expand Down
11 changes: 8 additions & 3 deletions tests/DatabaseUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace DBCheckerTests;

use DBChecker\DBAL\AbstractDBAL;
use DBChecker\InputModules\AbstractDBAL;
use DBChecker\InputModules\MySQL\MySQLDBAL;
use DBChecker\InputModules\SQLite\SQLiteDBAL;
use DBChecker\modules\ModuleManager;
Expand Down Expand Up @@ -32,10 +32,15 @@ public static function getMysqlConfig()
];
}

public function getPdo(ModuleManager $moduleManager, $index=0)
public function getDbal(ModuleManager $moduleManager, $index=0)
{
$dbals = iterator_to_array($moduleManager->getDatabaseModule()->getDBALs());
$dbal = $dbals[$index];
return $dbals[$index];
}

public function getPdo(ModuleManager $moduleManager, $index=0)
{
$dbal = $this->getDbal($moduleManager, $index);
$queries = $this->getAttributeValue($dbal, 'queries');
return $this->getAttributeValue($queries, 'pdo');
}
Expand Down
3 changes: 1 addition & 2 deletions tests/modules/MissingKeyDetect/MissingKeyDetectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public function tearDown()

private function init($dbIndex) : AbstractDBAL
{
$dbals = iterator_to_array($this->moduleManager->getDatabaseModule()->getDBALs());
$dbal = $dbals[$dbIndex];
$dbal = $this->getDbal($this->moduleManager, $dbIndex);
$queries = $this->getAttributeValue($dbal, 'queries');
$pdo = $this->getAttributeValue($queries, 'pdo');
$this->initDb($pdo);
Expand Down
3 changes: 1 addition & 2 deletions tests/modules/RelCheckTest/RelCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public function tearDown()

private function init($dbIndex)
{
$dbals = iterator_to_array($this->moduleManager->getDatabaseModule()->getDBALs());
$dbal = $dbals[$dbIndex];
$dbal = $this->getDbal($this->moduleManager, $dbIndex);
$queries = $this->getAttributeValue($dbal, 'queries');
$pdo = $this->getAttributeValue($queries, 'pdo');
$this->initDb($dbal, $pdo);
Expand Down
3 changes: 1 addition & 2 deletions tests/modules/SchemaIntegrityCheck/SchemaIntegrityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public function tearDown()

private function initDBal($dbIndex)
{
$dbals = iterator_to_array($this->moduleManager->getDatabaseModule()->getDBALs());
$dbal = $dbals[$dbIndex];
$dbal = $this->getDbal($this->moduleManager, $dbIndex);
$queries = $this->getAttributeValue($dbal, 'queries');
$pdo = $this->getAttributeValue($queries, 'pdo');
$pdo->exec("CREATE TABLE t1 (id INTEGER PRIMARY KEY, data VARCHAR(64));");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public function tearDown()

private function init($dbIndex)
{
$dbals = iterator_to_array($this->moduleManager->getDatabaseModule()->getDBALs());
$dbal = $dbals[$dbIndex];
$dbal = $this->getDbal($this->moduleManager, $dbIndex);
$queries = $this->getAttributeValue($dbal, 'queries');
$pdo = $this->getAttributeValue($queries, 'pdo');
$this->initDb($pdo);
Expand Down

0 comments on commit 03216f3

Please sign in to comment.