Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       84.62%  | 
       11 / 13  | 
               | 
       50.00%  | 
       2 / 4  | 
       CRAP |         | 
       0.00%  | 
       0 / 1  | 
      
| ProviderRegistry |         | 
       84.62%  | 
       11 / 13  | 
               | 
       50.00%  | 
       2 / 4  | 
       8.23 |         | 
       0.00%  | 
       0 / 1  | 
      
| getConfigId |         | 
       0.00%  | 
       0 / 1  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| getExtension |         | 
       0.00%  | 
       0 / 1  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| getByCategory |         | 
       100.00%  | 
       8 / 8  | 
               | 
       100.00%  | 
       1 / 1  | 
       3 | |||
| removeByCategory |         | 
       100.00%  | 
       3 / 3  | 
               | 
       100.00%  | 
       1 / 1  | 
       3 | |||
| 1 | <?php | 
| 2 | |
| 3 | /** | 
| 4 | * This program is free software; you can redistribute it and/or | 
| 5 | * modify it under the terms of the GNU General Public License | 
| 6 | * as published by the Free Software Foundation; under version 2 | 
| 7 | * of the License (non-upgradable). | 
| 8 | * | 
| 9 | * This program is distributed in the hope that it will be useful, | 
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 12 | * GNU General Public License for more details. | 
| 13 | * | 
| 14 | * You should have received a copy of the GNU General Public License | 
| 15 | * along with this program; if not, write to the Free Software | 
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
| 17 | * | 
| 18 | * Copyright (c) 2017-2019 (original work) Open Assessment Technologies SA; | 
| 19 | */ | 
| 20 | |
| 21 | namespace oat\taoTests\models\runner\providers; | 
| 22 | |
| 23 | use common_ext_ExtensionsManager; | 
| 24 | use oat\tao\model\modules\AbstractModuleRegistry; | 
| 25 | |
| 26 | /** | 
| 27 | * Store the <b>available</b> test runner providers, even if not activated, | 
| 28 | * providers have to be registered. | 
| 29 | * | 
| 30 | * @author Bertrand Chevrier <bertrand@taotesting.com> | 
| 31 | * @author Jean-Sébastien Conan <jean-sebastien@taotesting.com> | 
| 32 | */ | 
| 33 | class ProviderRegistry extends AbstractModuleRegistry | 
| 34 | { | 
| 35 | /** | 
| 36 | * @see \oat\oatbox\AbstractRegistry::getConfigId() | 
| 37 | */ | 
| 38 | protected function getConfigId() | 
| 39 | { | 
| 40 | return 'test_runner_provider_registry'; | 
| 41 | } | 
| 42 | |
| 43 | /** | 
| 44 | * @see \oat\oatbox\AbstractRegistry::getExtension() | 
| 45 | */ | 
| 46 | protected function getExtension() | 
| 47 | { | 
| 48 | return common_ext_ExtensionsManager::singleton()->getExtensionById('taoTests'); | 
| 49 | } | 
| 50 | |
| 51 | /** | 
| 52 | * Get all modules that belong to a category | 
| 53 | * @param string $category - the provider category (runner, proxy,etc.) | 
| 54 | * @return array the matching providers | 
| 55 | */ | 
| 56 | public function getByCategory($category = null) | 
| 57 | { | 
| 58 | if ($category === null) { | 
| 59 | return []; | 
| 60 | } | 
| 61 | |
| 62 | return array_filter( | 
| 63 | $this->getMap(), | 
| 64 | function ($provider) use ($category) { | 
| 65 | return isset($provider['category']) && $provider['category'] === $category; | 
| 66 | } | 
| 67 | ); | 
| 68 | } | 
| 69 | |
| 70 | /** | 
| 71 | * Unregister all modules that belong to a category | 
| 72 | * @param string $category - the provider category (runner, proxy,etc.) | 
| 73 | */ | 
| 74 | public function removeByCategory($category = null) | 
| 75 | { | 
| 76 | foreach ($this->getByCategory($category) as $provider) { | 
| 77 | if (isset($provider['module'])) { | 
| 78 | $this->remove($provider['module']); | 
| 79 | } | 
| 80 | } | 
| 81 | } | 
| 82 | } |