From 326566638fcc90ef20a87047ea55fb846c7d46e3 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 1 Jan 2023 21:10:41 +0100 Subject: [PATCH] adapt tests --- tests/FixtureTest.php | 13 +- tests/Util/VFSTrait.php | 15 ++ tests/datasets/api.fixture.php | 27 -- tests/datasets/config/node.config.php | 13 + tests/functional/DependencyCheckTest.php | 10 +- tests/src/Core/Config/Cache/CacheTest.php | 70 +++-- .../Config/Cache/ConfigFileLoaderTest.php | 61 ++++- tests/src/Core/Config/ConfigTest.php | 178 ++++-------- tests/src/Core/Config/JitConfigTest.php | 255 ------------------ tests/src/Core/Config/PreloadConfigTest.php | 213 --------------- tests/src/Core/Lock/SemaphoreLockTest.php | 10 +- .../Storage/Repository/StorageManagerTest.php | 6 +- tests/src/Database/DBATest.php | 5 +- tests/src/Database/DBStructureTest.php | 28 +- .../Api/GnuSocial/GnuSocial/ConfigTest.php | 1 + tests/src/Util/BaseURLTest.php | 61 +++-- 16 files changed, 254 insertions(+), 712 deletions(-) create mode 100644 tests/datasets/config/node.config.php delete mode 100644 tests/src/Core/Config/JitConfigTest.php delete mode 100644 tests/src/Core/Config/PreloadConfigTest.php diff --git a/tests/FixtureTest.php b/tests/FixtureTest.php index a57d3aa766..efb9280310 100644 --- a/tests/FixtureTest.php +++ b/tests/FixtureTest.php @@ -25,20 +25,24 @@ namespace Friendica\Test; use Dice\Dice; use Friendica\App\Arguments; use Friendica\App\Router; +use Friendica\Core\Config\Factory\Config; +use Friendica\Core\Config\Util\ConfigFileManager; use Friendica\Core\Config\ValueObject\Cache; -use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Session\Capability\IHandleSessions; use Friendica\Core\Session\Type\Memory; use Friendica\Database\Database; use Friendica\Database\DBStructure; use Friendica\DI; use Friendica\Test\Util\Database\StaticDatabase; +use Friendica\Test\Util\VFSTrait; /** * Parent class for test cases requiring fixtures */ abstract class FixtureTest extends DatabaseTest { + use VFSTrait; + /** @var Dice */ protected $dice; @@ -47,6 +51,8 @@ abstract class FixtureTest extends DatabaseTest */ protected function setUp(): void { + $this->setUpVfsDir(); + parent::setUp(); $server = $_SERVER; @@ -54,6 +60,10 @@ abstract class FixtureTest extends DatabaseTest $this->dice = (new Dice()) ->addRules(include __DIR__ . '/../static/dependencies.config.php') + ->addRule(ConfigFileManager::class, [ + 'instanceOf' => Config::class, + 'call' => [['createConfigFileLoader', [$this->root->url(), $server,], + Dice::CHAIN_CALL]]]) ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]) ->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null]) ->addRule(Arguments::class, [ @@ -64,7 +74,6 @@ abstract class FixtureTest extends DatabaseTest ]); DI::init($this->dice); - /** @var IManageConfigValues $config */ $configCache = $this->dice->create(Cache::class); $configCache->set('database', 'disable_pdo', true); diff --git a/tests/Util/VFSTrait.php b/tests/Util/VFSTrait.php index 30c27451eb..e36cc1234c 100644 --- a/tests/Util/VFSTrait.php +++ b/tests/Util/VFSTrait.php @@ -54,6 +54,21 @@ trait VFSTrait $this->setConfigFile('defaults.config.php', true); $this->setConfigFile('settings.config.php', true); $this->setConfigFile('local.config.php'); + $this->setDataFile('node.config.php'); + } + + protected function setDataFile(string $filename) + { + $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . + 'datasets' . DIRECTORY_SEPARATOR . + 'config' . DIRECTORY_SEPARATOR . + $filename; + + if (file_exists($file)) { + vfsStream::newFile($filename) + ->at($this->root->getChild('config')) + ->setContent(file_get_contents($file)); + } } /** diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index a8119106ee..b50f706251 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -36,33 +36,6 @@ return [ 'mail', 'post-delivery-data', // Base test config to avoid notice messages - 'config' => [ - [ - 'cat' => 'system', - 'k' => 'url', - 'v' => 'http://localhost', - ], - [ - 'cat' => 'config', - 'k' => 'hostname', - 'v' => 'localhost', - ], - [ - 'cat' => 'system', - 'k' => 'worker_dont_fork', - 'v' => '1', - ], - [ - 'cat' => 'system', - 'k' => 'curl_timeout', - 'v' => '1', - ], - [ - 'cat' => 'system', - 'k' => 'xrd_timeout', - 'v' => '1', - ], - ], 'user' => [ [ 'uid' => 42, diff --git a/tests/datasets/config/node.config.php b/tests/datasets/config/node.config.php new file mode 100644 index 0000000000..335ef19c9d --- /dev/null +++ b/tests/datasets/config/node.config.php @@ -0,0 +1,13 @@ + [ + 'hostname' => 'localhost', + ], + 'system' => [ + 'url' => 'http://localhost', + "worker_dont_fork" => 1, + "curl_timeout"=> 1, + "xrd_timeout"=> 1, + ], +]; diff --git a/tests/functional/DependencyCheckTest.php b/tests/functional/DependencyCheckTest.php index 3b21f75845..9bc7624d6a 100644 --- a/tests/functional/DependencyCheckTest.php +++ b/tests/functional/DependencyCheckTest.php @@ -31,7 +31,7 @@ use Friendica\Core\Lock\Capability\ICanLock; use Friendica\Database\Database; use Friendica\Test\Util\VFSTrait; use Friendica\Util\BasePath; -use Friendica\Core\Config\Util\ConfigFileLoader; +use Friendica\Core\Config\Util\ConfigFileManager; use Friendica\Util\Profiler; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; @@ -73,13 +73,13 @@ class DependencyCheckTest extends TestCase */ public function testConfigFileLoader() { - /** @var ConfigFileLoader $configFileLoader */ - $configFileLoader = $this->dice->create(ConfigFileLoader::class); + /** @var ConfigFileManager $configFileManager */ + $configFileManager = $this->dice->create(ConfigFileManager::class); - self::assertInstanceOf(ConfigFileLoader::class, $configFileLoader); + self::assertInstanceOf(ConfigFileManager::class, $configFileManager); $configCache = new Cache(); - $configFileLoader->setupCache($configCache); + $configFileManager->setupCache($configCache); self::assertNotEmpty($configCache->getAll()); self::assertArrayHasKey('database', $configCache->getAll()); diff --git a/tests/src/Core/Config/Cache/CacheTest.php b/tests/src/Core/Config/Cache/CacheTest.php index 6de87be5d4..8b2c24da3e 100644 --- a/tests/src/Core/Config/Cache/CacheTest.php +++ b/tests/src/Core/Config/Cache/CacheTest.php @@ -21,7 +21,7 @@ namespace Friendica\Test\src\Core\Config\Cache; -use Friendica\Core\Config\Cache; +use Friendica\Core\Config\ValueObject\Cache; use Friendica\Test\MockedTest; use ParagonIE\HiddenString\HiddenString; use stdClass; @@ -49,7 +49,7 @@ class CacheTest extends MockedTest ]; } - private function assertConfigValues($data, \Friendica\Core\Config\ValueObject\Cache $configCache) + private function assertConfigValues($data, Cache $configCache) { foreach ($data as $cat => $values) { foreach ($values as $key => $value) { @@ -64,7 +64,7 @@ class CacheTest extends MockedTest */ public function testLoadConfigArray($data) { - $configCache = new \Friendica\Core\Config\ValueObject\Cache(); + $configCache = new Cache(); $configCache->load($data); self::assertConfigValues($data, $configCache); @@ -83,27 +83,27 @@ class CacheTest extends MockedTest ] ]; - $configCache = new \Friendica\Core\Config\ValueObject\Cache(); - $configCache->load($data, \Friendica\Core\Config\ValueObject\Cache::SOURCE_DB); + $configCache = new Cache(); + $configCache->load($data, Cache::SOURCE_DATA); // doesn't override - Low Priority due Config file - $configCache->load($override, \Friendica\Core\Config\ValueObject\Cache::SOURCE_FILE); + $configCache->load($override, Cache::SOURCE_FILE); self::assertConfigValues($data, $configCache); // override the value - High Prio due Server Env - $configCache->load($override, \Friendica\Core\Config\ValueObject\Cache::SOURCE_ENV); + $configCache->load($override, Cache::SOURCE_ENV); self::assertEquals($override['system']['test'], $configCache->get('system', 'test')); self::assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue')); // Don't overwrite server ENV variables - even in load mode - $configCache->load($data, \Friendica\Core\Config\ValueObject\Cache::SOURCE_DB); + $configCache->load($data, Cache::SOURCE_DATA); self::assertEquals($override['system']['test'], $configCache->get('system', 'test')); self::assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue')); // Overwrite ENV variables with ENV variables - $configCache->load($data, \Friendica\Core\Config\ValueObject\Cache::SOURCE_ENV); + $configCache->load($data, Cache::SOURCE_ENV); self::assertConfigValues($data, $configCache); self::assertNotEquals($override['system']['test'], $configCache->get('system', 'test')); @@ -115,7 +115,7 @@ class CacheTest extends MockedTest */ public function testLoadConfigArrayWrong() { - $configCache = new \Friendica\Core\Config\ValueObject\Cache(); + $configCache = new Cache(); // empty dataset $configCache->load([]); @@ -136,7 +136,7 @@ class CacheTest extends MockedTest */ public function testGetAll($data) { - $configCache = new \Friendica\Core\Config\ValueObject\Cache(); + $configCache = new Cache(); $configCache->load($data); $all = $configCache->getAll(); @@ -151,7 +151,7 @@ class CacheTest extends MockedTest */ public function testSetGet($data) { - $configCache = new \Friendica\Core\Config\ValueObject\Cache(); + $configCache = new Cache(); foreach ($data as $cat => $values) { foreach ($values as $key => $value) { @@ -167,7 +167,7 @@ class CacheTest extends MockedTest */ public function testGetEmpty() { - $configCache = new \Friendica\Core\Config\ValueObject\Cache(); + $configCache = new Cache(); self::assertNull($configCache->get('something', 'value')); } @@ -177,7 +177,7 @@ class CacheTest extends MockedTest */ public function testGetCat() { - $configCache = new \Friendica\Core\Config\ValueObject\Cache([ + $configCache = new Cache([ 'system' => [ 'key1' => 'value1', 'key2' => 'value2', @@ -205,7 +205,7 @@ class CacheTest extends MockedTest */ public function testDelete($data) { - $configCache = new \Friendica\Core\Config\ValueObject\Cache($data); + $configCache = new Cache($data); foreach ($data as $cat => $values) { foreach ($values as $key => $value) { @@ -222,7 +222,7 @@ class CacheTest extends MockedTest */ public function testKeyDiffWithResult($data) { - $configCache = new \Friendica\Core\Config\ValueObject\Cache($data); + $configCache = new Cache($data); $diffConfig = [ 'fakeCat' => [ @@ -239,7 +239,7 @@ class CacheTest extends MockedTest */ public function testKeyDiffWithoutResult($data) { - $configCache = new \Friendica\Core\Config\ValueObject\Cache($data); + $configCache = new Cache($data); $diffConfig = $configCache->getAll(); @@ -251,7 +251,7 @@ class CacheTest extends MockedTest */ public function testPasswordHide() { - $configCache = new \Friendica\Core\Config\ValueObject\Cache([ + $configCache = new Cache([ 'database' => [ 'password' => 'supersecure', 'username' => 'notsecured', @@ -268,7 +268,7 @@ class CacheTest extends MockedTest */ public function testPasswordShow() { - $configCache = new \Friendica\Core\Config\ValueObject\Cache([ + $configCache = new Cache([ 'database' => [ 'password' => 'supersecure', 'username' => 'notsecured', @@ -285,7 +285,7 @@ class CacheTest extends MockedTest */ public function testEmptyPassword() { - $configCache = new \Friendica\Core\Config\ValueObject\Cache([ + $configCache = new Cache([ 'database' => [ 'password' => '', 'username' => '', @@ -299,7 +299,7 @@ class CacheTest extends MockedTest public function testWrongTypePassword() { - $configCache = new \Friendica\Core\Config\ValueObject\Cache([ + $configCache = new Cache([ 'database' => [ 'password' => new stdClass(), 'username' => '', @@ -309,7 +309,7 @@ class CacheTest extends MockedTest self::assertNotEmpty($configCache->get('database', 'password')); self::assertEmpty($configCache->get('database', 'username')); - $configCache = new \Friendica\Core\Config\ValueObject\Cache([ + $configCache = new Cache([ 'database' => [ 'password' => 23, 'username' => '', @@ -327,19 +327,35 @@ class CacheTest extends MockedTest public function testSetOverrides($data) { - $configCache = new \Friendica\Core\Config\ValueObject\Cache(); - $configCache->load($data, \Friendica\Core\Config\ValueObject\Cache::SOURCE_DB); + $configCache = new Cache(); + $configCache->load($data, Cache::SOURCE_DATA); // test with wrong override - self::assertFalse($configCache->set('system', 'test', '1234567', \Friendica\Core\Config\ValueObject\Cache::SOURCE_FILE)); + self::assertFalse($configCache->set('system', 'test', '1234567', Cache::SOURCE_FILE)); self::assertEquals($data['system']['test'], $configCache->get('system', 'test')); // test with override (equal) - self::assertTrue($configCache->set('system', 'test', '8910', \Friendica\Core\Config\ValueObject\Cache::SOURCE_DB)); + self::assertTrue($configCache->set('system', 'test', '8910', Cache::SOURCE_DATA)); self::assertEquals('8910', $configCache->get('system', 'test')); // test with override (over) - self::assertTrue($configCache->set('system', 'test', '111213', \Friendica\Core\Config\ValueObject\Cache::SOURCE_ENV)); + self::assertTrue($configCache->set('system', 'test', '111213', Cache::SOURCE_ENV)); self::assertEquals('111213', $configCache->get('system', 'test')); } + + /** + * @dataProvider dataTests + * + * @return void + */ + public function testSetData($data) + { + $configCache = new Cache(); + $configCache->load($data, Cache::SOURCE_FILE); + + $configCache->set('system', 'test_2','with_data', Cache::SOURCE_DATA); + + $this->assertEquals(['system' => ['test_2' => 'with_data']], $configCache->getDataBySource(Cache::SOURCE_DATA)); + $this->assertEquals($data, $configCache->getDataBySource(Cache::SOURCE_FILE)); + } } diff --git a/tests/src/Core/Config/Cache/ConfigFileLoaderTest.php b/tests/src/Core/Config/Cache/ConfigFileLoaderTest.php index be1c7def68..e8443611f2 100644 --- a/tests/src/Core/Config/Cache/ConfigFileLoaderTest.php +++ b/tests/src/Core/Config/Cache/ConfigFileLoaderTest.php @@ -25,7 +25,7 @@ use Friendica\Core\Config\Cache; use Friendica\Core\Config\Factory\Config; use Friendica\Test\MockedTest; use Friendica\Test\Util\VFSTrait; -use Friendica\Core\Config\Util\ConfigFileLoader; +use Friendica\Core\Config\Util\ConfigFileManager; use org\bovigo\vfs\vfsStream; class ConfigFileLoaderTest extends MockedTest @@ -46,7 +46,7 @@ class ConfigFileLoaderTest extends MockedTest { $this->delConfigFile('local.config.php'); - $configFileLoader = new ConfigFileLoader( + $configFileLoader = new ConfigFileManager( $this->root->url(), $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR, $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR @@ -72,7 +72,7 @@ class ConfigFileLoaderTest extends MockedTest ->at($this->root->getChild('config')) ->setContent('root->url(), $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR, $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR @@ -101,7 +101,7 @@ class ConfigFileLoaderTest extends MockedTest ->at($this->root->getChild('config')) ->setContent(file_get_contents($file)); - $configFileLoader = new ConfigFileLoader( + $configFileLoader = new ConfigFileManager( $this->root->url(), $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR, $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR @@ -138,7 +138,7 @@ class ConfigFileLoaderTest extends MockedTest ->at($this->root->getChild('config')) ->setContent(file_get_contents($file)); - $configFileLoader = new ConfigFileLoader( + $configFileLoader = new ConfigFileManager( $this->root->url(), $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR, $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR @@ -174,7 +174,7 @@ class ConfigFileLoaderTest extends MockedTest ->at($this->root) ->setContent(file_get_contents($file)); - $configFileLoader = new ConfigFileLoader( + $configFileLoader = new ConfigFileManager( $this->root->url(), $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR, $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR @@ -228,7 +228,7 @@ class ConfigFileLoaderTest extends MockedTest ->at($this->root->getChild('addon')->getChild('test')->getChild('config')) ->setContent(file_get_contents($file)); - $configFileLoader = new ConfigFileLoader( + $configFileLoader = new ConfigFileManager( $this->root->url(), $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR, $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR @@ -265,7 +265,7 @@ class ConfigFileLoaderTest extends MockedTest ->at($this->root->getChild('config')) ->setContent(file_get_contents($fileDir . 'B.config.php')); - $configFileLoader = new ConfigFileLoader( + $configFileLoader = new ConfigFileManager( $this->root->url(), $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR, $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR @@ -299,7 +299,7 @@ class ConfigFileLoaderTest extends MockedTest ->at($this->root->getChild('config')) ->setContent(file_get_contents($fileDir . 'B.ini.php')); - $configFileLoader = new ConfigFileLoader( + $configFileLoader = new ConfigFileManager( $this->root->url(), $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR, $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR @@ -333,7 +333,7 @@ class ConfigFileLoaderTest extends MockedTest ->at($this->root->getChild('config')) ->setContent(file_get_contents($fileDir . 'B.ini.php')); - $configFileLoader = new ConfigFileLoader( + $configFileLoader = new ConfigFileManager( $this->root->url(), $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR, $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR @@ -386,4 +386,45 @@ class ConfigFileLoaderTest extends MockedTest self::assertEquals('newValue', $configCache->get('system', 'newKey')); } + + public function testSaveData() + { + $this->delConfigFile('local.config.php'); + + $fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR . + '..' . DIRECTORY_SEPARATOR . + '..' . DIRECTORY_SEPARATOR . + '..' . DIRECTORY_SEPARATOR . + 'datasets' . DIRECTORY_SEPARATOR . + 'config' . DIRECTORY_SEPARATOR; + + vfsStream::newFile('B.config.php') + ->at($this->root->getChild('config2')) + ->setContent(file_get_contents($fileDir . 'B.config.php')); + + $configFileLoader = (new Config())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]); + $configCache = new \Friendica\Core\Config\ValueObject\Cache(); + + $configFileLoader->setupCache($configCache); + + // overwrite some data and save it back to the config file + $configCache->set('system', 'test', 'it', \Friendica\Core\Config\ValueObject\Cache::SOURCE_DATA); + $configCache->set('config', 'test', 'it', \Friendica\Core\Config\ValueObject\Cache::SOURCE_DATA); + $configCache->set('system', 'test_2', 2, \Friendica\Core\Config\ValueObject\Cache::SOURCE_DATA); + $configFileLoader->saveData($configCache); + + // Reload the configCache with the new values + $configCache2 = new \Friendica\Core\Config\ValueObject\Cache(); + $configFileLoader->setupCache($configCache2); + + self::assertEquals($configCache, $configCache2); + self::assertEquals([ + 'system' => [ + 'test' => 'it', + 'test_2' => 2 + ], + 'config' => [ + 'test' => 'it' + ]], $configCache2->getDataBySource(\Friendica\Core\Config\ValueObject\Cache::SOURCE_DATA)); + } } diff --git a/tests/src/Core/Config/ConfigTest.php b/tests/src/Core/Config/ConfigTest.php index bdcba724e6..c85cf3f708 100644 --- a/tests/src/Core/Config/ConfigTest.php +++ b/tests/src/Core/Config/ConfigTest.php @@ -23,22 +23,25 @@ namespace Friendica\Test\src\Core\Config; use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\Config\Repository\Config as ConfigModel; +use Friendica\Core\Config\Model\Config; +use Friendica\Core\Config\Util\ConfigFileManager; +use Friendica\Core\Config\Util\ConfigFileTransformer; use Friendica\Core\Config\ValueObject\Cache; use Friendica\Test\MockedTest; -use Mockery\MockInterface; -use Mockery; +use Friendica\Test\Util\VFSTrait; +use org\bovigo\vfs\vfsStream; -abstract class ConfigTest extends MockedTest +class ConfigTest extends MockedTest { use ArraySubsetAsserts; - - /** @var ConfigModel|MockInterface */ - protected $configModel; + use VFSTrait; /** @var Cache */ protected $configCache; + /** @var ConfigFileManager */ + protected $configFileManager; + /** @var IManageConfigValues */ protected $testedConfig; @@ -60,17 +63,22 @@ abstract class ConfigTest extends MockedTest protected function setUp(): void { + $this->setUpVfsDir(); + parent::setUp(); - // Create the config model - $this->configModel = Mockery::mock(ConfigModel::class); $this->configCache = new Cache(); + $this->configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/'); } /** * @return IManageConfigValues */ - abstract public function getInstance(); + public function getInstance() + { + $this->configFileManager->setupCache($this->configCache, []); + return new Config($this->configFileManager, $this->configCache); + } public function dataTests() { @@ -156,12 +164,13 @@ abstract class ConfigTest extends MockedTest /** * Test the configuration initialization + * @dataProvider dataConfigLoad */ public function testSetUp(array $data) { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true) - ->once(); + vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE) + ->at($this->root->getChild('config')) + ->setContent(ConfigFileTransformer::encode($data)); $this->testedConfig = $this->getInstance(); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache()); @@ -171,19 +180,23 @@ abstract class ConfigTest extends MockedTest } /** - * Test the configuration load() method + * Test the configuration reload() method * * @param array $data * @param array $load + * + * @dataProvider dataConfigLoad */ - public function testLoad(array $data, array $load) + public function testReload(array $data, array $load) { + vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE) + ->at($this->root->getChild('config')) + ->setContent(ConfigFileTransformer::encode($data)); + $this->testedConfig = $this->getInstance(); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache()); - foreach ($load as $loadedCats) { - $this->testedConfig->load($loadedCats); - } + $this->testedConfig->reload(); // Assert at least loaded cats are loaded foreach ($load as $loadedCats) { @@ -256,23 +269,31 @@ abstract class ConfigTest extends MockedTest /** * Test the configuration load() method with overwrite + * + * @dataProvider dataDoubleLoad */ public function testCacheLoadDouble(array $data1, array $data2, array $expect = []) { + vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE) + ->at($this->root->getChild('config')) + ->setContent(ConfigFileTransformer::encode($data1)); + $this->testedConfig = $this->getInstance(); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache()); - foreach ($data1 as $cat => $data) { - $this->testedConfig->load($cat); - } - // Assert at least loaded cats are loaded foreach ($data1 as $cat => $data) { self::assertConfig($cat, $data); } + vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE) + ->at($this->root->getChild('config')) + ->setContent(ConfigFileTransformer::encode($data2)); + + $this->testedConfig->reload(); + foreach ($data2 as $cat => $data) { - $this->testedConfig->load($cat); + self::assertConfig($cat, $data); } } @@ -281,44 +302,19 @@ abstract class ConfigTest extends MockedTest */ public function testLoadWrong() { - $this->configModel->shouldReceive('isConnected')->andReturn(true)->once(); - $this->configModel->shouldReceive('load')->withAnyArgs()->andReturn([])->once(); - - $this->testedConfig = $this->getInstance(); + $this->testedConfig = new Config($this->configFileManager, new Cache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache()); self::assertEmpty($this->testedConfig->getCache()->getAll()); } /** - * Test the configuration get() and set() methods without adapter - * - * @dataProvider dataTests - */ - public function testSetGetWithoutDB($data) - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(false) - ->times(3); - - $this->testedConfig = $this->getInstance(); - self::assertInstanceOf(Cache::class, $this->testedConfig->getCache()); - - self::assertTrue($this->testedConfig->set('test', 'it', $data)); - - self::assertEquals($data, $this->testedConfig->get('test', 'it')); - self::assertEquals($data, $this->testedConfig->getCache()->get('test', 'it')); - } - - /** - * Test the configuration get() and set() methods with a model/db + * Test the configuration get() and set() methods * * @dataProvider dataTests */ - public function testSetGetWithDB($data) + public function testSetGet($data) { - $this->configModel->shouldReceive('set')->with('test', 'it', $data)->andReturn(true)->once(); - $this->testedConfig = $this->getInstance(); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache()); @@ -349,41 +345,16 @@ abstract class ConfigTest extends MockedTest self::assertEquals('default', $this->testedConfig->get('test', 'it', 'default', true)); } - /** - * Test the configuration get() method with refresh - * - * @dataProvider dataTests - */ - public function testGetWithRefresh($data) - { - $this->configCache->load(['test' => ['it' => 'now']], Cache::SOURCE_FILE); - - $this->testedConfig = $this->getInstance(); - self::assertInstanceOf(Cache::class, $this->testedConfig->getCache()); - - // without refresh - self::assertEquals('now', $this->testedConfig->get('test', 'it')); - self::assertEquals('now', $this->testedConfig->getCache()->get('test', 'it')); - - // with refresh - self::assertEquals($data, $this->testedConfig->get('test', 'it', null, true)); - self::assertEquals($data, $this->testedConfig->getCache()->get('test', 'it')); - - // without refresh and wrong value and default - self::assertEquals('default', $this->testedConfig->get('test', 'not', 'default')); - self::assertNull($this->testedConfig->getCache()->get('test', 'not')); - } - /** * Test the configuration delete() method without a model/db * * @dataProvider dataTests */ - public function testDeleteWithoutDB($data) + public function testDelete($data) { $this->configCache->load(['test' => ['it' => $data]], Cache::SOURCE_FILE); - $this->testedConfig = $this->getInstance(); + $this->testedConfig = new Config($this->configFileManager, $this->configCache); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache()); self::assertEquals($data, $this->testedConfig->get('test', 'it')); @@ -396,51 +367,6 @@ abstract class ConfigTest extends MockedTest self::assertEmpty($this->testedConfig->getCache()->getAll()); } - /** - * Test the configuration delete() method with a model/db - */ - public function testDeleteWithDB() - { - $this->configCache->load(['test' => ['it' => 'now', 'quarter' => 'true']], Cache::SOURCE_FILE); - - $this->configModel->shouldReceive('delete') - ->with('test', 'it') - ->andReturn(false) - ->once(); - $this->configModel->shouldReceive('delete') - ->with('test', 'second') - ->andReturn(true) - ->once(); - $this->configModel->shouldReceive('delete') - ->with('test', 'third') - ->andReturn(false) - ->once(); - $this->configModel->shouldReceive('delete') - ->with('test', 'quarter') - ->andReturn(true) - ->once(); - - $this->testedConfig = $this->getInstance(); - self::assertInstanceOf(Cache::class, $this->testedConfig->getCache()); - - // directly set the value to the cache - $this->testedConfig->getCache()->set('test', 'it', 'now'); - - self::assertEquals('now', $this->testedConfig->get('test', 'it')); - self::assertEquals('now', $this->testedConfig->getCache()->get('test', 'it')); - - // delete from cache only - self::assertTrue($this->testedConfig->delete('test', 'it')); - // delete from db only - self::assertTrue($this->testedConfig->delete('test', 'second')); - // no delete - self::assertFalse($this->testedConfig->delete('test', 'third')); - // delete both - self::assertTrue($this->testedConfig->delete('test', 'quarter')); - - self::assertEmpty($this->testedConfig->getCache()->getAll()); - } - /** * Test the configuration get() and set() method where the db value has a higher prio than the config file */ @@ -462,6 +388,12 @@ abstract class ConfigTest extends MockedTest */ public function testSetGetLowPrio() { + vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE) + ->at($this->root->getChild('config')) + ->setContent(ConfigFileTransformer::encode([ + 'config' => ['test' => 'it'], + ])); + $this->testedConfig = $this->getInstance(); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache()); self::assertEquals('it', $this->testedConfig->get('config', 'test')); diff --git a/tests/src/Core/Config/JitConfigTest.php b/tests/src/Core/Config/JitConfigTest.php deleted file mode 100644 index a468ae7276..0000000000 --- a/tests/src/Core/Config/JitConfigTest.php +++ /dev/null @@ -1,255 +0,0 @@ -. - * - */ - -namespace Friendica\Test\src\Core\Config; - -use Friendica\Core\Config\Type\JitConfig; - -class JitConfigTest extends ConfigTest -{ - public function getInstance() - { - return new JitConfig($this->configCache, $this->configModel); - } - - /** - * @dataProvider dataConfigLoad - */ - public function testSetUp(array $data) - { - $this->configModel->shouldReceive('load') - ->with('config') - ->andReturn(['config' => $data['config']]) - ->once(); - - parent::testSetUp($data); - } - - /** - * @dataProvider dataConfigLoad - * - * @param array $data - * @param array $load - */ - public function testLoad(array $data, array $load) - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true) - ->times(count($load) + 1); - - $this->configModel->shouldReceive('load') - ->with('config') - ->andReturn(['config' => $data['config']]) - ->once(); - - foreach ($load as $loadCat) { - $this->configModel->shouldReceive('load') - ->with($loadCat) - ->andReturn([$loadCat => $data[$loadCat]]) - ->once(); - } - - parent::testLoad($data, $load); - } - - /** - * @dataProvider dataDoubleLoad - */ - public function testCacheLoadDouble(array $data1, array $data2, array $expect = []) - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true) - ->times(count($data1) + count($data2) + 1); - - $this->configModel->shouldReceive('load') - ->with('config') - ->andReturn(['config' => $data1['config']]) - ->once(); - - foreach ($data1 as $cat => $data) { - $this->configModel->shouldReceive('load') - ->with($cat) - ->andReturn([$cat => $data]) - ->once(); - } - - - foreach ($data2 as $cat => $data) { - $this->configModel->shouldReceive('load') - ->with($cat) - ->andReturn([$cat => $data]) - ->once(); - } - - parent::testCacheLoadDouble($data1, $data2); - - // Assert the expected categories - foreach ($data2 as $cat => $data) { - self::assertConfig($cat, $expect[$cat]); - } - } - - /** - * @dataProvider dataTests - */ - public function testSetGetWithDB($data) - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true) - ->times(3); - - $this->configModel->shouldReceive('load')->with('config')->andReturn(['config' => []])->once(); - - parent::testSetGetWithDB($data); - } - - /** - * @dataProvider dataTests - */ - public function testGetWithRefresh($data) - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true) - ->times(4); - - // constructor loading - $this->configModel->shouldReceive('load') - ->with('config') - ->andReturn(['config' => []]) - ->once(); - - // mocking one get without result - $this->configModel->shouldReceive('get') - ->with('test', 'it') - ->andReturn(null) - ->once(); - - // mocking the data get - $this->configModel->shouldReceive('get') - ->with('test', 'it') - ->andReturn($data) - ->once(); - - // mocking second get - $this->configModel->shouldReceive('get') - ->with('test', 'not') - ->andReturn(null) - ->once(); - - parent::testGetWithRefresh($data); - } - - public function testGetWrongWithoutDB() - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(false) - ->times(4); - - parent::testGetWrongWithoutDB(); - } - - /** - * @dataProvider dataTests - */ - public function testDeleteWithoutDB($data) - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(false) - ->times(4); - - parent::testDeleteWithoutDB($data); - } - - public function testDeleteWithDB() - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true) - ->times(6); - - // constructor loading - $this->configModel->shouldReceive('load') - ->with('config') - ->andReturn(['config' => []]) - ->once(); - - // mocking one get without result - $this->configModel->shouldReceive('get') - ->with('test', 'it') - ->andReturn(null) - ->once(); - - parent::testDeleteWithDB(); - } - - public function testSetGetHighPrio() - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true); - - // constructor loading - $this->configModel->shouldReceive('load') - ->with('config') - ->andReturn(['config' => []]) - ->once(); - - $this->configModel->shouldReceive('get') - ->with('config', 'test') - ->andReturn('prio') - ->once(); - - $this->configModel->shouldReceive('set') - ->with('config', 'test', '123') - ->andReturn(true) - ->once(); - - $this->configModel->shouldReceive('get') - ->with('config', 'test') - ->andReturn('123') - ->once(); - - parent::testSetGetHighPrio(); - } - - public function testSetGetLowPrio() - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true); - - // constructor loading - $this->configModel->shouldReceive('load') - ->with('config') - ->andReturn(['config' => ['test' => 'it']]) - ->once(); - - $this->configModel->shouldReceive('set') - ->with('config', 'test', '123') - ->andReturn(true) - ->once(); - - // mocking one get without result - $this->configModel->shouldReceive('get') - ->with('config', 'test') - ->andReturn('it') - ->once(); - - parent::testSetGetLowPrio(); - } -} diff --git a/tests/src/Core/Config/PreloadConfigTest.php b/tests/src/Core/Config/PreloadConfigTest.php deleted file mode 100644 index 1f51427613..0000000000 --- a/tests/src/Core/Config/PreloadConfigTest.php +++ /dev/null @@ -1,213 +0,0 @@ -. - * - */ - -namespace Friendica\Test\src\Core\Config; - -use Friendica\Core\Config\Type\PreloadConfig; - -class PreloadConfigTest extends ConfigTest -{ - public function getInstance() - { - return new PreloadConfig($this->configCache, $this->configModel); - } - - /** - * @dataProvider dataConfigLoad - */ - public function testSetUp(array $data) - { - $this->configModel->shouldReceive('load') - ->andReturn($data) - ->once(); - - parent::testSetUp($data); - } - - /** - * @dataProvider dataConfigLoad - * - * @param array $data - * @param array $load - */ - public function testLoad(array $data, array $load) - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true) - ->once(); - - $this->configModel->shouldReceive('load') - ->andReturn($data) - ->once(); - - parent::testLoad($data, $load); - - // Assert that every category is loaded everytime - foreach ($data as $cat => $values) { - self::assertConfig($cat, $values); - } - } - - /** - * @dataProvider dataDoubleLoad - * - * @param array $data1 - * @param array $data2 - */ - public function testCacheLoadDouble(array $data1, array $data2, array $expect = []) - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true) - ->once(); - - $this->configModel->shouldReceive('load') - ->andReturn($data1) - ->once(); - - parent::testCacheLoadDouble($data1, $data2); - - // Assert that every category is loaded everytime and is NOT overwritten - foreach ($data1 as $cat => $values) { - self::assertConfig($cat, $values); - } - } - - /** - * @dataProvider dataTests - */ - public function testSetGetWithDB($data) - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true) - ->times(2); - - $this->configModel->shouldReceive('load')->andReturn(['config' => []])->once(); - - parent::testSetGetWithDB($data); - } - - /** - * @dataProvider dataTests - */ - public function testGetWithRefresh($data) - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true) - ->times(2); - - // constructor loading - $this->configModel->shouldReceive('load') - ->andReturn(['config' => []]) - ->once(); - - // mocking one get - $this->configModel->shouldReceive('get') - ->with('test', 'it') - ->andReturn($data) - ->once(); - - parent::testGetWithRefresh($data); - } - - - public function testGetWrongWithoutDB() - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(false) - ->times(2); - - parent::testGetWrongWithoutDB(); - } - - /** - * @dataProvider dataTests - */ - public function testDeleteWithoutDB($data) - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(false) - ->times(2); - - parent::testDeleteWithoutDB($data); - } - - public function testDeleteWithDB() - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true) - ->times(5); - - // constructor loading - $this->configModel->shouldReceive('load') - ->andReturn(['config' => []]) - ->once(); - - parent::testDeleteWithDB(); - } - - - public function testSetGetHighPrio() - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true); - - // constructor loading - $this->configModel->shouldReceive('load') - ->andReturn(['config' => []]) - ->once(); - - $this->configModel->shouldReceive('set') - ->with('config', 'test', '123') - ->andReturn(true) - ->once(); - - $this->configModel->shouldReceive('get') - ->with('config', 'test') - ->andReturn('123') - ->once(); - - parent::testSetGetHighPrio(); - } - - public function testSetGetLowPrio() - { - $this->configModel->shouldReceive('isConnected') - ->andReturn(true); - - // constructor loading - $this->configModel->shouldReceive('load') - ->andReturn(['config' => ['test' => 'it']]) - ->once(); - - $this->configModel->shouldReceive('set') - ->with('config', 'test', '123') - ->andReturn(true) - ->once(); - - // mocking one get without result - $this->configModel->shouldReceive('get') - ->with('config', 'test') - ->andReturn('it') - ->once(); - - parent::testSetGetLowPrio(); - } -} diff --git a/tests/src/Core/Lock/SemaphoreLockTest.php b/tests/src/Core/Lock/SemaphoreLockTest.php index a8f95f6fc6..6473935cab 100644 --- a/tests/src/Core/Lock/SemaphoreLockTest.php +++ b/tests/src/Core/Lock/SemaphoreLockTest.php @@ -24,7 +24,10 @@ namespace Friendica\Test\src\Core\Lock; use Dice\Dice; use Friendica\App; use Friendica\Core\Config\Capability\IManageConfigValues; +use Friendica\Core\Config\Model\Config; use Friendica\Core\Config\Type\JitConfig; +use Friendica\Core\Config\Util\ConfigFileManager; +use Friendica\Core\Config\ValueObject\Cache; use Friendica\Core\Lock\Type\SemaphoreLock; use Friendica\Core\System; use Friendica\DI; @@ -42,11 +45,8 @@ class SemaphoreLockTest extends LockTest $app->shouldReceive('getHostname')->andReturn('friendica.local'); $dice->shouldReceive('create')->with(App::class)->andReturn($app); - $configMock = Mockery::mock(JitConfig::class); - $configMock - ->shouldReceive('get') - ->with('system', 'temppath') - ->andReturn('/tmp/'); + $configCache = new Cache(['system' => ['temppath' => '/tmp']]); + $configMock = new Config(Mockery::mock(ConfigFileManager::class), $configCache); $dice->shouldReceive('create')->with(IManageConfigValues::class)->andReturn($configMock); // @todo Because "get_temppath()" is using static methods, we have to initialize the BaseObject diff --git a/tests/src/Core/Storage/Repository/StorageManagerTest.php b/tests/src/Core/Storage/Repository/StorageManagerTest.php index af198706f6..db4ca8ef2b 100644 --- a/tests/src/Core/Storage/Repository/StorageManagerTest.php +++ b/tests/src/Core/Storage/Repository/StorageManagerTest.php @@ -22,9 +22,7 @@ namespace Friendica\Test\src\Core\Storage\Repository; use Dice\Dice; -use Friendica\App\Mode; use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\Config\Type\PreloadConfig; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Session\Capability\IHandleSessions; @@ -41,7 +39,6 @@ use Friendica\Database\Definition\DbaDefinition; use Friendica\Database\Definition\ViewDefinition; use Friendica\DI; use Friendica\Core\Config\Factory\Config; -use Friendica\Core\Config\Repository; use Friendica\Core\Storage\Type; use Friendica\Test\DatabaseTest; use Friendica\Test\Util\Database\StaticDatabase; @@ -89,8 +86,7 @@ class StorageManagerTest extends DatabaseTest $this->dba = new StaticDatabase($configCache, $profiler, $dbaDefinition, $viewDefinition); - $configModel = new Repository\Config($this->dba, new Mode(Mode::DBCONFIGAVAILABLE)); - $this->config = new PreloadConfig($configCache, $configModel); + $this->config = new \Friendica\Core\Config\Model\Config($loader, $configCache); $this->config->set('storage', 'name', 'Database'); $this->config->set('storage', 'filesystem_path', $this->root->getChild(Type\FilesystemConfig::DEFAULT_BASE_FOLDER)->url()); diff --git a/tests/src/Database/DBATest.php b/tests/src/Database/DBATest.php index 44a6e01d3b..0c3c5e1604 100644 --- a/tests/src/Database/DBATest.php +++ b/tests/src/Database/DBATest.php @@ -52,10 +52,7 @@ class DBATest extends DatabaseTest */ public function testExists() { - self::assertTrue(DBA::exists('config', [])); + self::assertTrue(DBA::exists('user', [])); self::assertFalse(DBA::exists('notable', [])); - - self::assertTrue(DBA::exists('config', ['k' => 'hostname'])); - self::assertFalse(DBA::exists('config', ['k' => 'nonsense'])); } } diff --git a/tests/src/Database/DBStructureTest.php b/tests/src/Database/DBStructureTest.php index 67455f8512..dfb46514fd 100644 --- a/tests/src/Database/DBStructureTest.php +++ b/tests/src/Database/DBStructureTest.php @@ -44,30 +44,30 @@ class DBStructureTest extends DatabaseTest * @small */ public function testExists() { - self::assertTrue(DBStructure::existsTable('config')); + self::assertTrue(DBStructure::existsTable('user')); self::assertFalse(DBStructure::existsTable('notatable')); - self::assertTrue(DBStructure::existsColumn('config', ['k'])); - self::assertFalse(DBStructure::existsColumn('config', ['nonsense'])); - self::assertFalse(DBStructure::existsColumn('config', ['k', 'nonsense'])); + self::assertTrue(DBStructure::existsColumn('user', ['uid'])); + self::assertFalse(DBStructure::existsColumn('user', ['nonsense'])); + self::assertFalse(DBStructure::existsColumn('user', ['uid', 'nonsense'])); } /** * @small */ public function testRename() { - $fromColumn = 'k'; - $toColumn = 'key'; - $fromType = 'varbinary(255) not null'; - $toType = 'varbinary(255) not null comment \'Test To Type\''; + $fromColumn = 'email'; + $toColumn = 'email_key'; + $fromType = 'varchar(255) NOT NULL DEFAULT \'\' COMMENT \'the users email address\''; + $toType = 'varchar(255) NOT NULL DEFAULT \'\' COMMENT \'Adapted column\''; - self::assertTrue(DBStructure::rename('config', [ $fromColumn => [ $toColumn, $toType ]])); - self::assertTrue(DBStructure::existsColumn('config', [ $toColumn ])); - self::assertFalse(DBStructure::existsColumn('config', [ $fromColumn ])); + self::assertTrue(DBStructure::rename('user', [ $fromColumn => [ $toColumn, $toType ]])); + self::assertTrue(DBStructure::existsColumn('user', [ $toColumn ])); + self::assertFalse(DBStructure::existsColumn('user', [ $fromColumn ])); - self::assertTrue(DBStructure::rename('config', [ $toColumn => [ $fromColumn, $fromType ]])); - self::assertTrue(DBStructure::existsColumn('config', [ $fromColumn ])); - self::assertFalse(DBStructure::existsColumn('config', [ $toColumn ])); + self::assertTrue(DBStructure::rename('user', [ $toColumn => [ $fromColumn, $fromType ]])); + self::assertTrue(DBStructure::existsColumn('user', [ $fromColumn ])); + self::assertFalse(DBStructure::existsColumn('user', [ $toColumn ])); } /** diff --git a/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php b/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php index 034e1fc993..0d0afa64bc 100644 --- a/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php +++ b/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php @@ -26,6 +26,7 @@ use Friendica\App\Router; use Friendica\DI; use Friendica\Module\Api\GNUSocial\GNUSocial\Config; use Friendica\Test\src\Module\Api\ApiTest; +use Friendica\Test\Util\VFSTrait; class ConfigTest extends ApiTest { diff --git a/tests/src/Util/BaseURLTest.php b/tests/src/Util/BaseURLTest.php index 0be83be0a7..2733096e33 100644 --- a/tests/src/Util/BaseURLTest.php +++ b/tests/src/Util/BaseURLTest.php @@ -199,24 +199,34 @@ class BaseURLTest extends MockedTest $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($input['sslPolicy']); $configMock->shouldReceive('get')->with('system', 'url')->andReturn($input['url']); + $savable = false; + // If we don't have an urlPath as an input, we assert it, we will save it to the DB for the next time if (!isset($input['urlPath']) && isset($assert['urlPath'])) { - $configMock->shouldReceive('set')->with('system', 'urlpath', $assert['urlPath'])->once(); + $configMock->shouldReceive('set')->with('system', 'urlpath', $assert['urlPath'], false)->once(); + $savable = true; } // If we don't have the ssl_policy as an input, we assert it, we will save it to the DB for the next time if (!isset($input['sslPolicy']) && isset($assert['sslPolicy'])) { - $configMock->shouldReceive('set')->with('system', 'ssl_policy', $assert['sslPolicy'])->once(); + $configMock->shouldReceive('set')->with('system', 'ssl_policy', $assert['sslPolicy'], false)->once(); + $savable = true; } // If we don't have the hostname as an input, we assert it, we will save it to the DB for the next time if (empty($input['hostname']) && !empty($assert['hostname'])) { - $configMock->shouldReceive('set')->with('config', 'hostname', $assert['hostname'])->once(); + $configMock->shouldReceive('set')->with('config', 'hostname', $assert['hostname'], false)->once(); + $savable = true; } // If we don't have an URL at first, but we assert it, we will save it to the DB for the next time if (empty($input['url']) && !empty($assert['url'])) { - $configMock->shouldReceive('set')->with('system', 'url', $assert['url'])->once(); + $configMock->shouldReceive('set')->with('system', 'url', $assert['url'], false)->once(); + $savable = true; + } + + if ($savable) { + $configMock->shouldReceive('save')->once(); } $baseUrl = new BaseURL($configMock, $server); @@ -325,18 +335,20 @@ class BaseURLTest extends MockedTest $baseUrl = new BaseURL($configMock, []); if (isset($save['hostname'])) { - $configMock->shouldReceive('set')->with('config', 'hostname', $save['hostname'])->andReturn(true)->once(); + $configMock->shouldReceive('set')->with('config', 'hostname', $save['hostname'], false)->andReturn(true)->once(); } if (isset($save['urlPath'])) { - $configMock->shouldReceive('set')->with('system', 'urlpath', $save['urlPath'])->andReturn(true)->once(); + $configMock->shouldReceive('set')->with('system', 'urlpath', $save['urlPath'], false)->andReturn(true)->once(); } if (isset($save['sslPolicy'])) { - $configMock->shouldReceive('set')->with('system', 'ssl_policy', $save['sslPolicy'])->andReturn(true)->once(); + $configMock->shouldReceive('set')->with('system', 'ssl_policy', $save['sslPolicy'], false)->andReturn(true)->once(); } - $configMock->shouldReceive('set')->with('system', 'url', $url)->andReturn(true)->once(); + $configMock->shouldReceive('set')->with('system', 'url', $url, false)->andReturn(true)->once(); + + $configMock->shouldReceive('save')->once(); $baseUrl->save($save['hostname'], $save['sslPolicy'], $save['urlPath']); @@ -363,18 +375,20 @@ class BaseURLTest extends MockedTest $baseUrl = new BaseURL($configMock, []); if (isset($save['hostname'])) { - $configMock->shouldReceive('set')->with('config', 'hostname', $save['hostname'])->andReturn(true)->once(); + $configMock->shouldReceive('set')->with('config', 'hostname', $save['hostname'], false)->andReturn(true)->once(); } if (isset($save['urlPath'])) { - $configMock->shouldReceive('set')->with('system', 'urlpath', $save['urlPath'])->andReturn(true)->once(); + $configMock->shouldReceive('set')->with('system', 'urlpath', $save['urlPath'], false)->andReturn(true)->once(); } if (isset($save['sslPolicy'])) { - $configMock->shouldReceive('set')->with('system', 'ssl_policy', $save['sslPolicy'])->andReturn(true)->once(); + $configMock->shouldReceive('set')->with('system', 'ssl_policy', $save['sslPolicy'], false)->andReturn(true)->once(); } - $configMock->shouldReceive('set')->with('system', 'url', $url)->andReturn(true)->once(); + $configMock->shouldReceive('set')->with('system', 'url', $url, false)->andReturn(true)->once(); + + $configMock->shouldReceive('save')->once(); $baseUrl->saveByURL($url); @@ -531,22 +545,25 @@ class BaseURLTest extends MockedTest switch ($fail) { case 'hostname': - $configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any())->andReturn(false)->once(); + $configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any(), false)->andReturn(false)->once(); break; case 'sslPolicy': - $configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any())->andReturn(true)->twice(); - $configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any())->andReturn(false)->once(); + $configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any(), false)->andReturn(true)->twice(); + $configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any(), false)->andReturn(false)->once(); + $configMock->shouldReceive('save')->once(); break; case 'urlPath': - $configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any())->andReturn(true)->twice(); - $configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any())->andReturn(true)->twice(); - $configMock->shouldReceive('set')->with('system', 'urlpath', \Mockery::any())->andReturn(false)->once(); + $configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any(), false)->andReturn(true)->twice(); + $configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any(), false)->andReturn(true)->twice(); + $configMock->shouldReceive('set')->with('system', 'urlpath', \Mockery::any(), false)->andReturn(false)->once(); + $configMock->shouldReceive('save')->once(); break; case 'url': - $configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any())->andReturn(true)->twice(); - $configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any())->andReturn(true)->twice(); - $configMock->shouldReceive('set')->with('system', 'urlpath', \Mockery::any())->andReturn(true)->twice(); - $configMock->shouldReceive('set')->with('system', 'url', \Mockery::any())->andReturn(false)->once(); + $configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any(), false)->andReturn(true)->twice(); + $configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any(), false)->andReturn(true)->twice(); + $configMock->shouldReceive('set')->with('system', 'urlpath', \Mockery::any(), false)->andReturn(true)->twice(); + $configMock->shouldReceive('set')->with('system', 'url', \Mockery::any(), false)->andReturn(false)->once(); + $configMock->shouldReceive('save')->once(); break; } -- 2.39.5