use Friendica\BaseObject;
use Friendica\Core\Config;
use Friendica\Render\FriendicaSmartyEngine;
+use Friendica\Util\Profiler;
use Mockery\MockInterface;
use org\bovigo\vfs\vfsStreamDirectory;
/**
* @var MockInterface|Config\Configuration The mocked Config Cache
*/
- protected $configCache;
+ protected $configMock;
+
+ /**
+ * @var MockInterface|Profiler The mocked profiler
+ */
+ protected $profilerMock;
/**
* Mock the App
*
* @param vfsStreamDirectory $root The root directory
- * @param MockInterface|Config\Configuration $config The config cache
*/
- public function mockApp($root, Config\Configuration $config)
+ public function mockApp($root)
{
- $this->configCache = $config;
+ $this->configMock = \Mockery::mock(Config\Cache\IConfigCache::class);
+ $configAdapterMock = \Mockery::mock(Config\Adapter\IConfigAdapter::class);
+ // Disable the adapter
+ $configAdapterMock->shouldReceive('isConnected')->andReturn(false);
+
+ $config = new Config\Configuration($this->configMock, $configAdapterMock);
+ // Initialize empty Config
+ Config::init($config);
+
// Mocking App and most used functions
$this->app = \Mockery::mock(App::class);
$this->app
->shouldReceive('getBasePath')
->andReturn($root->url());
- $config
+ $this->configMock
+ ->shouldReceive('has')
+ ->andReturn(true);
+ $this->configMock
->shouldReceive('get')
->with('database', 'hostname')
->andReturn(getenv('MYSQL_HOST'));
- $config
+ $this->configMock
->shouldReceive('get')
->with('database', 'username')
->andReturn(getenv('MYSQL_USERNAME'));
- $config
+ $this->configMock
->shouldReceive('get')
->with('database', 'password')
->andReturn(getenv('MYSQL_PASSWORD'));
- $config
+ $this->configMock
->shouldReceive('get')
->with('database', 'database')
->andReturn(getenv('MYSQL_DATABASE'));
- $config
+ $this->configMock
->shouldReceive('get')
->with('config', 'hostname')
->andReturn('localhost');
- $config
+ $this->configMock
->shouldReceive('get')
- ->with('system', 'theme', NULL, false)
+ ->with('system', 'theme')
->andReturn('system_theme');
- $config
- ->shouldReceive('getConfig')
- ->andReturn($config);
+
+ $this->profilerMock = \Mockery::mock(Profiler::class);
+ $this->profilerMock->shouldReceive('saveTimestamp');
$this->app
->shouldReceive('getConfigCache')
- ->andReturn($config);
-
+ ->andReturn($this->configMock);
$this->app
->shouldReceive('getTemplateEngine')
->andReturn(new FriendicaSmartyEngine());
$this->app
->shouldReceive('getCurrentTheme')
->andReturn('Smarty3');
- $this->app
- ->shouldReceive('saveTimestamp')
- ->andReturn(true);
$this->app
->shouldReceive('getBaseUrl')
->andReturn('http://friendica.local');
-
- // Initialize empty Config
- Config::init($config);
+ $this->app
+ ->shouldReceive('getProfiler')
+ ->andReturn($this->profilerMock);
BaseObject::setApp($this->app);
}
namespace Friendica\Test\Util;
+use Friendica\Database\DBStructure;
use Mockery\MockInterface;
/**
/**
* Mocking DBStructure::update()
+ * @see DBStructure::update();
*
* @param array $args The arguments for the update call
* @param bool $return True, if the connect was successful, otherwise false
$this->mockConnected(true, 1);
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
- $config = \Mockery::mock('Friendica\Core\Config\Configuration');
+ $config = \Mockery::mock(Config\Configuration::class);
$config
->shouldReceive('get')
->with('system', 'maintenance', null, false)
$this->mockConnected(true, 1);
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
- $config = \Mockery::mock('Friendica\Core\Config\Configuration');
+ $config = \Mockery::mock(Config\Configuration::class);
$config
->shouldReceive('get')
->with('system', 'maintenance', null, false)
{
$baseObject = new BaseObject();
$this->setUpVfsDir();
- $configMock = \Mockery::mock('Friendica\Core\Config\Configuration');
- $this->mockApp($this->root, $configMock);
+ $this->mockApp($this->root);
$this->assertNull($baseObject->setApp($this->app));
$this->assertEquals($this->app, $baseObject->getApp());
protected function setUp()
{
$this->setUpVfsDir();
- $configMock = \Mockery::mock('Friendica\Core\Config\Configuration');
- $this->mockApp($this->root, $configMock);
+ $this->mockApp($this->root);
$this->app
->shouldReceive('getHostname')
->andReturn('friendica.local');
{
protected function getInstance()
{
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('system', 'memcache_host', NULL, false)
+ ->with('system', 'memcache_host')
->andReturn('localhost');
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('system', 'memcache_port', NULL, false)
+ ->with('system', 'memcache_port')
->andReturn(11211);
$this->cache = CacheDriverFactory::create('memcache');
{
protected function getInstance()
{
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('system', 'memcached_hosts', NULL, false)
+ ->with('system', 'memcached_hosts')
->andReturn([0 => 'localhost, 11211']);
$this->cache = CacheDriverFactory::create('memcached');
{
protected function getInstance()
{
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('system', 'redis_host', NULL, false)
+ ->with('system', 'redis_host')
->andReturn('localhost');
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('system', 'redis_port', NULL, false)
+ ->with('system', 'redis_port')
->andReturn(null);
$this->cache = CacheDriverFactory::create('redis');
namespace Friendica\Test\Core\Config;
+use Friendica\Core\Config\Adapter\IConfigAdapter;
use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Config\Cache\IConfigCache;
use Friendica\Core\Config\Configuration;
public function testSetUp()
{
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
+ $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->once();
$configuration = new Configuration($configCache, $configAdapter);
public function testCacheLoad()
{
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
+ $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
// constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->once();
public function testCacheLoadDouble()
{
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
+ $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(5);
// constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->once();
public function testSetGetWithoutDB($data)
{
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
+ $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
$configuration = new Configuration($configCache, $configAdapter);
public function testSetGetWithDB($data)
{
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
+ $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
// constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->once();
public function testGetWrongWithoutDB()
{
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
+ $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4);
$configuration = new Configuration($configCache, $configAdapter);
public function testGetWithRefresh($data)
{
$configCache = new ConfigCache(['test' => ['it' => 'now']]);
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
+ $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
// constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->once();
public function testGetWithoutLoaded($data)
{
$configCache = new ConfigCache(['test' => ['it' => 'now']]);
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
+ $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
// constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->once();
public function testDeleteWithoutDB($data)
{
$configCache = new ConfigCache(['test' => ['it' => $data]]);
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
+ $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4);
$configuration = new Configuration($configCache, $configAdapter);
public function testDeleteWithDB()
{
$configCache = new ConfigCache(['test' => ['it' => 'now', 'quarter' => 'true']]);
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
+ $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(6);
// constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->once();
namespace Friendica\Test\Core\Config;
+use Friendica\Core\Config\Adapter\IPConfigAdapter;
use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Config\PConfiguration;
use Friendica\Test\MockedTest;
{
$uid = 234;
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
+ $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
// expected loading
$configAdapter->shouldReceive('load')
{
$uid = 234;
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
+ $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
// expected loading
$configAdapter->shouldReceive('load')->with($uid, 'testing')->andReturn(['testing' => ['test' => 'it']])->once();
{
$uid = 234;
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
+ $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(2);
$configuration = new PConfiguration($configCache, $configAdapter);
{
$uid = 234;
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
+ $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(2);
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(true)->once();
$configAdapter->shouldReceive('set')->with($uid, 'test', 'it', $data)->andReturn(true)->once();
{
$uid = 234;
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
+ $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
$configuration = new PConfiguration($configCache, $configAdapter);
{
$uid = 234;
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
+ $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(false)->once();
$configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn('now')->once();
{
$uid = 234;
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
+ $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(false)->once();
{
$uid = 234;
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
+ $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4);
$configuration = new PConfiguration($configCache, $configAdapter);
{
$uid = 234;
$configCache = new ConfigCache();
- $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
+ $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(6);
$configAdapter->shouldReceive('set')->with($uid, 'test', 'it', 'now')->andReturn(false)->once();
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(true)->once();
$this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER');
$this->db_pass = getenv('MYSQL_PASSWORD');
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('config', 'php_path', NULL, false)
+ ->with('config', 'php_path')
->andReturn(false);
$this->mockL10nT();
}
function testSetGetKeyValue() {
- $this->configCache
+ $this->configMock
->shouldReceive('set')
->with('config', 'test', 'now')
->andReturn(true)
->once();
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('config', 'test', NULL, false)
+ ->with('config', 'test')
->andReturn('now')
->twice();
$txt = $this->dumpExecute($console);
$this->assertEquals("config.test <= now\n", $txt);
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('config', 'test', null, false)
+ ->with('config', 'test')
->andReturn('now')
->once();
$txt = $this->dumpExecute($console);
$this->assertEquals("config.test => now\n", $txt);
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('config', 'test', null, false)
+ ->with('config', 'test')
->andReturn(null)
->once();
function testSetArrayValue() {
$testArray = [1, 2, 3];
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('config', 'test', null, false)
+ ->with('config', 'test')
->andReturn($testArray)
->once();
}
function testVerbose() {
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('test', 'it', null, false)
+ ->with('test', 'it')
->andReturn('now')
->once();
$console = new Config($this->consoleArgv);
}
function testUnableToSet() {
- $this->configCache
+ $this->configMock
->shouldReceive('set')
->with('test', 'it', 'now')
->andReturn(false)
->once();
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('test', 'it', NULL, false)
+ ->with('test', 'it')
->andReturn(NULL)
->once();
$console = new Config();
namespace Friendica\Test\src\Core\Console;
use Asika\SimpleConsole\Console;
-use Friendica\Core\Config\Configuration;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\Intercept;
use Friendica\Test\Util\VFSTrait;
-use Friendica\Util\Profiler;
abstract class ConsoleTest extends MockedTest
{
Intercept::setUp();
$this->setUpVfsDir();
- $configMock = \Mockery::mock(Configuration::class);
- $this->mockApp($this->root, $configMock);
- $profileMock = \Mockery::mock(Profiler::class);
- $this->app->shouldReceive('getProfiler')->andReturn($profileMock);
+ $this->mockApp($this->root);
}
/**
{
// Reusable App object
$this->setUpVfsDir();
- $configMock = \Mockery::mock('Friendica\Core\Config\Configuration');
- $this->mockApp($this->root, $configMock);
+ $this->mockApp($this->root);
$this->app
->shouldReceive('getHostname')
->andReturn('friendica.local');
{
protected function getInstance()
{
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('system', 'memcache_host', NULL, false)
+ ->with('system', 'memcache_host')
->andReturn('localhost');
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('system', 'memcache_port', NULL, false)
+ ->with('system', 'memcache_port')
->andReturn(11211);
return new CacheLockDriver(CacheDriverFactory::create('memcache'));
{
protected function getInstance()
{
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('system', 'memcached_hosts', NULL, false)
+ ->with('system', 'memcached_hosts')
->andReturn([0 => 'localhost, 11211']);
return new CacheLockDriver(CacheDriverFactory::create('memcached'));
{
protected function getInstance()
{
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('system', 'redis_host', NULL, false)
+ ->with('system', 'redis_host')
->andReturn('localhost');
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('system', 'redis_port', NULL, false)
+ ->with('system', 'redis_port')
->andReturn(null);
return new CacheLockDriver(CacheDriverFactory::create('redis'));
$this->app->shouldReceive('getHostname')->andReturn('friendica.local');
- $this->configCache
+ $this->configMock
->shouldReceive('get')
- ->with('system', 'temppath', NULL, false)
+ ->with('system', 'temppath')
->andReturn('/tmp/');
}