]> git.mxchange.org Git - friendica.git/commitdiff
Refactor ConfigMockTrait to mocked ConfigCache
authorPhilipp Holzer <admin@philipp.info>
Thu, 7 Feb 2019 19:44:03 +0000 (20:44 +0100)
committerPhilipp Holzer <admin@philipp.info>
Thu, 7 Feb 2019 19:44:03 +0000 (20:44 +0100)
27 files changed:
src/Core/Config.php
src/Core/Config/AbstractDbaConfigAdapter.php [new file with mode: 0644]
src/Core/Config/ConfigCache.php
src/Core/Config/IConfigAdapter.php
src/Core/Config/IConfigCache.php
src/Core/Config/JITConfigAdapter.php
src/Core/Config/PreloadConfigAdapter.php
tests/Util/AppMockTrait.php
tests/Util/ConfigMockTrait.php [deleted file]
tests/Util/RendererMockTrait.php
tests/src/App/ModeTest.php
tests/src/BaseObjectTest.php
tests/src/Core/Cache/ArrayCacheDriverTest.php
tests/src/Core/Cache/CacheTest.php
tests/src/Core/Cache/DatabaseCacheDriverTest.php
tests/src/Core/Cache/MemcacheCacheDriverTest.php
tests/src/Core/Cache/MemcachedCacheDriverTest.php
tests/src/Core/Cache/RedisCacheDriverTest.php
tests/src/Core/Console/AutomaticInstallationConsoleTest.php
tests/src/Core/Console/ConfigConsoleTest.php
tests/src/Core/Lock/ArrayCacheLockDriverTest.php
tests/src/Core/Lock/LockTest.php
tests/src/Core/Lock/MemcacheCacheLockDriverTest.php
tests/src/Core/Lock/MemcachedCacheLockDriverTest.php
tests/src/Core/Lock/RedisCacheLockDriverTest.php
tests/src/Core/Lock/SemaphoreLockDriverTest.php
tests/src/Database/DBStructureTest.php

index 6ceb637701a251506c4d32a09b9d52af2edcfa55..559ee83ece57e08b8bfedb53d94510b082606459 100644 (file)
@@ -22,7 +22,7 @@ use Friendica\Core\Config\IConfigCache;
 class Config
 {
        /**
-        * @var Config\IConfigAdapter
+        * @var Config\IConfigAdapter|null
         */
        private static $adapter;
 
@@ -62,7 +62,7 @@ class Config
         */
        public static function load($family = "config")
        {
-               if (!isset(self::$adapter)) {
+               if (!isset(self::$adapter) || !self::$adapter->isConnected()) {
                        return;
                }
 
@@ -86,7 +86,7 @@ class Config
         */
        public static function get($family, $key, $default_value = null, $refresh = false)
        {
-               if (!isset(self::$adapter)) {
+               if (!isset(self::$adapter) || !self::$adapter->isConnected()) {
                        return self::$cache->get($family, $key, $default_value);
                }
 
@@ -108,9 +108,8 @@ class Config
         */
        public static function set($family, $key, $value)
        {
-               if (!isset(self::$adapter)) {
-                       self::$cache->set($family, $key, $value);
-                       return true;
+               if (!isset(self::$adapter) || !self::$adapter->isConnected()) {
+                       return self::$cache->set($family, $key, $value);
                }
 
                return self::$adapter->set($family, $key, $value);
@@ -129,7 +128,7 @@ class Config
         */
        public static function delete($family, $key)
        {
-               if (!isset(self::$adapter)) {
+               if (!isset(self::$adapter) || !self::$adapter->isConnected()) {
                        self::$cache->delete($family, $key);
                }
 
diff --git a/src/Core/Config/AbstractDbaConfigAdapter.php b/src/Core/Config/AbstractDbaConfigAdapter.php
new file mode 100644 (file)
index 0000000..f7fd701
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+namespace Friendica\Core\Config;
+
+use Friendica\Database\DBA;
+
+abstract class AbstractDbaConfigAdapter
+{
+       public function isConnected()
+       {
+               return DBA::connected();
+       }
+}
index e03d3525666464a849e5c09e53f4179b3abdfb05..0c9e1f48694ae7da78e661a5cea29238e21819a8 100644 (file)
@@ -94,6 +94,8 @@ class ConfigCache implements IConfigCache, IPConfigCache
 
                        $this->config[$cat][$key] = $value;
                }
+
+               return true;
        }
 
        /**
index 139483de26922d9db7761e2a413d7a6218af098a..70e141484eb3bd05cd6b3586dd2bdb0751c47fcd 100644 (file)
@@ -54,4 +54,11 @@ interface IConfigAdapter
         * @return mixed
         */
        public function delete($cat, $k);
+
+       /**
+        * Checks, if the current adapter is connected to the backend
+        *
+        * @return bool
+        */
+       public function isConnected();
 }
index 8266cc2dd4399f87a77ef094d265e4a72ab682e2..898e3c0f863b81ed631360be1a28b4901671a516 100644 (file)
@@ -22,6 +22,8 @@ interface IConfigCache
         * @param string $cat   Config category
         * @param string $key   Config key
         * @param mixed  $value Value to set
+        *
+        * @return bool True, if the value is set
         */
        function set($cat, $key, $value);
 
index e7aecb933b673af56a7a65e9f3cdccf28f596d37..76476be3aa4e8c94021658557a88dd13343d1369 100644 (file)
@@ -10,7 +10,7 @@ use Friendica\Database\DBA;
  *
  * @author Hypolite Petovan <hypolite@mrpetovan.com>
  */
-class JITConfigAdapter implements IConfigAdapter
+class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapter
 {
        private $cache;
        private $in_db;
@@ -33,6 +33,10 @@ class JITConfigAdapter implements IConfigAdapter
         */
        public function load($cat = "config")
        {
+               if (!$this->isConnected()) {
+                       return;
+               }
+
                // We don't preload "system" anymore.
                // This reduces the number of database reads a lot.
                if ($cat === 'system') {
@@ -58,6 +62,10 @@ class JITConfigAdapter implements IConfigAdapter
         */
        public function get($cat, $k, $default_value = null, $refresh = false)
        {
+               if (!$this->isConnected()) {
+                       return $default_value;
+               }
+
                if (!$refresh) {
                        // Do we have the cached value? Then return it
                        if (isset($this->cache[$cat][$k])) {
@@ -103,6 +111,10 @@ class JITConfigAdapter implements IConfigAdapter
         */
        public function set($cat, $k, $value)
        {
+               if (!$this->isConnected()) {
+                       return false;
+               }
+
                // We store our setting values in a string variable.
                // So we have to do the conversion here so that the compare below works.
                // The exception are array values.
@@ -143,6 +155,10 @@ class JITConfigAdapter implements IConfigAdapter
         */
        public function delete($cat, $k)
        {
+               if (!$this->isConnected()) {
+                       return false;
+               }
+
                if (isset($this->cache[$cat][$k])) {
                        unset($this->cache[$cat][$k]);
                        unset($this->in_db[$cat][$k]);
index d5fbd982bf56e6f912fa5568c3168087819fdf61..2fe3d4cdad61ed213e283d0b31d10467fdd15405 100644 (file)
@@ -12,7 +12,7 @@ use Friendica\Database\DBA;
  *
  * @author Hypolite Petovan <hypolite@mrpetovan.com>
  */
-class PreloadConfigAdapter implements IConfigAdapter
+class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapter
 {
        private $config_loaded = false;
 
@@ -35,6 +35,10 @@ class PreloadConfigAdapter implements IConfigAdapter
         */
        public function load($family = 'config')
        {
+               if (!$this->isConnected()) {
+                       return;
+               }
+
                if ($this->config_loaded) {
                        return;
                }
@@ -53,6 +57,10 @@ class PreloadConfigAdapter implements IConfigAdapter
         */
        public function get($cat, $k, $default_value = null, $refresh = false)
        {
+               if (!$this->isConnected()) {
+                       return $default_value;
+               }
+
                if ($refresh) {
                        $config = DBA::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $k]);
                        if (DBA::isResult($config)) {
@@ -70,6 +78,10 @@ class PreloadConfigAdapter implements IConfigAdapter
         */
        public function set($cat, $k, $value)
        {
+               if (!$this->isConnected()) {
+                       return false;
+               }
+
                // We store our setting values as strings.
                // So we have to do the conversion here so that the compare below works.
                // The exception are array values.
@@ -97,6 +109,10 @@ class PreloadConfigAdapter implements IConfigAdapter
         */
        public function delete($cat, $k)
        {
+               if (!$this->isConnected()) {
+                       return false;
+               }
+
                $this->configCache->delete($cat, $k);
 
                $result = DBA::delete('config', ['cat' => $cat, 'k' => $k]);
index 290191cba125b6e40fca01d5d1a8f279e9e459da..18188239f1760ee2aff511f9a4a3a5524d10a270 100644 (file)
@@ -4,6 +4,7 @@ namespace Friendica\Test\Util;
 
 use Friendica\App;
 use Friendica\BaseObject;
+use Friendica\Core\Config;
 use Friendica\Core\Config\ConfigCache;
 use Friendica\Render\FriendicaSmartyEngine;
 use Mockery\MockInterface;
@@ -14,13 +15,16 @@ use org\bovigo\vfs\vfsStreamDirectory;
  */
 trait AppMockTrait
 {
-       use ConfigMockTrait;
-
        /**
         * @var MockInterface|App The mocked Friendica\App
         */
        protected $app;
 
+       /**
+        * @var MockInterface|ConfigCache The mocked Config Cache
+        */
+       protected $configCache;
+
        /**
         * Mock the App
         *
@@ -29,8 +33,7 @@ trait AppMockTrait
         */
        public function mockApp($root, $config)
        {
-               $this->mockConfigGet('system', 'theme', 'testtheme');
-
+               $this->configCache = $config;
                // Mocking App and most used functions
                $this->app = \Mockery::mock(App::class);
                $this->app
@@ -53,6 +56,15 @@ trait AppMockTrait
                        ->shouldReceive('get')
                        ->with('database', 'database')
                        ->andReturn(getenv('MYSQL_DATABASE'));
+               $config
+                       ->shouldReceive('get')
+                       ->with('config', 'hostname')
+                       ->andReturn('localhost');
+               $config
+                       ->shouldReceive('get')
+                       ->with('system', 'theme', NULL)
+                       ->andReturn('system_theme');
+
                $this->app
                        ->shouldReceive('getConfig')
                        ->andReturn($config);
@@ -70,6 +82,14 @@ trait AppMockTrait
                        ->shouldReceive('getBaseUrl')
                        ->andReturn('http://friendica.local');
 
+               // Initialize empty Config
+               Config::init($config);
+               $configAdapter = \Mockery::mock('Friendica\Core\Config\IConfigAdapter');
+               $configAdapter
+                       ->shouldReceive('isConnected')
+                       ->andReturn(false);
+               Config::setAdapter($configAdapter);
+
                BaseObject::setApp($this->app);
        }
 }
diff --git a/tests/Util/ConfigMockTrait.php b/tests/Util/ConfigMockTrait.php
deleted file mode 100644 (file)
index d2867a5..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-
-namespace Friendica\Test\Util;
-
-use Mockery\MockInterface;
-
-/**
- * Trait to Mock Config settings
- */
-trait ConfigMockTrait
-{
-       /**
-        * @var MockInterface The mocking interface of Friendica\Core\Config
-        */
-       private $configMock;
-
-       /**
-        * Mocking a config setting
-        *
-        * @param string $family The family of the config double
-        * @param string $key The key of the config double
-        * @param mixed $value The value of the config double
-        * @param null|int $times How often the Config will get used
-        */
-       public function mockConfigGet($family, $key, $value, $times = null)
-       {
-               if (!isset($this->configMock)) {
-                       $this->configMock = \Mockery::mock('alias:Friendica\Core\Config');
-               }
-
-               $this->configMock
-                       ->shouldReceive('get')
-                       ->times($times)
-                       ->with($family, $key)
-                       ->andReturn($value);
-       }
-
-       /**
-        * Mocking setting a new config entry
-        *
-        * @param string $family The family of the config double
-        * @param string $key The key of the config double
-        * @param mixed $value The value of the config double
-        * @param null|int $times How often the Config will get used
-        * @param bool $return Return value of the set (default is true)
-        */
-       public function mockConfigSet($family, $key, $value, $times = null, $return = true)
-       {
-               if (!isset($this->configMock)) {
-                       $this->configMock = \Mockery::mock('alias:Friendica\Core\Config');
-               }
-
-               $this->mockConfigGet($family, $key, false, 1);
-               if ($return) {
-                       $this->mockConfigGet($family, $key, $value, 1);
-               }
-
-               $this->configMock
-                       ->shouldReceive('set')
-                       ->times($times)
-                       ->with($family, $key, $value)
-                       ->andReturn($return);
-       }
-}
index b12327f49cf0de18345fc9d926e3ec5d880702e4..bea0fe16fc24db01e00e969b2455982fe3b03003 100644 (file)
@@ -1,14 +1,7 @@
 <?php
-/**
- * Created by PhpStorm.
- * User: philipp
- * Date: 01.11.18
- * Time: 10:08
- */
 
 namespace Friendica\Test\Util;
 
-
 use Mockery\MockInterface;
 
 trait RendererMockTrait
index d534e24edea507c9a8eb5bf3049883976e998607..19dad07cd6eae94af0e590cc0f410889eaa6e38b 100644 (file)
@@ -3,24 +3,19 @@
 namespace Friendica\Test\src\App;
 
 use Friendica\App\Mode;
+use Friendica\Core\Config;
 use Friendica\Test\MockedTest;
-use Friendica\Test\Util\ConfigMockTrait;
 use Friendica\Test\Util\DBAMockTrait;
 use Friendica\Test\Util\VFSTrait;
 
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- */
 class ModeTest extends MockedTest
 {
        use VFSTrait;
        use DBAMockTrait;
-       use ConfigMockTrait;
 
        public function setUp()
        {
-               parent::setUp(); // TODO: Change the autogenerated stub
+               parent::setUp();
 
                $this->setUpVfsDir();
        }
@@ -50,6 +45,10 @@ class ModeTest extends MockedTest
                $this->assertFalse($mode->has(Mode::LOCALCONFIGPRESENT));
        }
 
+       /**
+        * @runInSeparateProcess
+        * @preserveGlobalState disabled
+        */
        public function testWithoutDatabase()
        {
                $this->mockConnected(false, 1);
@@ -64,6 +63,10 @@ class ModeTest extends MockedTest
                $this->assertFalse($mode->has(Mode::DBAVAILABLE));
        }
 
+       /**
+        * @runInSeparateProcess
+        * @preserveGlobalState disabled
+        */
        public function testWithoutDatabaseSetup()
        {
                $this->mockConnected(true, 1);
@@ -78,11 +81,28 @@ class ModeTest extends MockedTest
                $this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
        }
 
+       /**
+        * @runInSeparateProcess
+        * @preserveGlobalState disabled
+        */
        public function testWithMaintenanceMode()
        {
                $this->mockConnected(true, 1);
                $this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
-               $this->mockConfigGet('system', 'maintenance', true, 1);
+
+               $config = \Mockery::mock('Friendica\Core\Config\ConfigCache');
+               $config
+                       ->shouldReceive('get')
+                       ->with('system', 'maintenance', null)
+                       ->andReturn(true)
+                       ->once();
+               // Initialize empty Config
+               Config::init($config);
+               $configAdapter = \Mockery::mock('Friendica\Core\Config\IConfigAdapter');
+               $configAdapter
+                       ->shouldReceive('isConnected')
+                       ->andReturn(false);
+               Config::setAdapter($configAdapter);
 
                $mode = new Mode($this->root->url());
                $mode->determine();
@@ -94,11 +114,28 @@ class ModeTest extends MockedTest
                $this->assertFalse($mode->has(Mode::MAINTENANCEDISABLED));
        }
 
+       /**
+        * @runInSeparateProcess
+        * @preserveGlobalState disabled
+        */
        public function testNormalMode()
        {
                $this->mockConnected(true, 1);
                $this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
-               $this->mockConfigGet('system', 'maintenance', false, 1);
+
+               $config = \Mockery::mock('Friendica\Core\Config\ConfigCache');
+               $config
+                       ->shouldReceive('get')
+                       ->with('system', 'maintenance', null)
+                       ->andReturn(false)
+                       ->once();
+               // Initialize empty Config
+               Config::init($config);
+               $configAdapter = \Mockery::mock('Friendica\Core\Config\IConfigAdapter');
+               $configAdapter
+                       ->shouldReceive('isConnected')
+                       ->andReturn(false);
+               Config::setAdapter($configAdapter);
 
                $mode = new Mode($this->root->url());
                $mode->determine();
index b2c73780a4499247544524f0f515636a1979f298..784944c3a06425a35a6aa8b78da5f5245c6fa299 100644 (file)
@@ -5,7 +5,6 @@
 
 namespace Friendica\Test;
 
-use Friendica\App;
 use Friendica\BaseObject;
 use Friendica\Test\Util\AppMockTrait;
 use Friendica\Test\Util\VFSTrait;
@@ -13,8 +12,6 @@ use PHPUnit\Framework\TestCase;
 
 /**
  * Tests for the BaseObject class.
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
  */
 class BaseObjectTest extends TestCase
 {
@@ -27,46 +24,29 @@ class BaseObjectTest extends TestCase
        private $baseObject;
 
        /**
-        * Create variables used in tests.
-        */
-       protected function setUp()
-       {
-               $this->baseObject = new BaseObject();
-       }
-
-       /**
-        * Test the getApp() function.
-        * @return void
-        */
-       public function testGetApp()
-       {
-               $this->setUpVfsDir();
-               $configMock = \Mockery::mock('Friendica\Core\Config\ConfigCache');
-               $this->mockApp($this->root, $configMock);
-
-               $this->assertInstanceOf(App::class, $this->baseObject->getApp());
-       }
-
-       /**
-        * Test the setApp() function.
+        * Test the setApp() and getApp() function.
         * @return void
         */
-       public function testSetApp()
+       public function testGetSetApp()
        {
+               $baseObject = new BaseObject();
                $this->setUpVfsDir();
                $configMock = \Mockery::mock('Friendica\Core\Config\ConfigCache');
                $this->mockApp($this->root, $configMock);
 
-               $this->assertNull($this->baseObject->setApp($this->app));
-               $this->assertEquals($this->app, $this->baseObject->getApp());
+               $this->assertNull($baseObject->setApp($this->app));
+               $this->assertEquals($this->app, $baseObject->getApp());
        }
 
        /**
         * Test the getApp() function without App
         * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
+        * @runInSeparateProcess
+        * @preserveGlobalState disabled
         */
        public function testGetAppFailed()
        {
-               BaseObject::getApp();
+               $baseObject = new BaseObject();
+               $baseObject->getApp();
        }
 }
index 62c599d54003258e8e180f9fed4aa4a85f2fd777..c92fb98dacc2c370dd24ed4554fcb6132fee60df 100644 (file)
@@ -2,13 +2,8 @@
 
 namespace Friendica\Test\src\Core\Cache;
 
-
 use Friendica\Core\Cache\ArrayCache;
 
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- */
 class ArrayCacheDriverTest extends MemoryCacheTest
 {
        protected function getInstance()
index d0b357bf465dad6a77768cb9fc9ec48110b6c763..e8bd65cbfe5670c0865dd28537b6f39b67684c44 100644 (file)
@@ -5,7 +5,6 @@ namespace Friendica\Test\src\Core\Cache;
 use Friendica\Core\Cache\MemcachedCacheDriver;
 use Friendica\Test\MockedTest;
 use Friendica\Test\Util\AppMockTrait;
-use Friendica\Test\Util\DateTimeFormatMockTrait;
 use Friendica\Test\Util\VFSTrait;
 use Friendica\Util\PidFile;
 
@@ -13,7 +12,6 @@ abstract class CacheTest extends MockedTest
 {
        use VFSTrait;
        use AppMockTrait;
-       use DateTimeFormatMockTrait;
 
        /**
         * @var int Start time of the mock (used for time operations)
@@ -75,19 +73,10 @@ abstract class CacheTest extends MockedTest
                        ->shouldReceive('getHostname')
                        ->andReturn('friendica.local');
 
-               $this->mockUtcNow($this->startTime);
-
                parent::setUp();
 
                $this->instance = $this->getInstance();
 
-               // Default config
-               $this->mockConfigGet('config', 'hostname', 'localhost');
-               $this->mockConfigGet('system', 'throttle_limit_day', 100);
-               $this->mockConfigGet('system', 'throttle_limit_week', 100);
-               $this->mockConfigGet('system', 'throttle_limit_month', 100);
-               $this->mockConfigGet('system', 'theme', 'system_theme');
-
                $this->instance->clear(false);
        }
 
index f035f3fecde902cdc2be23364f239ccb9f4ad150..775a083a9b30059d3f8db6f1f2f8c9336402babe 100644 (file)
@@ -16,6 +16,8 @@ class DatabaseCacheDriverTest extends CacheTest
 
        public function setUp()
        {
+               $this->mockUtcNow($this->startTime);
+
                $this->mockConnected();
                $this->mockConnect();
 
index 4a4c4ebd7eb7be134602caa17758c19e326598a4..7832344a89522071a47da49efada0689d9e8256c 100644 (file)
@@ -6,16 +6,21 @@ namespace Friendica\Test\src\Core\Cache;
 use Friendica\Core\Cache\CacheDriverFactory;
 
 /**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
  * @requires extension memcache
  */
 class MemcacheCacheDriverTest extends MemoryCacheTest
 {
        protected function getInstance()
        {
-               $this->mockConfigGet('system', 'memcache_host', 'localhost', 1);
-               $this->mockConfigGet('system', 'memcache_port', 11211, 1);
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('system', 'memcache_host', NULL)
+                       ->andReturn('localhost');
+
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('system', 'memcache_port', NULL)
+                       ->andReturn(11211);
 
                $this->cache = CacheDriverFactory::create('memcache');
                return $this->cache;
index b118ee0f6ef3a4f5245587f79ede8df0ad6c9691..fe401f97dd40d95d718ebf8fe5959884684300de 100644 (file)
@@ -6,15 +6,16 @@ namespace Friendica\Test\src\Core\Cache;
 use Friendica\Core\Cache\CacheDriverFactory;
 
 /**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
  * @requires extension memcached
  */
 class MemcachedCacheDriverTest extends MemoryCacheTest
 {
        protected function getInstance()
        {
-               $this->mockConfigGet('system', 'memcached_hosts', [0 => 'localhost, 11211']);
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('system', 'memcached_hosts', NULL)
+                       ->andReturn([0 => 'localhost, 11211']);
 
                $this->cache = CacheDriverFactory::create('memcached');
                return $this->cache;
index 4530ff1c025b16dedbf54d624bfdc0cbe9751846..0a3dba439d83ace9f5b254667e06d73e50de131f 100644 (file)
@@ -6,16 +6,21 @@ namespace Friendica\Test\src\Core\Cache;
 use Friendica\Core\Cache\CacheDriverFactory;
 
 /**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
  * @requires extension redis
  */
 class RedisCacheDriverTest extends MemoryCacheTest
 {
        protected function getInstance()
        {
-               $this->mockConfigGet('system', 'redis_host', 'localhost', 1);
-               $this->mockConfigGet('system', 'redis_port', null, 1);
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('system', 'redis_host', NULL)
+                       ->andReturn('localhost');
+
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('system', 'redis_port', NULL)
+                       ->andReturn(null);
 
                $this->cache = CacheDriverFactory::create('redis');
                return $this->cache;
index 127a8bc3f87bdf38fdd4228de33925b1ec94f91f..41ccce0b28827410ebe67a6695d9788032af77b1 100644 (file)
@@ -52,7 +52,10 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
                $this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER');
                $this->db_pass = getenv('MYSQL_PASSWORD');
 
-               $this->mockConfigGet('config', 'php_path', false);
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('config', 'php_path', NULL)
+                       ->andReturn(false);
 
                $this->mockL10nT();
        }
index 4ee34917d8a5d9a77fec70dfd6d659218655ea7b..505c4f794dc58db64f1299d673798e2cb7c14a70 100644 (file)
@@ -32,7 +32,17 @@ class ConfigConsoleTest extends ConsoleTest
        }
 
        function testSetGetKeyValue() {
-               $this->mockConfigSet('config', 'test', 'now', 1);
+               $this->configCache
+                       ->shouldReceive('set')
+                       ->with('config', 'test', 'now')
+                       ->andReturn(true)
+                       ->once();
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('config', 'test', NULL)
+                       ->andReturn('now')
+                       ->twice();
+
                $console = new Config($this->consoleArgv);
                $console->setArgument(0, 'config');
                $console->setArgument(1, 'test');
@@ -40,14 +50,24 @@ class ConfigConsoleTest extends ConsoleTest
                $txt = $this->dumpExecute($console);
                $this->assertEquals("config.test <= now\n", $txt);
 
-               $this->mockConfigGet('config', 'test', 'now', 1);
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('config', 'test', null)
+                       ->andReturn('now')
+                       ->once();
+
                $console = new Config($this->consoleArgv);
                $console->setArgument(0, 'config');
                $console->setArgument(1, 'test');
                $txt = $this->dumpExecute($console);
                $this->assertEquals("config.test => now\n", $txt);
 
-               $this->mockConfigGet('config', 'test', null, 1);
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('config', 'test', null)
+                       ->andReturn(null)
+                       ->once();
+
                $console = new Config($this->consoleArgv);
                $console->setArgument(0, 'config');
                $console->setArgument(1, 'test');
@@ -57,7 +77,11 @@ class ConfigConsoleTest extends ConsoleTest
 
        function testSetArrayValue() {
                $testArray = [1, 2, 3];
-               $this->mockConfigGet('config', 'test', $testArray, 1);
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('config', 'test', null)
+                       ->andReturn($testArray)
+                       ->once();
 
                $console = new Config($this->consoleArgv);
                $console->setArgument(0, 'config');
@@ -81,7 +105,11 @@ class ConfigConsoleTest extends ConsoleTest
        }
 
        function testVerbose() {
-               $this->mockConfigGet('test', 'it', 'now', 1);
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('test', 'it', null)
+                       ->andReturn('now')
+                       ->once();
                $console = new Config($this->consoleArgv);
                $console->setArgument(0, 'test');
                $console->setArgument(1, 'it');
@@ -105,7 +133,16 @@ CONF;
        }
 
        function testUnableToSet() {
-               $this->mockConfigSet('test', 'it', 'now', 1, false);
+               $this->configCache
+                       ->shouldReceive('set')
+                       ->with('test', 'it', 'now')
+                       ->andReturn(false)
+                       ->once();
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('test', 'it', NULL)
+                       ->andReturn(NULL)
+                       ->once();
                $console = new Config();
                $console->setArgument(0, 'test');
                $console->setArgument(1, 'it');
index bfea27253f1599af697be02569504fb89a9498e8..671341718b78168e5d15ffaadcd05d50747ed34d 100644 (file)
@@ -6,10 +6,6 @@ namespace Friendica\Test\src\Core\Lock;
 use Friendica\Core\Cache\ArrayCache;
 use Friendica\Core\Lock\CacheLockDriver;
 
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- */
 class ArrayCacheLockDriverTest extends LockTest
 {
        protected function getInstance()
index 2d11a71ae18946c153d726f0c56833d881914995..ab8e1b2f2efc1f60171c22b021b908e4f33bcde4 100644 (file)
@@ -25,10 +25,6 @@ abstract class LockTest extends MockedTest
 
        protected function setUp()
        {
-               parent::setUp();
-               $this->instance = $this->getInstance();
-               $this->instance->releaseAll();
-
                // Reusable App object
                $this->setUpVfsDir();
                $configMock = \Mockery::mock('Friendica\Core\Config\ConfigCache');
@@ -37,12 +33,9 @@ abstract class LockTest extends MockedTest
                        ->shouldReceive('getHostname')
                        ->andReturn('friendica.local');
 
-               // Default config
-               $this->mockConfigGet('config', 'hostname', 'localhost');
-               $this->mockConfigGet('system', 'throttle_limit_day', 100);
-               $this->mockConfigGet('system', 'throttle_limit_week', 100);
-               $this->mockConfigGet('system', 'throttle_limit_month', 100);
-               $this->mockConfigGet('system', 'theme', 'system_theme');
+               parent::setUp();
+               $this->instance = $this->getInstance();
+               $this->instance->releaseAll();
        }
 
        protected function tearDown()
index d7002037e0def7f4f6dcff67c06088ef94c949f9..46f29f52e2f9da8a758f2d3a68e9e063bfa390d6 100644 (file)
@@ -8,15 +8,20 @@ use Friendica\Core\Lock\CacheLockDriver;
 
 /**
  * @requires extension Memcache
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
  */
 class MemcacheCacheLockDriverTest extends LockTest
 {
        protected function getInstance()
        {
-               $this->mockConfigGet('system', 'memcache_host', 'localhost', 1);
-               $this->mockConfigGet('system', 'memcache_port', 11211, 1);
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('system', 'memcache_host', NULL)
+                       ->andReturn('localhost');
+
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('system', 'memcache_port', NULL)
+                       ->andReturn(11211);
 
                return new CacheLockDriver(CacheDriverFactory::create('memcache'));
        }
index 3ba6de53efce02e8832752ef85e48fe362149827..72271c98b9ef98d2c87dd72998e0e687e39156bf 100644 (file)
@@ -8,14 +8,15 @@ use Friendica\Core\Lock\CacheLockDriver;
 
 /**
  * @requires extension memcached
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
  */
 class MemcachedCacheLockDriverTest extends LockTest
 {
        protected function getInstance()
        {
-               $this->mockConfigGet('system', 'memcached_hosts', [0 => 'localhost, 11211']);
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('system', 'memcached_hosts', NULL)
+                       ->andReturn([0 => 'localhost, 11211']);
 
                return new CacheLockDriver(CacheDriverFactory::create('memcached'));
        }
index 765055add0ad7fe5783e7eee7edf96358ab59f52..0c9deea16e3ba9124d43e526f4fa0d7f8e53a3fd 100644 (file)
@@ -8,15 +8,20 @@ use Friendica\Core\Lock\CacheLockDriver;
 
 /**
  * @requires extension redis
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
  */
 class RedisCacheLockDriverTest extends LockTest
 {
        protected function getInstance()
        {
-               $this->mockConfigGet('system', 'redis_host', 'localhost', 1);
-               $this->mockConfigGet('system', 'redis_port', null, 1);
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('system', 'redis_host', NULL)
+                       ->andReturn('localhost');
+
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('system', 'redis_port', NULL)
+                       ->andReturn(null);
 
                return new CacheLockDriver(CacheDriverFactory::create('redis'));
        }
index 58daa3516cba633f45ffa9edaaf9accf709a672b..c2b94145725187d7e951d644903b15e4cdf06f3f 100644 (file)
@@ -4,10 +4,6 @@ namespace Friendica\Test\src\Core\Lock;
 
 use Friendica\Core\Lock\SemaphoreLockDriver;
 
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- */
 class SemaphoreLockDriverTest extends LockTest
 {
        public function setUp()
@@ -15,7 +11,11 @@ class SemaphoreLockDriverTest extends LockTest
                parent::setUp();
 
                $this->app->shouldReceive('getHostname')->andReturn('friendica.local');
-               $this->mockConfigGet('system', 'temppath', '/tmp/');
+
+               $this->configCache
+                       ->shouldReceive('get')
+                       ->with('system', 'temppath', NULL)
+                       ->andReturn('/tmp/');
        }
 
        protected function getInstance()
index 53c4e8895b2dac1afe52cea59b6d5ffa29af7f49..bc50a0a691aa43cb4cf2121196767be1aa403f60 100644 (file)
@@ -21,13 +21,6 @@ class DBStructureTest extends DatabaseTest
                $this->logOutput = FActory\LoggerFactory::enableTest($this->app->getLogger());
 
                parent::setUp();
-
-               // Default config
-               Config::set('config', 'hostname', 'localhost');
-               Config::set('system', 'throttle_limit_day', 100);
-               Config::set('system', 'throttle_limit_week', 100);
-               Config::set('system', 'throttle_limit_month', 100);
-               Config::set('system', 'theme', 'system_theme');
        }
 
        /**