From 8462bed7820cecc23a0e0d64aa50db7be92272d9 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 9 Oct 2014 09:08:19 +0200 Subject: cleanup test method in appconfig class, add test for item serialization --- config/appconfig.php | 56 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'config') diff --git a/config/appconfig.php b/config/appconfig.php index 52e82dc25..3729e56b2 100644 --- a/config/appconfig.php +++ b/config/appconfig.php @@ -153,51 +153,65 @@ class AppConfig { } } - private function testDatabaseDependencies($databases, $databaseType) { - if(!in_array($databaseType, $databases)) { + + private function testDatabaseDependencies() { + if(array_key_exists('databases', $this->config)) { + $databases = $this->config['databases']; + $databaseType = $this->databaseType; + + if(!in_array($databaseType, $databases)) { return 'Database ' . $databaseType . ' not supported.' . 'App is only compatible with ' . implode(', ', $databases); - } else { - return ''; + } } + return ''; } - /** - * Validates all dependencies that the app has - * @throws DependencyException if one version is not satisfied - */ - public function testDependencies() { - $msg = ''; - - // test databases - if(array_key_exists('databases', $this->config)) { - $msg .= $this->testDatabaseDependencies( - $this->config['databases'], $this->databaseType - ); - } - // test dependencies + private function testPHPDependencies() { if(array_key_exists('dependencies', $this->config)) { $deps = $this->config['dependencies']; if (array_key_exists('php', $deps)) { - $msg .= $this->requireVersion($this->phpVersion, $deps['php'], + return $this->requireVersion($this->phpVersion, $deps['php'], 'PHP'); } + } + return ''; + } + + + private function testLibraryDependencies() { + if(array_key_exists('dependencies', $this->config)) { + + $deps = $this->config['dependencies']; + if (array_key_exists('libs', $deps)) { foreach ($deps['libs'] as $lib => $versions) { if(array_key_exists($lib, $this->installedExtensions)) { - $msg .= $this->requireVersion($this->installedExtensions[$lib], + return $this->requireVersion($this->installedExtensions[$lib], $versions, 'PHP extension ' . $lib); } else { - $msg .= 'PHP extension ' . $lib . ' required but not installed'; + return 'PHP extension ' . $lib . ' required but not installed'; } } } } + return ''; + } + + + /** + * Validates all dependencies that the app has + * @throws DependencyException if one version is not satisfied + */ + public function testDependencies() { + $msg = $this->testDatabaseDependencies(); + $msg .= $this->testPHPDependencies(); + $msg .= $this->testLibraryDependencies(); if($msg !== '') { throw new DependencyException($msg); -- cgit v1.2.3