mirror of
https://github.com/friendica/friendica
synced 2025-09-09 18:51:12 +02:00
Fix tests for StrategiesFileManager
This commit is contained in:
parent
f9d695d80d
commit
3f1082400a
1 changed files with 85 additions and 60 deletions
|
@ -8,6 +8,7 @@
|
|||
namespace Friendica\Test\src\Core\Hooks\Util;
|
||||
|
||||
use Friendica\Core\Addon\Capability\ICanLoadAddons;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Hooks\Capability\ICanRegisterStrategies;
|
||||
use Friendica\Core\Hooks\Exceptions\HookConfigException;
|
||||
use Friendica\Core\Hooks\Util\StrategiesFileManager;
|
||||
|
@ -41,7 +42,11 @@ return [
|
|||
],
|
||||
];
|
||||
EOF,
|
||||
'addonsArray' => [],
|
||||
'addonContent' => <<<EOF
|
||||
<?php
|
||||
|
||||
return [];
|
||||
EOF,
|
||||
'assertStrategies' => [
|
||||
[LoggerInterface::class, NullLogger::class, ''],
|
||||
],
|
||||
|
@ -56,7 +61,11 @@ return [
|
|||
],
|
||||
];
|
||||
EOF,
|
||||
'addonsArray' => [],
|
||||
'addonContent' => <<<EOF
|
||||
<?php
|
||||
|
||||
return [];
|
||||
EOF,
|
||||
'assertStrategies' => [
|
||||
[LoggerInterface::class, NullLogger::class, ''],
|
||||
],
|
||||
|
@ -71,11 +80,15 @@ return [
|
|||
],
|
||||
];
|
||||
EOF,
|
||||
'addonsArray' => [
|
||||
'addonContent' => <<<EOF
|
||||
<?php
|
||||
|
||||
return [
|
||||
\Psr\Log\LoggerInterface::class => [
|
||||
\Psr\Log\NullLogger::class => ['null'],
|
||||
],
|
||||
],
|
||||
];
|
||||
EOF,
|
||||
'assertStrategies' => [
|
||||
[LoggerInterface::class, NullLogger::class, ''],
|
||||
[LoggerInterface::class, NullLogger::class, 'null'],
|
||||
|
@ -91,11 +104,15 @@ return [
|
|||
],
|
||||
];
|
||||
EOF,
|
||||
'addonsArray' => [
|
||||
'addonContent' => <<<EOF
|
||||
<?php
|
||||
|
||||
return [
|
||||
\Psr\Log\LoggerInterface::class => [
|
||||
\Psr\Log\NullLogger::class => 'null',
|
||||
],
|
||||
\Psr\Log\NullLogger::class => ['null'],
|
||||
],
|
||||
];
|
||||
EOF,
|
||||
'assertStrategies' => [
|
||||
[LoggerInterface::class, NullLogger::class, ''],
|
||||
[LoggerInterface::class, NullLogger::class, 'null'],
|
||||
|
@ -112,11 +129,15 @@ return [
|
|||
],
|
||||
];
|
||||
EOF,
|
||||
'addonsArray' => [
|
||||
'addonContent' => <<<EOF
|
||||
<?php
|
||||
|
||||
return [
|
||||
\Psr\Log\LoggerInterface::class => [
|
||||
\Psr\Log\NullLogger::class => [''],
|
||||
],
|
||||
],
|
||||
];
|
||||
EOF,
|
||||
'assertStrategies' => [
|
||||
[LoggerInterface::class, NullLogger::class, ''],
|
||||
[LoggerInterface::class, NullLogger::class, ''],
|
||||
|
@ -128,16 +149,20 @@ EOF,
|
|||
/**
|
||||
* @dataProvider dataHooks
|
||||
*/
|
||||
public function testSetupHooks(string $content, array $addonsArray, array $assertStrategies)
|
||||
public function testSetupHooks(string $content, string $addonContent, array $assertStrategies)
|
||||
{
|
||||
vfsStream::newFile(StrategiesFileManager::STATIC_DIR . '/' . StrategiesFileManager::CONFIG_NAME . '.config.php')
|
||||
->withContent($content)
|
||||
->at($this->root);
|
||||
|
||||
$addonLoader = \Mockery::mock(ICanLoadAddons::class);
|
||||
$addonLoader->shouldReceive('getActiveAddonConfig')->andReturn($addonsArray)->once();
|
||||
vfsStream::newFile('addon/testaddon/' . StrategiesFileManager::STATIC_DIR . '/' . StrategiesFileManager::CONFIG_NAME . '.config.php')
|
||||
->withContent($addonContent)
|
||||
->at($this->root);
|
||||
|
||||
$hookFileManager = new StrategiesFileManager($this->root->url(), $addonLoader);
|
||||
$config = \Mockery::mock(IManageConfigValues::class);
|
||||
$config->shouldReceive('get')->andReturn(['testaddon' => ['admin' => false]])->once();
|
||||
|
||||
$hookFileManager = new StrategiesFileManager($this->root->url(), $config);
|
||||
|
||||
$instanceManager = \Mockery::mock(ICanRegisterStrategies::class);
|
||||
foreach ($assertStrategies as $assertStrategy) {
|
||||
|
@ -155,9 +180,9 @@ EOF,
|
|||
*/
|
||||
public function testMissingStrategiesFile()
|
||||
{
|
||||
$addonLoader = \Mockery::mock(ICanLoadAddons::class);
|
||||
$config = \Mockery::mock(IManageConfigValues::class);
|
||||
$instanceManager = \Mockery::mock(ICanRegisterStrategies::class);
|
||||
$hookFileManager = new StrategiesFileManager($this->root->url(), $addonLoader);
|
||||
$hookFileManager = new StrategiesFileManager($this->root->url(), $config);
|
||||
|
||||
self::expectException(HookConfigException::class);
|
||||
self::expectExceptionMessage(sprintf('config file %s does not exist.',
|
||||
|
@ -171,9 +196,9 @@ EOF,
|
|||
*/
|
||||
public function testWrongStrategiesFile()
|
||||
{
|
||||
$addonLoader = \Mockery::mock(ICanLoadAddons::class);
|
||||
$config = \Mockery::mock(IManageConfigValues::class);
|
||||
$instanceManager = \Mockery::mock(ICanRegisterStrategies::class);
|
||||
$hookFileManager = new StrategiesFileManager($this->root->url(), $addonLoader);
|
||||
$hookFileManager = new StrategiesFileManager($this->root->url(), $config);
|
||||
|
||||
vfsStream::newFile(StrategiesFileManager::STATIC_DIR . '/' . StrategiesFileManager::CONFIG_NAME . '.config.php')
|
||||
->withContent("<?php return 'WRONG_CONTENT';")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue