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": {
"mockery/mockery": "^1.3",
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^8.5"
"phpunit/phpunit": "^9",
"dms/phpunit-arraysubset-asserts": "^0.3.1"
},
"scripts": {
"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;
use Friendica\Core\Config\Cache;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Config\Repository\Config as ConfigModel;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Test\MockedTest;
use Mockery\MockInterface;
use Mockery;
abstract class ConfigTest extends MockedTest
{
use ArraySubsetAsserts;
/** @var ConfigModel|MockInterface */
protected $configModel;
/** @var \Friendica\Core\Config\ValueObject\Cache */
/** @var Cache */
protected $configCache;
/** @var IManageConfigValues */
@ -61,7 +64,7 @@ abstract class ConfigTest extends MockedTest
// Create the config model
$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();
$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
self::assertConfig('config', $data['config']);
@ -176,7 +179,7 @@ abstract class ConfigTest extends MockedTest
public function testLoad(array $data, array $load)
{
$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) {
$this->testedConfig->load($loadedCats);
@ -257,7 +260,7 @@ abstract class ConfigTest extends MockedTest
public function testCacheLoadDouble(array $data1, array $data2, array $expect = [])
{
$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) {
$this->testedConfig->load($cat);
@ -282,7 +285,7 @@ abstract class ConfigTest extends MockedTest
$this->configModel->shouldReceive('load')->withAnyArgs()->andReturn([])->once();
$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());
}
@ -299,7 +302,7 @@ abstract class ConfigTest extends MockedTest
->times(3);
$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));
@ -317,7 +320,7 @@ abstract class ConfigTest extends MockedTest
$this->configModel->shouldReceive('set')->with('test', 'it', $data)->andReturn(true)->once();
$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));
@ -331,7 +334,7 @@ abstract class ConfigTest extends MockedTest
public function testGetWrongWithoutDB()
{
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
// without refresh
self::assertNull($this->testedConfig->get('test', 'it'));
@ -353,10 +356,10 @@ abstract class ConfigTest extends MockedTest
*/
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();
self::assertInstanceOf(\Friendica\Core\Config\ValueObject\Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
// without refresh
self::assertEquals('now', $this->testedConfig->get('test', 'it'));
@ -378,10 +381,10 @@ abstract class ConfigTest extends MockedTest
*/
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();
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->getCache()->get('test', 'it'));
@ -398,7 +401,7 @@ abstract class ConfigTest extends MockedTest
*/
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')
->with('test', 'it')
@ -418,7 +421,7 @@ abstract class ConfigTest extends MockedTest
->once();
$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
$this->testedConfig->getCache()->set('test', 'it', 'now');
@ -444,9 +447,9 @@ abstract class ConfigTest extends MockedTest
public function testSetGetHighPrio()
{
$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'));
// 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()
{
$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'));
$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
self::assertFalse($this->testedConfig->set('config', 'test', '123'));
self::assertEquals('prio', $this->testedConfig->get('config', 'test', '', true));

View File

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

View File

@ -21,19 +21,22 @@
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\Repository\PConfig as PConfigModel;
use Friendica\Core\PConfig\ValueObject\Cache;
use Friendica\Test\MockedTest;
use Mockery;
use Mockery\MockInterface;
abstract class PConfigTest extends MockedTest
{
use ArraySubsetAsserts;
/** @var PConfigModel|MockInterface */
protected $configModel;
/** @var \Friendica\Core\PConfig\ValueObject\Cache */
/** @var Cache */
protected $configCache;
/** @var AbstractPConfigValues */
@ -63,7 +66,7 @@ abstract class PConfigTest extends MockedTest
// Create the config model
$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()
{
$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());
}
@ -174,7 +177,7 @@ abstract class PConfigTest extends MockedTest
public function testLoad(int $uid, array $data, array $possibleCats, array $load)
{
$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) {
$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)
{
$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) {
$this->testedConfig->load($uid, $cat);
@ -281,7 +284,7 @@ abstract class PConfigTest extends MockedTest
public function testSetGetWithoutDB(int $uid, $data)
{
$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));
@ -302,7 +305,7 @@ abstract class PConfigTest extends MockedTest
->once();
$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));
@ -316,7 +319,7 @@ abstract class PConfigTest extends MockedTest
public function testGetWrongWithoutDB()
{
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\PConfig\ValueObject\Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
// without refresh
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->testedConfig = $this->getInstance();
self::assertInstanceOf(\Friendica\Core\PConfig\ValueObject\Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
// without refresh
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->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->getCache()->get($uid, 'test', 'it'));
@ -405,7 +408,7 @@ abstract class PConfigTest extends MockedTest
->once();
$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
$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->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'], 'cat2', $data1['data']['cat2']);

View File

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

View File

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

View File

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