Adhere feedback
- rename hooks.config.php to strategies.config.php - change all corresponding classes and tests
This commit is contained in:
parent
e659a03140
commit
cba656383e
12 changed files with 72 additions and 121 deletions
|
@ -43,7 +43,7 @@ public class ConcreteClassB implements ExampleInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var \Friendica\Core\Hooks\Capabilities\ICanRegisterInstances $instanceRegister */
|
/** @var \Friendica\Core\Hooks\Capabilities\ICanRegisterStrategies $instanceRegister */
|
||||||
$instanceRegister->registerStrategy(ExampleInterface::class, ConcreteClassA::class, 'A');
|
$instanceRegister->registerStrategy(ExampleInterface::class, ConcreteClassA::class, 'A');
|
||||||
$instanceRegister->registerStrategy(ExampleInterface::class, ConcreteClassB::class, 'B');
|
$instanceRegister->registerStrategy(ExampleInterface::class, ConcreteClassB::class, 'B');
|
||||||
|
|
||||||
|
|
|
@ -32,10 +32,10 @@ interface ICanCreateInstances
|
||||||
* The instance will be build based on the registered strategy and the (unique) name
|
* The instance will be build based on the registered strategy and the (unique) name
|
||||||
*
|
*
|
||||||
* @param string $class The fully-qualified name of the given class or interface which will get returned
|
* @param string $class The fully-qualified name of the given class or interface which will get returned
|
||||||
* @param string $name An arbitrary identifier to find a concrete instance strategy.
|
* @param string $strategy An arbitrary identifier to find a concrete instance strategy.
|
||||||
* @param array $arguments Additional arguments, which can be passed to the constructor of "$class" at runtime
|
* @param array $arguments Additional arguments, which can be passed to the constructor of "$class" at runtime
|
||||||
*
|
*
|
||||||
* @return object The concrete instance of the type "$class"
|
* @return object The concrete instance of the type "$class"
|
||||||
*/
|
*/
|
||||||
public function create(string $class, string $name, array $arguments = []): object;
|
public function create(string $class, string $strategy, array $arguments = []): object;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ use Friendica\Core\Hooks\Exceptions\HookRegisterArgumentException;
|
||||||
/**
|
/**
|
||||||
* Register strategies for given classes
|
* Register strategies for given classes
|
||||||
*/
|
*/
|
||||||
interface ICanRegisterInstances
|
interface ICanRegisterStrategies
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Register a class(strategy) for a given interface with a unique name.
|
* Register a class(strategy) for a given interface with a unique name.
|
||||||
|
@ -36,7 +36,7 @@ interface ICanRegisterInstances
|
||||||
* @param string $interface The interface, which the given class implements
|
* @param string $interface The interface, which the given class implements
|
||||||
* @param string $class The fully-qualified given class name
|
* @param string $class The fully-qualified given class name
|
||||||
* A placeholder for dependencies is possible as well
|
* A placeholder for dependencies is possible as well
|
||||||
* @param ?string $name An arbitrary identifier for the given class, which will be used for factories, dependency injections etc.
|
* @param ?string $name An arbitrary identifier for the given strategy, which will be used for factories, dependency injections etc.
|
||||||
*
|
*
|
||||||
* @return $this This interface for chain-calls
|
* @return $this This interface for chain-calls
|
||||||
*
|
*
|
|
@ -23,31 +23,31 @@ namespace Friendica\Core\Hooks\Model;
|
||||||
|
|
||||||
use Dice\Dice;
|
use Dice\Dice;
|
||||||
use Friendica\Core\Hooks\Capabilities\ICanCreateInstances;
|
use Friendica\Core\Hooks\Capabilities\ICanCreateInstances;
|
||||||
use Friendica\Core\Hooks\Capabilities\ICanRegisterInstances;
|
use Friendica\Core\Hooks\Capabilities\ICanRegisterStrategies;
|
||||||
use Friendica\Core\Hooks\Exceptions\HookInstanceException;
|
use Friendica\Core\Hooks\Exceptions\HookInstanceException;
|
||||||
use Friendica\Core\Hooks\Exceptions\HookRegisterArgumentException;
|
use Friendica\Core\Hooks\Exceptions\HookRegisterArgumentException;
|
||||||
use Friendica\Core\Hooks\Util\HookFileManager;
|
use Friendica\Core\Hooks\Util\StrategiesFileManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents an instance register, which uses Dice for creation
|
* This class represents an instance register, which uses Dice for creation
|
||||||
*
|
*
|
||||||
* @see Dice
|
* @see Dice
|
||||||
*/
|
*/
|
||||||
class DiceInstanceManager implements ICanCreateInstances, ICanRegisterInstances
|
class DiceInstanceManager implements ICanCreateInstances, ICanRegisterStrategies
|
||||||
{
|
{
|
||||||
protected $instance = [];
|
protected $instance = [];
|
||||||
|
|
||||||
/** @var Dice */
|
/** @var Dice */
|
||||||
protected $dice;
|
protected $dice;
|
||||||
|
|
||||||
public function __construct(Dice $dice, HookFileManager $hookFileManager)
|
public function __construct(Dice $dice, StrategiesFileManager $strategiesFileManager)
|
||||||
{
|
{
|
||||||
$this->dice = $dice;
|
$this->dice = $dice;
|
||||||
$hookFileManager->setupHooks($this);
|
$strategiesFileManager->setupStrategies($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public function registerStrategy(string $interface, string $class, ?string $name = null): ICanRegisterInstances
|
public function registerStrategy(string $interface, string $class, ?string $name = null): ICanRegisterStrategies
|
||||||
{
|
{
|
||||||
if (!empty($this->instance[$interface][$name])) {
|
if (!empty($this->instance[$interface][$name])) {
|
||||||
throw new HookRegisterArgumentException(sprintf('A class with the name %s is already set for the interface %s', $name, $interface));
|
throw new HookRegisterArgumentException(sprintf('A class with the name %s is already set for the interface %s', $name, $interface));
|
||||||
|
@ -59,12 +59,12 @@ class DiceInstanceManager implements ICanCreateInstances, ICanRegisterInstances
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public function create(string $class, string $name, array $arguments = []): object
|
public function create(string $class, string $strategy, array $arguments = []): object
|
||||||
{
|
{
|
||||||
if (empty($this->instance[$class][$name])) {
|
if (empty($this->instance[$class][$strategy])) {
|
||||||
throw new HookInstanceException(sprintf('The class with the name %s isn\'t registered for the class or interface %s', $name, $class));
|
throw new HookInstanceException(sprintf('The class with the name %s isn\'t registered for the class or interface %s', $strategy, $class));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->dice->create($this->instance[$class][$name], $arguments);
|
return $this->dice->create($this->instance[$class][$strategy], $arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,22 +22,21 @@
|
||||||
namespace Friendica\Core\Hooks\Util;
|
namespace Friendica\Core\Hooks\Util;
|
||||||
|
|
||||||
use Friendica\Core\Addon\Capabilities\ICanLoadAddons;
|
use Friendica\Core\Addon\Capabilities\ICanLoadAddons;
|
||||||
use Friendica\Core\Hooks\Capabilities\BehavioralHookType;
|
use Friendica\Core\Hooks\Capabilities\ICanRegisterStrategies;
|
||||||
use Friendica\Core\Hooks\Capabilities\ICanRegisterInstances;
|
|
||||||
use Friendica\Core\Hooks\Exceptions\HookConfigException;
|
use Friendica\Core\Hooks\Exceptions\HookConfigException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage all hooks.config.php files
|
* Manage all strategies.config.php files
|
||||||
*/
|
*/
|
||||||
class HookFileManager
|
class StrategiesFileManager
|
||||||
{
|
{
|
||||||
const STATIC_DIR = 'static';
|
const STATIC_DIR = 'static';
|
||||||
const CONFIG_NAME = 'hooks';
|
const CONFIG_NAME = 'strategies';
|
||||||
|
|
||||||
/** @var ICanLoadAddons */
|
/** @var ICanLoadAddons */
|
||||||
protected $addonLoader;
|
protected $addonLoader;
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $hookConfig = [];
|
protected $config = [];
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $basePath;
|
protected $basePath;
|
||||||
|
|
||||||
|
@ -50,32 +49,21 @@ class HookFileManager
|
||||||
/**
|
/**
|
||||||
* Loads all kinds of hooks and registers the corresponding instances
|
* Loads all kinds of hooks and registers the corresponding instances
|
||||||
*
|
*
|
||||||
* @param ICanRegisterInstances $instanceRegister The instance register
|
* @param ICanRegisterStrategies $instanceRegister The instance register
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setupHooks(ICanRegisterInstances $instanceRegister)
|
public function setupStrategies(ICanRegisterStrategies $instanceRegister)
|
||||||
{
|
{
|
||||||
// In case it wasn't used before, reload the whole hook config
|
foreach ($this->config as $interface => $strategy) {
|
||||||
if (empty($this->hookConfig)) {
|
foreach ($strategy as $dependencyName => $names) {
|
||||||
$this->reloadHookConfig();
|
if (is_array($names)) {
|
||||||
}
|
foreach ($names as $name) {
|
||||||
|
$instanceRegister->registerStrategy($interface, $dependencyName, $name);
|
||||||
foreach ($this->hookConfig as $hookType => $classList) {
|
|
||||||
switch ($hookType) {
|
|
||||||
case BehavioralHookType::STRATEGY:
|
|
||||||
foreach ($classList as $interface => $strategy) {
|
|
||||||
foreach ($strategy as $dependencyName => $names) {
|
|
||||||
if (is_array($names)) {
|
|
||||||
foreach ($names as $name) {
|
|
||||||
$instanceRegister->registerStrategy($interface, $dependencyName, $name);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$instanceRegister->registerStrategy($interface, $dependencyName, $names);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
|
$instanceRegister->registerStrategy($interface, $dependencyName, $names);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +75,7 @@ class HookFileManager
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function reloadHookConfig()
|
public function loadConfig()
|
||||||
{
|
{
|
||||||
// load core hook config
|
// load core hook config
|
||||||
$configFile = $this->basePath . '/' . static::STATIC_DIR . '/' . static::CONFIG_NAME . '.config.php';
|
$configFile = $this->basePath . '/' . static::STATIC_DIR . '/' . static::CONFIG_NAME . '.config.php';
|
||||||
|
@ -102,6 +90,6 @@ class HookFileManager
|
||||||
throw new HookConfigException(sprintf('Error loading config file %s.', $configFile));
|
throw new HookConfigException(sprintf('Error loading config file %s.', $configFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hookConfig = array_merge_recursive($config, $this->addonLoader->getActiveAddonConfig(static::CONFIG_NAME));
|
$this->config = array_merge_recursive($config, $this->addonLoader->getActiveAddonConfig(static::CONFIG_NAME));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -43,7 +43,7 @@ class Logger
|
||||||
$this->channel = $channel;
|
$this->channel = $channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(ICanCreateInstances $createInstances, IManageConfigValues $config, Profiler $profiler): LoggerInterface
|
public function create(ICanCreateInstances $instanceCreator, IManageConfigValues $config, Profiler $profiler): LoggerInterface
|
||||||
{
|
{
|
||||||
if (empty($config->get('system', 'debugging') ?? false)) {
|
if (empty($config->get('system', 'debugging') ?? false)) {
|
||||||
return new NullLogger();
|
return new NullLogger();
|
||||||
|
@ -53,7 +53,7 @@ class Logger
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/** @var LoggerInterface $logger */
|
/** @var LoggerInterface $logger */
|
||||||
$logger = $createInstances->create(LoggerInterface::class, $name, [$this->channel]);
|
$logger = $instanceCreator->create(LoggerInterface::class, $name, [$this->channel]);
|
||||||
if ($config->get('system', 'profiling') ?? false) {
|
if ($config->get('system', 'profiling') ?? false) {
|
||||||
return new ProfilerLoggerClass($logger, $profiler);
|
return new ProfilerLoggerClass($logger, $profiler);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -297,7 +297,7 @@ abstract class DI
|
||||||
static::init($flushDice);
|
static::init($flushDice);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function loggCheck(): ICheckLoggerSettings
|
public static function logCheck(): ICheckLoggerSettings
|
||||||
{
|
{
|
||||||
return self::$dice->create(LoggerSettingsCheck::class);
|
return self::$dice->create(LoggerSettingsCheck::class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,10 +126,10 @@ class Summary extends BaseAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check logfile permission
|
// Check logfile permission
|
||||||
if (($return = DI::loggCheck()->checkLogfile()) !== null) {
|
if (($return = DI::logCheck()->checkLogfile()) !== null) {
|
||||||
$warningtext[] = $return;
|
$warningtext[] = $return;
|
||||||
}
|
}
|
||||||
if (($return = DI::loggCheck()->checkDebugLogfile()) !== null) {
|
if (($return = DI::logCheck()->checkDebugLogfile()) !== null) {
|
||||||
$warningtext[] = $return;
|
$warningtext[] = $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ use Friendica\App;
|
||||||
use Friendica\Core\Cache;
|
use Friendica\Core\Cache;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\Hooks\Capabilities\ICanCreateInstances;
|
use Friendica\Core\Hooks\Capabilities\ICanCreateInstances;
|
||||||
use Friendica\Core\Hooks\Capabilities\ICanRegisterInstances;
|
use Friendica\Core\Hooks\Capabilities\ICanRegisterStrategies;
|
||||||
use Friendica\Core\Hooks\Model\DiceInstanceManager;
|
use Friendica\Core\Hooks\Model\DiceInstanceManager;
|
||||||
use Friendica\Core\PConfig;
|
use Friendica\Core\PConfig;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
|
@ -91,12 +91,15 @@ return [
|
||||||
[Dice::INSTANCE => Dice::SELF],
|
[Dice::INSTANCE => Dice::SELF],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
\Friendica\Core\Hooks\Util\HookFileManager::class => [
|
\Friendica\Core\Hooks\Util\StrategiesFileManager::class => [
|
||||||
'constructParams' => [
|
'constructParams' => [
|
||||||
[Dice::INSTANCE => '$basepath'],
|
[Dice::INSTANCE => '$basepath'],
|
||||||
],
|
],
|
||||||
|
'call' => [
|
||||||
|
['loadConfig'],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
ICanRegisterInstances::class => [
|
ICanRegisterStrategies::class => [
|
||||||
'instanceOf' => DiceInstanceManager::class,
|
'instanceOf' => DiceInstanceManager::class,
|
||||||
'constructParams' => [
|
'constructParams' => [
|
||||||
[Dice::INSTANCE => Dice::SELF],
|
[Dice::INSTANCE => Dice::SELF],
|
||||||
|
|
|
@ -24,11 +24,9 @@ use Friendica\Core\Logger\Type;
|
||||||
use Psr\Log;
|
use Psr\Log;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
H::STRATEGY => [
|
Log\LoggerInterface::class => [
|
||||||
Log\LoggerInterface::class => [
|
Log\NullLogger::class => [''],
|
||||||
Log\NullLogger::class => [''],
|
Type\SyslogLogger::class => ['syslog'],
|
||||||
Type\SyslogLogger::class => ['syslog'],
|
Type\StreamLogger::class => ['stream'],
|
||||||
Type\StreamLogger::class => ['stream'],
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
];
|
];
|
|
@ -25,7 +25,7 @@ use Dice\Dice;
|
||||||
use Friendica\Core\Hooks\Exceptions\HookInstanceException;
|
use Friendica\Core\Hooks\Exceptions\HookInstanceException;
|
||||||
use Friendica\Core\Hooks\Exceptions\HookRegisterArgumentException;
|
use Friendica\Core\Hooks\Exceptions\HookRegisterArgumentException;
|
||||||
use Friendica\Core\Hooks\Model\DiceInstanceManager;
|
use Friendica\Core\Hooks\Model\DiceInstanceManager;
|
||||||
use Friendica\Core\Hooks\Util\HookFileManager;
|
use Friendica\Core\Hooks\Util\StrategiesFileManager;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
use Friendica\Test\Util\Hooks\InstanceMocks\FakeInstance;
|
use Friendica\Test\Util\Hooks\InstanceMocks\FakeInstance;
|
||||||
use Friendica\Test\Util\Hooks\InstanceMocks\FakeInstanceDecorator;
|
use Friendica\Test\Util\Hooks\InstanceMocks\FakeInstanceDecorator;
|
||||||
|
@ -34,15 +34,15 @@ use Mockery\MockInterface;
|
||||||
|
|
||||||
class InstanceManagerTest extends MockedTest
|
class InstanceManagerTest extends MockedTest
|
||||||
{
|
{
|
||||||
/** @var HookFileManager|MockInterface */
|
/** @var StrategiesFileManager|MockInterface */
|
||||||
protected $hookFileManager;
|
protected $hookFileManager;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->hookFileManager = \Mockery::mock(HookFileManager::class);
|
$this->hookFileManager = \Mockery::mock(StrategiesFileManager::class);
|
||||||
$this->hookFileManager->shouldReceive('setupHooks')->withAnyArgs();
|
$this->hookFileManager->shouldReceive('setupStrategies')->withAnyArgs();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
|
|
|
@ -22,16 +22,16 @@
|
||||||
namespace Friendica\Test\src\Core\Hooks\Util;
|
namespace Friendica\Test\src\Core\Hooks\Util;
|
||||||
|
|
||||||
use Friendica\Core\Addon\Capabilities\ICanLoadAddons;
|
use Friendica\Core\Addon\Capabilities\ICanLoadAddons;
|
||||||
use Friendica\Core\Hooks\Capabilities\ICanRegisterInstances;
|
use Friendica\Core\Hooks\Capabilities\ICanRegisterStrategies;
|
||||||
use Friendica\Core\Hooks\Exceptions\HookConfigException;
|
use Friendica\Core\Hooks\Exceptions\HookConfigException;
|
||||||
use Friendica\Core\Hooks\Util\HookFileManager;
|
use Friendica\Core\Hooks\Util\StrategiesFileManager;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
use org\bovigo\vfs\vfsStream;
|
use org\bovigo\vfs\vfsStream;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
|
|
||||||
class HookFileManagerTest extends MockedTest
|
class StrategiesFileManagerTest extends MockedTest
|
||||||
{
|
{
|
||||||
use VFSTrait;
|
use VFSTrait;
|
||||||
|
|
||||||
|
@ -50,11 +50,9 @@ class HookFileManagerTest extends MockedTest
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
\Friendica\Core\Hooks\Capabilities\BehavioralHookType::STRATEGY => [
|
|
||||||
\Psr\Log\LoggerInterface::class => [
|
\Psr\Log\LoggerInterface::class => [
|
||||||
\Psr\Log\NullLogger::class => [''],
|
\Psr\Log\NullLogger::class => [''],
|
||||||
],
|
],
|
||||||
],
|
|
||||||
];
|
];
|
||||||
EOF,
|
EOF,
|
||||||
'addonsArray' => [],
|
'addonsArray' => [],
|
||||||
|
@ -67,11 +65,9 @@ EOF,
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
\Friendica\Core\Hooks\Capabilities\BehavioralHookType::STRATEGY => [
|
|
||||||
\Psr\Log\LoggerInterface::class => [
|
\Psr\Log\LoggerInterface::class => [
|
||||||
\Psr\Log\NullLogger::class => '',
|
\Psr\Log\NullLogger::class => '',
|
||||||
],
|
],
|
||||||
],
|
|
||||||
];
|
];
|
||||||
EOF,
|
EOF,
|
||||||
'addonsArray' => [],
|
'addonsArray' => [],
|
||||||
|
@ -84,19 +80,15 @@ EOF,
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
\Friendica\Core\Hooks\Capabilities\BehavioralHookType::STRATEGY => [
|
|
||||||
\Psr\Log\LoggerInterface::class => [
|
\Psr\Log\LoggerInterface::class => [
|
||||||
\Psr\Log\NullLogger::class => [''],
|
\Psr\Log\NullLogger::class => [''],
|
||||||
],
|
],
|
||||||
],
|
|
||||||
];
|
];
|
||||||
EOF,
|
EOF,
|
||||||
'addonsArray' => [
|
'addonsArray' => [
|
||||||
\Friendica\Core\Hooks\Capabilities\BehavioralHookType::STRATEGY => [
|
|
||||||
\Psr\Log\LoggerInterface::class => [
|
\Psr\Log\LoggerInterface::class => [
|
||||||
\Psr\Log\NullLogger::class => ['null'],
|
\Psr\Log\NullLogger::class => ['null'],
|
||||||
],
|
],
|
||||||
],
|
|
||||||
],
|
],
|
||||||
'assertStrategies' => [
|
'assertStrategies' => [
|
||||||
[LoggerInterface::class, NullLogger::class, ''],
|
[LoggerInterface::class, NullLogger::class, ''],
|
||||||
|
@ -108,19 +100,15 @@ EOF,
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
\Friendica\Core\Hooks\Capabilities\BehavioralHookType::STRATEGY => [
|
|
||||||
\Psr\Log\LoggerInterface::class => [
|
\Psr\Log\LoggerInterface::class => [
|
||||||
\Psr\Log\NullLogger::class => [''],
|
\Psr\Log\NullLogger::class => [''],
|
||||||
],
|
],
|
||||||
],
|
|
||||||
];
|
];
|
||||||
EOF,
|
EOF,
|
||||||
'addonsArray' => [
|
'addonsArray' => [
|
||||||
\Friendica\Core\Hooks\Capabilities\BehavioralHookType::STRATEGY => [
|
|
||||||
\Psr\Log\LoggerInterface::class => [
|
\Psr\Log\LoggerInterface::class => [
|
||||||
\Psr\Log\NullLogger::class => 'null',
|
\Psr\Log\NullLogger::class => 'null',
|
||||||
],
|
],
|
||||||
],
|
|
||||||
],
|
],
|
||||||
'assertStrategies' => [
|
'assertStrategies' => [
|
||||||
[LoggerInterface::class, NullLogger::class, ''],
|
[LoggerInterface::class, NullLogger::class, ''],
|
||||||
|
@ -133,48 +121,21 @@ EOF,
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
\Friendica\Core\Hooks\Capabilities\BehavioralHookType::STRATEGY => [
|
|
||||||
\Psr\Log\LoggerInterface::class => [
|
\Psr\Log\LoggerInterface::class => [
|
||||||
\Psr\Log\NullLogger::class => [''],
|
\Psr\Log\NullLogger::class => [''],
|
||||||
],
|
],
|
||||||
],
|
|
||||||
];
|
];
|
||||||
EOF,
|
EOF,
|
||||||
'addonsArray' => [
|
'addonsArray' => [
|
||||||
\Friendica\Core\Hooks\Capabilities\BehavioralHookType::STRATEGY => [
|
|
||||||
\Psr\Log\LoggerInterface::class => [
|
\Psr\Log\LoggerInterface::class => [
|
||||||
\Psr\Log\NullLogger::class => [''],
|
\Psr\Log\NullLogger::class => [''],
|
||||||
],
|
],
|
||||||
],
|
|
||||||
],
|
],
|
||||||
'assertStrategies' => [
|
'assertStrategies' => [
|
||||||
[LoggerInterface::class, NullLogger::class, ''],
|
[LoggerInterface::class, NullLogger::class, ''],
|
||||||
[LoggerInterface::class, NullLogger::class, ''],
|
[LoggerInterface::class, NullLogger::class, ''],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'withWrongContentButAddons' => [
|
|
||||||
'content' => <<<EOF
|
|
||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
'REALLY_WRONG' => [
|
|
||||||
\Psr\Log\LoggerInterface::class => [
|
|
||||||
\Psr\Log\NullLogger::class => [''],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
EOF,
|
|
||||||
'addonsArray' => [
|
|
||||||
\Friendica\Core\Hooks\Capabilities\BehavioralHookType::STRATEGY => [
|
|
||||||
\Psr\Log\LoggerInterface::class => [
|
|
||||||
\Psr\Log\NullLogger::class => [''],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'assertStrategies' => [
|
|
||||||
[LoggerInterface::class, NullLogger::class, ''],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,58 +144,59 @@ EOF,
|
||||||
*/
|
*/
|
||||||
public function testSetupHooks(string $content, array $addonsArray, array $assertStrategies)
|
public function testSetupHooks(string $content, array $addonsArray, array $assertStrategies)
|
||||||
{
|
{
|
||||||
vfsStream::newFile('static/hooks.config.php')
|
vfsStream::newFile(StrategiesFileManager::STATIC_DIR . '/' . StrategiesFileManager::CONFIG_NAME . '.config.php')
|
||||||
->withContent($content)
|
->withContent($content)
|
||||||
->at($this->root);
|
->at($this->root);
|
||||||
|
|
||||||
$addonLoader = \Mockery::mock(ICanLoadAddons::class);
|
$addonLoader = \Mockery::mock(ICanLoadAddons::class);
|
||||||
$addonLoader->shouldReceive('getActiveAddonConfig')->andReturn($addonsArray)->once();
|
$addonLoader->shouldReceive('getActiveAddonConfig')->andReturn($addonsArray)->once();
|
||||||
|
|
||||||
$hookFileManager = new HookFileManager($this->root->url(), $addonLoader);
|
$hookFileManager = new StrategiesFileManager($this->root->url(), $addonLoader);
|
||||||
|
|
||||||
$instanceManager = \Mockery::mock(ICanRegisterInstances::class);
|
$instanceManager = \Mockery::mock(ICanRegisterStrategies::class);
|
||||||
foreach ($assertStrategies as $assertStrategy) {
|
foreach ($assertStrategies as $assertStrategy) {
|
||||||
$instanceManager->shouldReceive('registerStrategy')->withArgs($assertStrategy)->once();
|
$instanceManager->shouldReceive('registerStrategy')->withArgs($assertStrategy)->once();
|
||||||
}
|
}
|
||||||
|
|
||||||
$hookFileManager->setupHooks($instanceManager);
|
$hookFileManager->loadConfig();
|
||||||
|
$hookFileManager->setupStrategies($instanceManager);
|
||||||
|
|
||||||
self::expectNotToPerformAssertions();
|
self::expectNotToPerformAssertions();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the exception in case the hooks.config.php file is missing
|
* Test the exception in case the strategies.config.php file is missing
|
||||||
*/
|
*/
|
||||||
public function testMissingHooksFile()
|
public function testMissingStrategiesFile()
|
||||||
{
|
{
|
||||||
$addonLoader = \Mockery::mock(ICanLoadAddons::class);
|
$addonLoader = \Mockery::mock(ICanLoadAddons::class);
|
||||||
$instanceManager = \Mockery::mock(ICanRegisterInstances::class);
|
$instanceManager = \Mockery::mock(ICanRegisterStrategies::class);
|
||||||
$hookFileManager = new HookFileManager($this->root->url(), $addonLoader);
|
$hookFileManager = new StrategiesFileManager($this->root->url(), $addonLoader);
|
||||||
|
|
||||||
self::expectException(HookConfigException::class);
|
self::expectException(HookConfigException::class);
|
||||||
self::expectExceptionMessage(sprintf('config file %s does not exist.',
|
self::expectExceptionMessage(sprintf('config file %s does not exist.',
|
||||||
$this->root->url() . '/' . HookFileManager::STATIC_DIR . '/' . HookFileManager::CONFIG_NAME . '.config.php'));
|
$this->root->url() . '/' . StrategiesFileManager::STATIC_DIR . '/' . StrategiesFileManager::CONFIG_NAME . '.config.php'));
|
||||||
|
|
||||||
$hookFileManager->setupHooks($instanceManager);
|
$hookFileManager->loadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the exception in case the hooks.config.php file is wrong
|
* Test the exception in case the strategies.config.php file is wrong
|
||||||
*/
|
*/
|
||||||
public function testWrongHooksFile()
|
public function testWrongStrategiesFile()
|
||||||
{
|
{
|
||||||
$addonLoader = \Mockery::mock(ICanLoadAddons::class);
|
$addonLoader = \Mockery::mock(ICanLoadAddons::class);
|
||||||
$instanceManager = \Mockery::mock(ICanRegisterInstances::class);
|
$instanceManager = \Mockery::mock(ICanRegisterStrategies::class);
|
||||||
$hookFileManager = new HookFileManager($this->root->url(), $addonLoader);
|
$hookFileManager = new StrategiesFileManager($this->root->url(), $addonLoader);
|
||||||
|
|
||||||
vfsStream::newFile('static/hooks.config.php')
|
vfsStream::newFile(StrategiesFileManager::STATIC_DIR . '/' . StrategiesFileManager::CONFIG_NAME . '.config.php')
|
||||||
->withContent("<php return 'WRONG_CONTENT';")
|
->withContent("<php return 'WRONG_CONTENT';")
|
||||||
->at($this->root);
|
->at($this->root);
|
||||||
|
|
||||||
self::expectException(HookConfigException::class);
|
self::expectException(HookConfigException::class);
|
||||||
self::expectExceptionMessage(sprintf('Error loading config file %s.',
|
self::expectExceptionMessage(sprintf('Error loading config file %s.',
|
||||||
$this->root->url() . '/' . HookFileManager::STATIC_DIR . '/' . HookFileManager::CONFIG_NAME . '.config.php'));
|
$this->root->url() . '/' . StrategiesFileManager::STATIC_DIR . '/' . StrategiesFileManager::CONFIG_NAME . '.config.php'));
|
||||||
|
|
||||||
$hookFileManager->setupHooks($instanceManager);
|
$hookFileManager->loadConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue