Use ArraySubsetAsserts

This commit is contained in:
Philipp 2021-12-10 21:34:19 +01:00
parent ab5184d27a
commit 31ca758d4e
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
3 changed files with 41 additions and 33 deletions

View file

@ -21,19 +21,22 @@
namespace Friendica\Test\src\Core\Config; namespace Friendica\Test\src\Core\Config;
use Friendica\Core\Config\Cache; use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Config\Repository\Config as ConfigModel; use Friendica\Core\Config\Repository\Config as ConfigModel;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Test\MockedTest; use Friendica\Test\MockedTest;
use Mockery\MockInterface; use Mockery\MockInterface;
use Mockery; use Mockery;
abstract class ConfigTest extends MockedTest abstract class ConfigTest extends MockedTest
{ {
use ArraySubsetAsserts;
/** @var ConfigModel|MockInterface */ /** @var ConfigModel|MockInterface */
protected $configModel; protected $configModel;
/** @var \Friendica\Core\Config\ValueObject\Cache */ /** @var Cache */
protected $configCache; protected $configCache;
/** @var IManageConfigValues */ /** @var IManageConfigValues */
@ -61,7 +64,7 @@ abstract class ConfigTest extends MockedTest
// Create the config model // Create the config model
$this->configModel = Mockery::mock(ConfigModel::class); $this->configModel = Mockery::mock(ConfigModel::class);
$this->configCache = new \Friendica\Core\Config\ValueObject\Cache(); $this->configCache = new Cache();
} }
/** /**
@ -161,7 +164,7 @@ abstract class ConfigTest extends MockedTest
->once(); ->once();
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
// assert config is loaded everytime // assert config is loaded everytime
self::assertConfig('config', $data['config']); self::assertConfig('config', $data['config']);
@ -176,7 +179,7 @@ abstract class ConfigTest extends MockedTest
public function testLoad(array $data, array $load) public function testLoad(array $data, array $load)
{ {
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
foreach ($load as $loadedCats) { foreach ($load as $loadedCats) {
$this->testedConfig->load($loadedCats); $this->testedConfig->load($loadedCats);
@ -257,7 +260,7 @@ abstract class ConfigTest extends MockedTest
public function testCacheLoadDouble(array $data1, array $data2, array $expect = []) public function testCacheLoadDouble(array $data1, array $data2, array $expect = [])
{ {
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
foreach ($data1 as $cat => $data) { foreach ($data1 as $cat => $data) {
$this->testedConfig->load($cat); $this->testedConfig->load($cat);
@ -282,7 +285,7 @@ abstract class ConfigTest extends MockedTest
$this->configModel->shouldReceive('load')->withAnyArgs()->andReturn([])->once(); $this->configModel->shouldReceive('load')->withAnyArgs()->andReturn([])->once();
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertEmpty($this->testedConfig->getCache()->getAll()); self::assertEmpty($this->testedConfig->getCache()->getAll());
} }
@ -299,7 +302,7 @@ abstract class ConfigTest extends MockedTest
->times(3); ->times(3);
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertTrue($this->testedConfig->set('test', 'it', $data)); self::assertTrue($this->testedConfig->set('test', 'it', $data));
@ -317,7 +320,7 @@ abstract class ConfigTest extends MockedTest
$this->configModel->shouldReceive('set')->with('test', 'it', $data)->andReturn(true)->once(); $this->configModel->shouldReceive('set')->with('test', 'it', $data)->andReturn(true)->once();
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertTrue($this->testedConfig->set('test', 'it', $data)); self::assertTrue($this->testedConfig->set('test', 'it', $data));
@ -331,7 +334,7 @@ abstract class ConfigTest extends MockedTest
public function testGetWrongWithoutDB() public function testGetWrongWithoutDB()
{ {
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
// without refresh // without refresh
self::assertNull($this->testedConfig->get('test', 'it')); self::assertNull($this->testedConfig->get('test', 'it'));
@ -353,10 +356,10 @@ abstract class ConfigTest extends MockedTest
*/ */
public function testGetWithRefresh($data) public function testGetWithRefresh($data)
{ {
$this->configCache->load(['test' => ['it' => 'now']], \Friendica\Core\Config\ValueObject\Cache::SOURCE_FILE); $this->configCache->load(['test' => ['it' => 'now']], Cache::SOURCE_FILE);
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
// without refresh // without refresh
self::assertEquals('now', $this->testedConfig->get('test', 'it')); self::assertEquals('now', $this->testedConfig->get('test', 'it'));
@ -378,10 +381,10 @@ abstract class ConfigTest extends MockedTest
*/ */
public function testDeleteWithoutDB($data) public function testDeleteWithoutDB($data)
{ {
$this->configCache->load(['test' => ['it' => $data]], \Friendica\Core\Config\ValueObject\Cache::SOURCE_FILE); $this->configCache->load(['test' => ['it' => $data]], Cache::SOURCE_FILE);
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertEquals($data, $this->testedConfig->get('test', 'it')); self::assertEquals($data, $this->testedConfig->get('test', 'it'));
self::assertEquals($data, $this->testedConfig->getCache()->get('test', 'it')); self::assertEquals($data, $this->testedConfig->getCache()->get('test', 'it'));
@ -398,7 +401,7 @@ abstract class ConfigTest extends MockedTest
*/ */
public function testDeleteWithDB() public function testDeleteWithDB()
{ {
$this->configCache->load(['test' => ['it' => 'now', 'quarter' => 'true']], \Friendica\Core\Config\ValueObject\Cache::SOURCE_FILE); $this->configCache->load(['test' => ['it' => 'now', 'quarter' => 'true']], Cache::SOURCE_FILE);
$this->configModel->shouldReceive('delete') $this->configModel->shouldReceive('delete')
->with('test', 'it') ->with('test', 'it')
@ -418,7 +421,7 @@ abstract class ConfigTest extends MockedTest
->once(); ->once();
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
// directly set the value to the cache // directly set the value to the cache
$this->testedConfig->getCache()->set('test', 'it', 'now'); $this->testedConfig->getCache()->set('test', 'it', 'now');
@ -444,9 +447,9 @@ abstract class ConfigTest extends MockedTest
public function testSetGetHighPrio() public function testSetGetHighPrio()
{ {
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
$this->testedConfig->getCache()->set('config', 'test', 'prio', \Friendica\Core\Config\ValueObject\Cache::SOURCE_FILE); $this->testedConfig->getCache()->set('config', 'test', 'prio', Cache::SOURCE_FILE);
self::assertEquals('prio', $this->testedConfig->get('config', 'test')); self::assertEquals('prio', $this->testedConfig->get('config', 'test'));
// now you have to get the new variable entry because of the new set the get refresh succeed as well // now you have to get the new variable entry because of the new set the get refresh succeed as well
@ -460,10 +463,10 @@ abstract class ConfigTest extends MockedTest
public function testSetGetLowPrio() public function testSetGetLowPrio()
{ {
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertEquals('it', $this->testedConfig->get('config', 'test')); self::assertEquals('it', $this->testedConfig->get('config', 'test'));
$this->testedConfig->getCache()->set('config', 'test', 'prio', \Friendica\Core\Config\ValueObject\Cache::SOURCE_ENV); $this->testedConfig->getCache()->set('config', 'test', 'prio', Cache::SOURCE_ENV);
// now you have to get the env variable entry as output, even with a new set (which failed) and a get refresh // now you have to get the env variable entry as output, even with a new set (which failed) and a get refresh
self::assertFalse($this->testedConfig->set('config', 'test', '123')); self::assertFalse($this->testedConfig->set('config', 'test', '123'));
self::assertEquals('prio', $this->testedConfig->get('config', 'test', '', true)); self::assertEquals('prio', $this->testedConfig->get('config', 'test', '', true));

View file

@ -23,6 +23,7 @@
namespace Friendica\Core; namespace Friendica\Core;
use Dice\Dice; use Dice\Dice;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Friendica\Core\Config\ValueObject\Cache; use Friendica\Core\Config\ValueObject\Cache;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses; use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
@ -35,6 +36,7 @@ use Mockery\MockInterface;
class InstallerTest extends MockedTest class InstallerTest extends MockedTest
{ {
use VFSTrait; use VFSTrait;
use ArraySubsetAsserts;
/** /**
* @var L10n|MockInterface * @var L10n|MockInterface

View file

@ -21,19 +21,22 @@
namespace Friendica\Test\src\Core\PConfig; namespace Friendica\Test\src\Core\PConfig;
use Friendica\Core\PConfig\Cache; use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Friendica\Core\PConfig\Type\AbstractPConfigValues; use Friendica\Core\PConfig\Type\AbstractPConfigValues;
use Friendica\Core\PConfig\Repository\PConfig as PConfigModel; use Friendica\Core\PConfig\Repository\PConfig as PConfigModel;
use Friendica\Core\PConfig\ValueObject\Cache;
use Friendica\Test\MockedTest; use Friendica\Test\MockedTest;
use Mockery; use Mockery;
use Mockery\MockInterface; use Mockery\MockInterface;
abstract class PConfigTest extends MockedTest abstract class PConfigTest extends MockedTest
{ {
use ArraySubsetAsserts;
/** @var PConfigModel|MockInterface */ /** @var PConfigModel|MockInterface */
protected $configModel; protected $configModel;
/** @var \Friendica\Core\PConfig\ValueObject\Cache */ /** @var Cache */
protected $configCache; protected $configCache;
/** @var AbstractPConfigValues */ /** @var AbstractPConfigValues */
@ -63,7 +66,7 @@ abstract class PConfigTest extends MockedTest
// Create the config model // Create the config model
$this->configModel = Mockery::mock(PConfigModel::class); $this->configModel = Mockery::mock(PConfigModel::class);
$this->configCache = new \Friendica\Core\PConfig\ValueObject\Cache(); $this->configCache = new Cache();
} }
/** /**
@ -163,7 +166,7 @@ abstract class PConfigTest extends MockedTest
public function testSetUp() public function testSetUp()
{ {
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\PConfig\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertEmpty($this->testedConfig->getCache()->getAll()); self::assertEmpty($this->testedConfig->getCache()->getAll());
} }
@ -174,7 +177,7 @@ abstract class PConfigTest extends MockedTest
public function testLoad(int $uid, array $data, array $possibleCats, array $load) public function testLoad(int $uid, array $data, array $possibleCats, array $load)
{ {
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\PConfig\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
foreach ($load as $loadedCats) { foreach ($load as $loadedCats) {
$this->testedConfig->load($uid, $loadedCats); $this->testedConfig->load($uid, $loadedCats);
@ -257,7 +260,7 @@ abstract class PConfigTest extends MockedTest
public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect) public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
{ {
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\PConfig\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
foreach ($data1 as $cat => $data) { foreach ($data1 as $cat => $data) {
$this->testedConfig->load($uid, $cat); $this->testedConfig->load($uid, $cat);
@ -281,7 +284,7 @@ abstract class PConfigTest extends MockedTest
public function testSetGetWithoutDB(int $uid, $data) public function testSetGetWithoutDB(int $uid, $data)
{ {
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\PConfig\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertTrue($this->testedConfig->set($uid, 'test', 'it', $data)); self::assertTrue($this->testedConfig->set($uid, 'test', 'it', $data));
@ -302,7 +305,7 @@ abstract class PConfigTest extends MockedTest
->once(); ->once();
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\PConfig\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertTrue($this->testedConfig->set($uid, 'test', 'it', $data)); self::assertTrue($this->testedConfig->set($uid, 'test', 'it', $data));
@ -316,7 +319,7 @@ abstract class PConfigTest extends MockedTest
public function testGetWrongWithoutDB() public function testGetWrongWithoutDB()
{ {
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\PConfig\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
// without refresh // without refresh
self::assertNull($this->testedConfig->get(0, 'test', 'it')); self::assertNull($this->testedConfig->get(0, 'test', 'it'));
@ -341,7 +344,7 @@ abstract class PConfigTest extends MockedTest
$this->configCache->load($uid, ['test' => ['it' => 'now']]); $this->configCache->load($uid, ['test' => ['it' => 'now']]);
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\PConfig\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
// without refresh // without refresh
self::assertEquals('now', $this->testedConfig->get($uid, 'test', 'it')); self::assertEquals('now', $this->testedConfig->get($uid, 'test', 'it'));
@ -366,7 +369,7 @@ abstract class PConfigTest extends MockedTest
$this->configCache->load($uid, ['test' => ['it' => $data]]); $this->configCache->load($uid, ['test' => ['it' => $data]]);
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\PConfig\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertEquals($data, $this->testedConfig->get($uid, 'test', 'it')); self::assertEquals($data, $this->testedConfig->get($uid, 'test', 'it'));
self::assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it')); self::assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it'));
@ -405,7 +408,7 @@ abstract class PConfigTest extends MockedTest
->once(); ->once();
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\PConfig\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
// directly set the value to the cache // directly set the value to the cache
$this->testedConfig->getCache()->set($uid, 'test', 'it', 'now'); $this->testedConfig->getCache()->set($uid, 'test', 'it', 'now');
@ -465,7 +468,7 @@ abstract class PConfigTest extends MockedTest
$this->configCache->load($data2['uid'], $data2['data']); $this->configCache->load($data2['uid'], $data2['data']);
$this->testedConfig = $this->getInstance(); $this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\PConfig\ValueObject\Cache::class, $this->testedConfig->getCache()); self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertConfig($data1['uid'], 'cat1', $data1['data']['cat1']); self::assertConfig($data1['uid'], 'cat1', $data1['data']['cat1']);
self::assertConfig($data1['uid'], 'cat2', $data1['data']['cat2']); self::assertConfig($data1['uid'], 'cat2', $data1['data']['cat2']);