Merge pull request #11087 from nupplaphil/feat/tests_adaption

Tests - avoid deprecation notices
This commit is contained in:
Hypolite Petovan 2021-12-10 19:29:54 -05:00 committed by GitHub
commit 753cf8aeae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 621 additions and 356 deletions

View file

@ -127,7 +127,8 @@
"require-dev": { "require-dev": {
"mockery/mockery": "^1.3", "mockery/mockery": "^1.3",
"mikey179/vfsstream": "^1.6", "mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^8.5" "phpunit/phpunit": "^9",
"dms/phpunit-arraysubset-asserts": "^0.3.1"
}, },
"scripts": { "scripts": {
"test": "phpunit", "test": "phpunit",

892
composer.lock generated

File diff suppressed because it is too large Load diff

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']);

View file

@ -39,8 +39,8 @@ class UpdateTest extends ApiTest
$json = $this->toJson($response); $json = $this->toJson($response);
self::assertStatus($json); self::assertStatus($json);
self::assertContains('Status content #friendica', $json->text); self::assertStringContainsString('Status content #friendica', $json->text);
self::assertContains('Status content #', $json->statusnet_html); self::assertStringContainsString('Status content #', $json->statusnet_html);
} }
/** /**

View file

@ -6,7 +6,7 @@ use Friendica\Test\src\Module\Api\ApiTest;
class BaseApiTest extends ApiTest class BaseApiTest extends ApiTest
{ {
public function withWrongAuth() public function testWithWrongAuth()
{ {
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first'); self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');

View file

@ -2,6 +2,7 @@
namespace Friendica\Test\src\Util; namespace Friendica\Test\src\Util;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Friendica\Test\DiceHttpMockHandlerTrait; use Friendica\Test\DiceHttpMockHandlerTrait;
use Friendica\Test\MockedTest; use Friendica\Test\MockedTest;
use Friendica\Util\Images; use Friendica\Util\Images;
@ -11,6 +12,7 @@ use GuzzleHttp\Psr7\Response;
class ImagesTest extends MockedTest class ImagesTest extends MockedTest
{ {
use DiceHttpMockHandlerTrait; use DiceHttpMockHandlerTrait;
use ArraySubsetAsserts;
protected function setUp(): void protected function setUp(): void
{ {