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

@ -90,7 +90,7 @@ class ModeTest extends MockedTest
$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)
@ -118,7 +118,7 @@ class ModeTest extends MockedTest
$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)

View file

@ -31,8 +31,7 @@ class BaseObjectTest extends TestCase
{
$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());

View file

@ -67,8 +67,7 @@ abstract class CacheTest extends MockedTest
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');

View file

@ -12,14 +12,14 @@ class MemcacheCacheDriverTest extends MemoryCacheTest
{
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');

View file

@ -12,9 +12,9 @@ class MemcachedCacheDriverTest extends MemoryCacheTest
{
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');

View file

@ -12,14 +12,14 @@ class RedisCacheDriverTest extends MemoryCacheTest
{
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');

View file

@ -2,6 +2,7 @@
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;
@ -29,7 +30,7 @@ class ConfigurationTest extends MockedTest
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);
@ -43,7 +44,7 @@ class ConfigurationTest extends MockedTest
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();
@ -64,7 +65,7 @@ class ConfigurationTest extends MockedTest
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();
@ -93,7 +94,7 @@ class ConfigurationTest extends MockedTest
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);
@ -111,7 +112,7 @@ class ConfigurationTest extends MockedTest
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();
@ -132,7 +133,7 @@ class ConfigurationTest extends MockedTest
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);
@ -157,7 +158,7 @@ class ConfigurationTest extends MockedTest
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();
@ -188,7 +189,7 @@ class ConfigurationTest extends MockedTest
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();
@ -223,7 +224,7 @@ class ConfigurationTest extends MockedTest
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);
@ -244,7 +245,7 @@ class ConfigurationTest extends MockedTest
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();

View file

@ -2,6 +2,7 @@
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;
@ -29,7 +30,7 @@ class PConfigurationTest extends 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')
@ -51,7 +52,7 @@ class PConfigurationTest extends MockedTest
{
$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();
@ -77,7 +78,7 @@ class PConfigurationTest extends MockedTest
{
$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);
@ -95,7 +96,7 @@ class PConfigurationTest extends MockedTest
{
$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();
@ -114,7 +115,7 @@ class PConfigurationTest extends MockedTest
{
$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);
@ -137,7 +138,7 @@ class PConfigurationTest extends MockedTest
{
$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();
@ -168,7 +169,7 @@ class PConfigurationTest extends MockedTest
{
$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();
@ -199,7 +200,7 @@ class PConfigurationTest extends MockedTest
{
$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);
@ -218,7 +219,7 @@ class PConfigurationTest extends MockedTest
{
$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();

View file

@ -52,9 +52,9 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
$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();

View file

@ -32,14 +32,14 @@ class ConfigConsoleTest extends ConsoleTest
}
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();
@ -50,9 +50,9 @@ class ConfigConsoleTest extends ConsoleTest
$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();
@ -62,9 +62,9 @@ class ConfigConsoleTest extends ConsoleTest
$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();
@ -77,9 +77,9 @@ class ConfigConsoleTest extends ConsoleTest
function testSetArrayValue() {
$testArray = [1, 2, 3];
$this->configCache
$this->configMock
->shouldReceive('get')
->with('config', 'test', null, false)
->with('config', 'test')
->andReturn($testArray)
->once();
@ -105,9 +105,9 @@ class ConfigConsoleTest extends ConsoleTest
}
function testVerbose() {
$this->configCache
$this->configMock
->shouldReceive('get')
->with('test', 'it', null, false)
->with('test', 'it')
->andReturn('now')
->once();
$console = new Config($this->consoleArgv);
@ -133,14 +133,14 @@ CONF;
}
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();

View file

@ -3,12 +3,10 @@
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
{
@ -31,10 +29,7 @@ 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);
}
/**

View file

@ -27,8 +27,7 @@ abstract class LockTest extends MockedTest
{
// 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');

View file

@ -13,14 +13,14 @@ class MemcacheCacheLockDriverTest extends LockTest
{
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'));

View file

@ -13,9 +13,9 @@ class MemcachedCacheLockDriverTest extends LockTest
{
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'));

View file

@ -13,14 +13,14 @@ class RedisCacheLockDriverTest extends LockTest
{
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'));

View file

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