3 namespace Org\Mxchange\CoreFramework\Tests\Filter\Configuration\Classes;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Filter\Filterable;
8 use Org\Mxchange\CoreFramework\Request\Requestable;
9 use Org\Mxchange\CoreFramework\Response\Responseable;
10 use Org\Mxchange\CoreFramework\Tests\Filter\BaseTestsFilter;
13 use \InvalidArgumentException;
16 * A LoadableClasses filter for tests
18 * @author Roland Haeder <webmaster@ship-simu.org>
20 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
21 * @license GNU GPL 3.0 or any newer version
22 * @link http://www.ship-simu.org
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 class TestConfigurationLoadableClassesFilter extends BaseTestsFilter implements Filterable {
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
49 * Creates an instance of this filter class
51 * @return $filterInstance An instance of this filter class
53 public final static function createTestConfigurationLoadableClassesFilter () {
55 $filterInstance = new TestConfigurationLoadableClassesFilter();
57 // Return the instance
58 return $filterInstance;
62 * Executes the filter with given request and response objects
64 * @param $requestInstance An instance of a class with an Requestable interface
65 * @param $responseInstance An instance of a class with an Responseable interface
69 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
74 // Loop through all configuration keys
75 foreach (FrameworkBootstrap::getConfigurationInstance()->getConfigurationArray() as $configKey => $configValue) {
76 // Key must end with _class
77 if (substr($configKey, -6, 6) != '_class') {
83 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Testing configKey=%s,configValue[%s]=%s', $configKey, gettype($configValue), $configValue));
85 // This may throw exceptions
87 // Is the config entry valid and class is there?
88 if (!is_string($configKey)) {
90 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('configKey=%s has unexpected type "%s". FAILED', $configKey, gettype($configKey)));
95 } elseif (!class_exists($configValue)) {
97 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Class "%s" not found. FAILED', $configValue));
103 } catch (InvalidArgumentException $e) {
104 // Maybe not conform?
105 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Class "%s" failed to load. Message: "%s"', $configValue, $e->getMessage()));
107 // Skip further tests
112 // class_exists() didn't fail
113 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Class "%s" loaded successfully. OKAY', $configValue));
118 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Test result: %d okay, %d failed (%0.02f%% passed)', $passed, $failed, ($passed / ($passed + $failed) * 100)));
121 $this->partialStub('Please implement this method.');