-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from garygitton/feature/issue-71-class-name-re…
…solution-problem issue-71 - class name resolution problem
- Loading branch information
Showing
6 changed files
with
369 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaminasTest\ApiTools\Admin; | ||
|
||
use Laminas\ModuleManager\ModuleManager; | ||
use Laminas\Mvc\Service\ServiceManagerConfig; | ||
use Laminas\ServiceManager\ServiceManager; | ||
|
||
use function date_default_timezone_set; | ||
use function error_reporting; | ||
use function ini_set; | ||
use function is_array; | ||
|
||
use const E_ALL; | ||
|
||
class Bootstrap | ||
{ | ||
/** @var ServiceManager */ | ||
protected static $serviceManager; | ||
|
||
/** @var bool */ | ||
private static $initialized = false; | ||
|
||
public static function init(): void | ||
{ | ||
if (static::$initialized) { | ||
return; | ||
} | ||
|
||
ini_set('display_errors', '1'); | ||
ini_set('display_startup_errors', '1'); | ||
ini_set('log_errors_max_len', '0'); | ||
error_reporting(E_ALL); | ||
date_default_timezone_set('UTC'); | ||
|
||
include 'vendor/autoload.php'; | ||
|
||
$config = [ | ||
'modules' => [ | ||
'Laminas\\Filter', | ||
'Laminas\\Validator', | ||
'Laminas\\InputFilter', | ||
'Laminas\\ApiTools\\Admin', | ||
], | ||
'module_listener_options' => [ | ||
'config_glob_paths' => [ | ||
'./config/autoload/*.php', | ||
], | ||
'module_paths' => [ | ||
'./module', | ||
'./vendor', | ||
], | ||
'config_cache_enabled' => false, | ||
'module_map_cache_enabled' => false, | ||
'check_dependencies' => true, | ||
], | ||
]; | ||
|
||
$serviceManagerConfig = new ServiceManagerConfig(); | ||
$serviceManager = new ServiceManager(); | ||
$serviceManagerConfig->configureServiceManager($serviceManager); | ||
$serviceManager->setService('ApplicationConfig', $config); | ||
/** @var ModuleManager $moduleManager */ | ||
$moduleManager = $serviceManager->get('ModuleManager'); | ||
$moduleManager->loadModules(); | ||
|
||
static::$serviceManager = $serviceManager; | ||
static::$initialized = true; | ||
} | ||
|
||
/** | ||
* @return mixed|object | ||
*/ | ||
public static function getService(string $name) | ||
{ | ||
$serviceManager = self::getServiceManager(); | ||
|
||
return $serviceManager->get($name); | ||
} | ||
|
||
public static function getConfig(): array | ||
{ | ||
$serviceManager = self::getServiceManager(); | ||
/** @psalm-suppress MixedAssignment */ | ||
$config = $serviceManager->get('config'); | ||
|
||
return is_array($config) ? $config : []; | ||
} | ||
|
||
public static function getServiceManager(): ServiceManager | ||
{ | ||
self::init(); | ||
|
||
return static::$serviceManager; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaminasIntegrationTest\ApiTools\Admin\InputFilter; | ||
|
||
use Exception; | ||
use Laminas\InputFilter\InputFilter; | ||
use Laminas\InputFilter\InputFilterInterface; | ||
use Laminas\InputFilter\InputFilterPluginManager; | ||
use LaminasTest\ApiTools\Admin\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
use function array_keys; | ||
use function is_array; | ||
|
||
class LaminasTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* @throws Exception | ||
*/ | ||
public function inputFilterServiceKeyWillReturnInputFilter(): void | ||
{ | ||
$inputFilterConfig = $this->getInputFilterAliases(); | ||
$inputFilterKeys = array_keys($inputFilterConfig); | ||
|
||
/** @var string $key */ | ||
foreach ($inputFilterKeys as $key) { | ||
$inputFilter = $this->getInputFilter($key); | ||
$this->assertInstanceOf(InputFilter::class, $inputFilter); | ||
} | ||
} | ||
|
||
private function getInputFilterManager(): InputFilterPluginManager | ||
{ | ||
$inputFilterManager = Bootstrap::getService(InputFilterPluginManager::class); | ||
|
||
if (! $inputFilterManager instanceof InputFilterPluginManager) { | ||
throw new Exception('Invalid class.'); | ||
} | ||
|
||
return $inputFilterManager; | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
private function getInputFilter(string $name): InputFilterInterface | ||
{ | ||
$inputFilterManager = $this->getInputFilterManager(); | ||
$inputFilter = $inputFilterManager->get($name); | ||
|
||
if (! $inputFilter instanceof InputFilterInterface) { | ||
throw new Exception('Invalid class.'); | ||
} | ||
|
||
return $inputFilter; | ||
} | ||
|
||
private function getInputFilterConfig(): array | ||
{ | ||
$config = Bootstrap::getConfig(); | ||
|
||
return is_array($config['input_filters']) ? $config['input_filters'] : []; | ||
} | ||
|
||
private function getInputFilterAliases(): array | ||
{ | ||
$config = $this->getInputFilterConfig(); | ||
|
||
return is_array($config['aliases']) ? $config['aliases'] : []; | ||
} | ||
} |