Fixing tests

This commit is contained in:
Philipp Holzer 2019-02-17 21:41:45 +01:00
parent 5e5c39b0e1
commit f5adbd268b
No known key found for this signature in database
GPG Key ID: 517BE60E2CE5C8A5
18 changed files with 101 additions and 93 deletions

View File

@ -6,6 +6,7 @@ use Friendica\App;
use Friendica\BaseObject; use Friendica\BaseObject;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Render\FriendicaSmartyEngine; use Friendica\Render\FriendicaSmartyEngine;
use Friendica\Util\Profiler;
use Mockery\MockInterface; use Mockery\MockInterface;
use org\bovigo\vfs\vfsStreamDirectory; use org\bovigo\vfs\vfsStreamDirectory;
@ -22,70 +23,81 @@ trait AppMockTrait
/** /**
* @var MockInterface|Config\Configuration The mocked Config Cache * @var MockInterface|Config\Configuration The mocked Config Cache
*/ */
protected $configCache; protected $configMock;
/**
* @var MockInterface|Profiler The mocked profiler
*/
protected $profilerMock;
/** /**
* Mock the App * Mock the App
* *
* @param vfsStreamDirectory $root The root directory * @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 // Mocking App and most used functions
$this->app = \Mockery::mock(App::class); $this->app = \Mockery::mock(App::class);
$this->app $this->app
->shouldReceive('getBasePath') ->shouldReceive('getBasePath')
->andReturn($root->url()); ->andReturn($root->url());
$config $this->configMock
->shouldReceive('has')
->andReturn(true);
$this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('database', 'hostname') ->with('database', 'hostname')
->andReturn(getenv('MYSQL_HOST')); ->andReturn(getenv('MYSQL_HOST'));
$config $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('database', 'username') ->with('database', 'username')
->andReturn(getenv('MYSQL_USERNAME')); ->andReturn(getenv('MYSQL_USERNAME'));
$config $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('database', 'password') ->with('database', 'password')
->andReturn(getenv('MYSQL_PASSWORD')); ->andReturn(getenv('MYSQL_PASSWORD'));
$config $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('database', 'database') ->with('database', 'database')
->andReturn(getenv('MYSQL_DATABASE')); ->andReturn(getenv('MYSQL_DATABASE'));
$config $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('config', 'hostname') ->with('config', 'hostname')
->andReturn('localhost'); ->andReturn('localhost');
$config $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'theme', NULL, false) ->with('system', 'theme')
->andReturn('system_theme'); ->andReturn('system_theme');
$config
->shouldReceive('getConfig') $this->profilerMock = \Mockery::mock(Profiler::class);
->andReturn($config); $this->profilerMock->shouldReceive('saveTimestamp');
$this->app $this->app
->shouldReceive('getConfigCache') ->shouldReceive('getConfigCache')
->andReturn($config); ->andReturn($this->configMock);
$this->app $this->app
->shouldReceive('getTemplateEngine') ->shouldReceive('getTemplateEngine')
->andReturn(new FriendicaSmartyEngine()); ->andReturn(new FriendicaSmartyEngine());
$this->app $this->app
->shouldReceive('getCurrentTheme') ->shouldReceive('getCurrentTheme')
->andReturn('Smarty3'); ->andReturn('Smarty3');
$this->app
->shouldReceive('saveTimestamp')
->andReturn(true);
$this->app $this->app
->shouldReceive('getBaseUrl') ->shouldReceive('getBaseUrl')
->andReturn('http://friendica.local'); ->andReturn('http://friendica.local');
$this->app
// Initialize empty Config ->shouldReceive('getProfiler')
Config::init($config); ->andReturn($this->profilerMock);
BaseObject::setApp($this->app); BaseObject::setApp($this->app);
} }

View File

@ -2,6 +2,7 @@
namespace Friendica\Test\Util; namespace Friendica\Test\Util;
use Friendica\Database\DBStructure;
use Mockery\MockInterface; use Mockery\MockInterface;
/** /**
@ -16,6 +17,7 @@ trait DBStructureMockTrait
/** /**
* Mocking DBStructure::update() * Mocking DBStructure::update()
* @see DBStructure::update();
* *
* @param array $args The arguments for the update call * @param array $args The arguments for the update call
* @param bool $return True, if the connect was successful, otherwise false * @param bool $return True, if the connect was successful, otherwise false

View File

@ -90,7 +90,7 @@ class ModeTest extends MockedTest
$this->mockConnected(true, 1); $this->mockConnected(true, 1);
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1); $this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
$config = \Mockery::mock('Friendica\Core\Config\Configuration'); $config = \Mockery::mock(Config\Configuration::class);
$config $config
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'maintenance', null, false) ->with('system', 'maintenance', null, false)
@ -118,7 +118,7 @@ class ModeTest extends MockedTest
$this->mockConnected(true, 1); $this->mockConnected(true, 1);
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1); $this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
$config = \Mockery::mock('Friendica\Core\Config\Configuration'); $config = \Mockery::mock(Config\Configuration::class);
$config $config
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'maintenance', null, false) ->with('system', 'maintenance', null, false)

View File

@ -31,8 +31,7 @@ class BaseObjectTest extends TestCase
{ {
$baseObject = new BaseObject(); $baseObject = new BaseObject();
$this->setUpVfsDir(); $this->setUpVfsDir();
$configMock = \Mockery::mock('Friendica\Core\Config\Configuration'); $this->mockApp($this->root);
$this->mockApp($this->root, $configMock);
$this->assertNull($baseObject->setApp($this->app)); $this->assertNull($baseObject->setApp($this->app));
$this->assertEquals($this->app, $baseObject->getApp()); $this->assertEquals($this->app, $baseObject->getApp());

View File

@ -67,8 +67,7 @@ abstract class CacheTest extends MockedTest
protected function setUp() protected function setUp()
{ {
$this->setUpVfsDir(); $this->setUpVfsDir();
$configMock = \Mockery::mock('Friendica\Core\Config\Configuration'); $this->mockApp($this->root);
$this->mockApp($this->root, $configMock);
$this->app $this->app
->shouldReceive('getHostname') ->shouldReceive('getHostname')
->andReturn('friendica.local'); ->andReturn('friendica.local');

View File

@ -12,14 +12,14 @@ class MemcacheCacheDriverTest extends MemoryCacheTest
{ {
protected function getInstance() protected function getInstance()
{ {
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'memcache_host', NULL, false) ->with('system', 'memcache_host')
->andReturn('localhost'); ->andReturn('localhost');
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'memcache_port', NULL, false) ->with('system', 'memcache_port')
->andReturn(11211); ->andReturn(11211);
$this->cache = CacheDriverFactory::create('memcache'); $this->cache = CacheDriverFactory::create('memcache');

View File

@ -12,9 +12,9 @@ class MemcachedCacheDriverTest extends MemoryCacheTest
{ {
protected function getInstance() protected function getInstance()
{ {
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'memcached_hosts', NULL, false) ->with('system', 'memcached_hosts')
->andReturn([0 => 'localhost, 11211']); ->andReturn([0 => 'localhost, 11211']);
$this->cache = CacheDriverFactory::create('memcached'); $this->cache = CacheDriverFactory::create('memcached');

View File

@ -12,14 +12,14 @@ class RedisCacheDriverTest extends MemoryCacheTest
{ {
protected function getInstance() protected function getInstance()
{ {
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'redis_host', NULL, false) ->with('system', 'redis_host')
->andReturn('localhost'); ->andReturn('localhost');
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'redis_port', NULL, false) ->with('system', 'redis_port')
->andReturn(null); ->andReturn(null);
$this->cache = CacheDriverFactory::create('redis'); $this->cache = CacheDriverFactory::create('redis');

View File

@ -2,6 +2,7 @@
namespace Friendica\Test\Core\Config; namespace Friendica\Test\Core\Config;
use Friendica\Core\Config\Adapter\IConfigAdapter;
use Friendica\Core\Config\Cache\ConfigCache; use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Config\Cache\IConfigCache; use Friendica\Core\Config\Cache\IConfigCache;
use Friendica\Core\Config\Configuration; use Friendica\Core\Config\Configuration;
@ -29,7 +30,7 @@ class ConfigurationTest extends MockedTest
public function testSetUp() public function testSetUp()
{ {
$configCache = new ConfigCache(); $configCache = new ConfigCache();
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter'); $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->once(); $configAdapter->shouldReceive('isConnected')->andReturn(false)->once();
$configuration = new Configuration($configCache, $configAdapter); $configuration = new Configuration($configCache, $configAdapter);
@ -43,7 +44,7 @@ class ConfigurationTest extends MockedTest
public function testCacheLoad() public function testCacheLoad()
{ {
$configCache = new ConfigCache(); $configCache = new ConfigCache();
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter'); $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3); $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
// constructor loading // constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->once(); $configAdapter->shouldReceive('load')->andReturn([])->once();
@ -64,7 +65,7 @@ class ConfigurationTest extends MockedTest
public function testCacheLoadDouble() public function testCacheLoadDouble()
{ {
$configCache = new ConfigCache(); $configCache = new ConfigCache();
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter'); $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(5); $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(5);
// constructor loading // constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->once(); $configAdapter->shouldReceive('load')->andReturn([])->once();
@ -93,7 +94,7 @@ class ConfigurationTest extends MockedTest
public function testSetGetWithoutDB($data) public function testSetGetWithoutDB($data)
{ {
$configCache = new ConfigCache(); $configCache = new ConfigCache();
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter'); $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3); $configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
$configuration = new Configuration($configCache, $configAdapter); $configuration = new Configuration($configCache, $configAdapter);
@ -111,7 +112,7 @@ class ConfigurationTest extends MockedTest
public function testSetGetWithDB($data) public function testSetGetWithDB($data)
{ {
$configCache = new ConfigCache(); $configCache = new ConfigCache();
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter'); $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3); $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
// constructor loading // constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->once(); $configAdapter->shouldReceive('load')->andReturn([])->once();
@ -132,7 +133,7 @@ class ConfigurationTest extends MockedTest
public function testGetWrongWithoutDB() public function testGetWrongWithoutDB()
{ {
$configCache = new ConfigCache(); $configCache = new ConfigCache();
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter'); $configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4); $configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4);
$configuration = new Configuration($configCache, $configAdapter); $configuration = new Configuration($configCache, $configAdapter);
@ -157,7 +158,7 @@ class ConfigurationTest extends MockedTest
public function testGetWithRefresh($data) public function testGetWithRefresh($data)
{ {
$configCache = new ConfigCache(['test' => ['it' => 'now']]); $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); $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
// constructor loading // constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->once(); $configAdapter->shouldReceive('load')->andReturn([])->once();
@ -188,7 +189,7 @@ class ConfigurationTest extends MockedTest
public function testGetWithoutLoaded($data) public function testGetWithoutLoaded($data)
{ {
$configCache = new ConfigCache(['test' => ['it' => 'now']]); $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); $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
// constructor loading // constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->once(); $configAdapter->shouldReceive('load')->andReturn([])->once();
@ -223,7 +224,7 @@ class ConfigurationTest extends MockedTest
public function testDeleteWithoutDB($data) public function testDeleteWithoutDB($data)
{ {
$configCache = new ConfigCache(['test' => ['it' => $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); $configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4);
$configuration = new Configuration($configCache, $configAdapter); $configuration = new Configuration($configCache, $configAdapter);
@ -244,7 +245,7 @@ class ConfigurationTest extends MockedTest
public function testDeleteWithDB() public function testDeleteWithDB()
{ {
$configCache = new ConfigCache(['test' => ['it' => 'now', 'quarter' => 'true']]); $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); $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(6);
// constructor loading // constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->once(); $configAdapter->shouldReceive('load')->andReturn([])->once();

View File

@ -2,6 +2,7 @@
namespace Friendica\Test\Core\Config; namespace Friendica\Test\Core\Config;
use Friendica\Core\Config\Adapter\IPConfigAdapter;
use Friendica\Core\Config\Cache\ConfigCache; use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Config\PConfiguration; use Friendica\Core\Config\PConfiguration;
use Friendica\Test\MockedTest; use Friendica\Test\MockedTest;
@ -29,7 +30,7 @@ class PConfigurationTest extends MockedTest
{ {
$uid = 234; $uid = 234;
$configCache = new ConfigCache(); $configCache = new ConfigCache();
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter'); $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->twice(); $configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
// expected loading // expected loading
$configAdapter->shouldReceive('load') $configAdapter->shouldReceive('load')
@ -51,7 +52,7 @@ class PConfigurationTest extends MockedTest
{ {
$uid = 234; $uid = 234;
$configCache = new ConfigCache(); $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('isConnected')->andReturn(true)->times(4);
// expected loading // expected loading
$configAdapter->shouldReceive('load')->with($uid, 'testing')->andReturn(['testing' => ['test' => 'it']])->once(); $configAdapter->shouldReceive('load')->with($uid, 'testing')->andReturn(['testing' => ['test' => 'it']])->once();
@ -77,7 +78,7 @@ class PConfigurationTest extends MockedTest
{ {
$uid = 234; $uid = 234;
$configCache = new ConfigCache(); $configCache = new ConfigCache();
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter'); $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(2); $configAdapter->shouldReceive('isConnected')->andReturn(false)->times(2);
$configuration = new PConfiguration($configCache, $configAdapter); $configuration = new PConfiguration($configCache, $configAdapter);
@ -95,7 +96,7 @@ class PConfigurationTest extends MockedTest
{ {
$uid = 234; $uid = 234;
$configCache = new ConfigCache(); $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('isConnected')->andReturn(true)->times(2);
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(true)->once(); $configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(true)->once();
$configAdapter->shouldReceive('set')->with($uid, 'test', 'it', $data)->andReturn(true)->once(); $configAdapter->shouldReceive('set')->with($uid, 'test', 'it', $data)->andReturn(true)->once();
@ -114,7 +115,7 @@ class PConfigurationTest extends MockedTest
{ {
$uid = 234; $uid = 234;
$configCache = new ConfigCache(); $configCache = new ConfigCache();
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter'); $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3); $configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
$configuration = new PConfiguration($configCache, $configAdapter); $configuration = new PConfiguration($configCache, $configAdapter);
@ -137,7 +138,7 @@ class PConfigurationTest extends MockedTest
{ {
$uid = 234; $uid = 234;
$configCache = new ConfigCache(); $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('isConnected')->andReturn(true)->times(4);
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(false)->once(); $configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(false)->once();
$configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn('now')->once(); $configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn('now')->once();
@ -168,7 +169,7 @@ class PConfigurationTest extends MockedTest
{ {
$uid = 234; $uid = 234;
$configCache = new ConfigCache(); $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('isConnected')->andReturn(true)->times(3);
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(false)->once(); $configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(false)->once();
@ -199,7 +200,7 @@ class PConfigurationTest extends MockedTest
{ {
$uid = 234; $uid = 234;
$configCache = new ConfigCache(); $configCache = new ConfigCache();
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter'); $configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4); $configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4);
$configuration = new PConfiguration($configCache, $configAdapter); $configuration = new PConfiguration($configCache, $configAdapter);
@ -218,7 +219,7 @@ class PConfigurationTest extends MockedTest
{ {
$uid = 234; $uid = 234;
$configCache = new ConfigCache(); $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('isConnected')->andReturn(true)->times(6);
$configAdapter->shouldReceive('set')->with($uid, 'test', 'it', 'now')->andReturn(false)->once(); $configAdapter->shouldReceive('set')->with($uid, 'test', 'it', 'now')->andReturn(false)->once();
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(true)->once(); $configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(true)->once();

View File

@ -52,9 +52,9 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
$this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER'); $this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER');
$this->db_pass = getenv('MYSQL_PASSWORD'); $this->db_pass = getenv('MYSQL_PASSWORD');
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('config', 'php_path', NULL, false) ->with('config', 'php_path')
->andReturn(false); ->andReturn(false);
$this->mockL10nT(); $this->mockL10nT();

View File

@ -32,14 +32,14 @@ class ConfigConsoleTest extends ConsoleTest
} }
function testSetGetKeyValue() { function testSetGetKeyValue() {
$this->configCache $this->configMock
->shouldReceive('set') ->shouldReceive('set')
->with('config', 'test', 'now') ->with('config', 'test', 'now')
->andReturn(true) ->andReturn(true)
->once(); ->once();
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('config', 'test', NULL, false) ->with('config', 'test')
->andReturn('now') ->andReturn('now')
->twice(); ->twice();
@ -50,9 +50,9 @@ class ConfigConsoleTest extends ConsoleTest
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
$this->assertEquals("config.test <= now\n", $txt); $this->assertEquals("config.test <= now\n", $txt);
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('config', 'test', null, false) ->with('config', 'test')
->andReturn('now') ->andReturn('now')
->once(); ->once();
@ -62,9 +62,9 @@ class ConfigConsoleTest extends ConsoleTest
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
$this->assertEquals("config.test => now\n", $txt); $this->assertEquals("config.test => now\n", $txt);
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('config', 'test', null, false) ->with('config', 'test')
->andReturn(null) ->andReturn(null)
->once(); ->once();
@ -77,9 +77,9 @@ class ConfigConsoleTest extends ConsoleTest
function testSetArrayValue() { function testSetArrayValue() {
$testArray = [1, 2, 3]; $testArray = [1, 2, 3];
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('config', 'test', null, false) ->with('config', 'test')
->andReturn($testArray) ->andReturn($testArray)
->once(); ->once();
@ -105,9 +105,9 @@ class ConfigConsoleTest extends ConsoleTest
} }
function testVerbose() { function testVerbose() {
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('test', 'it', null, false) ->with('test', 'it')
->andReturn('now') ->andReturn('now')
->once(); ->once();
$console = new Config($this->consoleArgv); $console = new Config($this->consoleArgv);
@ -133,14 +133,14 @@ CONF;
} }
function testUnableToSet() { function testUnableToSet() {
$this->configCache $this->configMock
->shouldReceive('set') ->shouldReceive('set')
->with('test', 'it', 'now') ->with('test', 'it', 'now')
->andReturn(false) ->andReturn(false)
->once(); ->once();
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('test', 'it', NULL, false) ->with('test', 'it')
->andReturn(NULL) ->andReturn(NULL)
->once(); ->once();
$console = new Config(); $console = new Config();

View File

@ -3,12 +3,10 @@
namespace Friendica\Test\src\Core\Console; namespace Friendica\Test\src\Core\Console;
use Asika\SimpleConsole\Console; use Asika\SimpleConsole\Console;
use Friendica\Core\Config\Configuration;
use Friendica\Test\MockedTest; use Friendica\Test\MockedTest;
use Friendica\Test\Util\AppMockTrait; use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\Intercept; use Friendica\Test\Util\Intercept;
use Friendica\Test\Util\VFSTrait; use Friendica\Test\Util\VFSTrait;
use Friendica\Util\Profiler;
abstract class ConsoleTest extends MockedTest abstract class ConsoleTest extends MockedTest
{ {
@ -31,10 +29,7 @@ abstract class ConsoleTest extends MockedTest
Intercept::setUp(); Intercept::setUp();
$this->setUpVfsDir(); $this->setUpVfsDir();
$configMock = \Mockery::mock(Configuration::class); $this->mockApp($this->root);
$this->mockApp($this->root, $configMock);
$profileMock = \Mockery::mock(Profiler::class);
$this->app->shouldReceive('getProfiler')->andReturn($profileMock);
} }
/** /**

View File

@ -27,8 +27,7 @@ abstract class LockTest extends MockedTest
{ {
// Reusable App object // Reusable App object
$this->setUpVfsDir(); $this->setUpVfsDir();
$configMock = \Mockery::mock('Friendica\Core\Config\Configuration'); $this->mockApp($this->root);
$this->mockApp($this->root, $configMock);
$this->app $this->app
->shouldReceive('getHostname') ->shouldReceive('getHostname')
->andReturn('friendica.local'); ->andReturn('friendica.local');

View File

@ -13,14 +13,14 @@ class MemcacheCacheLockDriverTest extends LockTest
{ {
protected function getInstance() protected function getInstance()
{ {
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'memcache_host', NULL, false) ->with('system', 'memcache_host')
->andReturn('localhost'); ->andReturn('localhost');
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'memcache_port', NULL, false) ->with('system', 'memcache_port')
->andReturn(11211); ->andReturn(11211);
return new CacheLockDriver(CacheDriverFactory::create('memcache')); return new CacheLockDriver(CacheDriverFactory::create('memcache'));

View File

@ -13,9 +13,9 @@ class MemcachedCacheLockDriverTest extends LockTest
{ {
protected function getInstance() protected function getInstance()
{ {
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'memcached_hosts', NULL, false) ->with('system', 'memcached_hosts')
->andReturn([0 => 'localhost, 11211']); ->andReturn([0 => 'localhost, 11211']);
return new CacheLockDriver(CacheDriverFactory::create('memcached')); return new CacheLockDriver(CacheDriverFactory::create('memcached'));

View File

@ -13,14 +13,14 @@ class RedisCacheLockDriverTest extends LockTest
{ {
protected function getInstance() protected function getInstance()
{ {
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'redis_host', NULL, false) ->with('system', 'redis_host')
->andReturn('localhost'); ->andReturn('localhost');
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'redis_port', NULL, false) ->with('system', 'redis_port')
->andReturn(null); ->andReturn(null);
return new CacheLockDriver(CacheDriverFactory::create('redis')); return new CacheLockDriver(CacheDriverFactory::create('redis'));

View File

@ -12,9 +12,9 @@ class SemaphoreLockDriverTest extends LockTest
$this->app->shouldReceive('getHostname')->andReturn('friendica.local'); $this->app->shouldReceive('getHostname')->andReturn('friendica.local');
$this->configCache $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'temppath', NULL, false) ->with('system', 'temppath')
->andReturn('/tmp/'); ->andReturn('/tmp/');
} }