mirror of
https://github.com/friendica/friendica
synced 2025-04-24 21:50:10 +00:00
Fix tests & Router is now using Dependency Injection instead of DI Registry
This commit is contained in:
parent
d5a473abda
commit
f9d0e57f91
12 changed files with 54 additions and 29 deletions
146
tests/src/Core/PConfig/JitPConfigTest.php
Normal file
146
tests/src/Core/PConfig/JitPConfigTest.php
Normal file
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\src\Core\PConfig;
|
||||
|
||||
use Friendica\Core\PConfig\JitPConfig;
|
||||
use Friendica\Test\src\Core\PConfig\PConfigTest;
|
||||
|
||||
class JitPConfigTest extends PConfigTest
|
||||
{
|
||||
public function getInstance()
|
||||
{
|
||||
return new JitPConfig($this->configCache, $this->configModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataConfigLoad
|
||||
*/
|
||||
public function testLoad(int $uid, array $data, array $possibleCats, array $load)
|
||||
{
|
||||
$this->configModel->shouldReceive('isConnected')
|
||||
->andReturn(true)
|
||||
->times(count($load));
|
||||
|
||||
foreach ($load as $loadCat) {
|
||||
$this->configModel->shouldReceive('load')
|
||||
->with($uid, $loadCat)
|
||||
->andReturn([$loadCat => $data[$loadCat]])
|
||||
->once();
|
||||
}
|
||||
|
||||
parent::testLoad($uid, $data, $possibleCats, $load);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataDoubleLoad
|
||||
*/
|
||||
public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
|
||||
{
|
||||
$this->configModel->shouldReceive('isConnected')
|
||||
->andReturn(true)
|
||||
->times(count($data1) + count($data2));
|
||||
|
||||
foreach ($data1 as $cat => $data) {
|
||||
$this->configModel->shouldReceive('load')
|
||||
->with($uid, $cat)
|
||||
->andReturn([$cat => $data])
|
||||
->once();
|
||||
}
|
||||
|
||||
|
||||
foreach ($data2 as $cat => $data) {
|
||||
$this->configModel->shouldReceive('load')
|
||||
->with($uid, $cat)
|
||||
->andReturn([$cat => $data])
|
||||
->once();
|
||||
}
|
||||
|
||||
parent::testCacheLoadDouble($uid, $data1, $data2, $expect);
|
||||
|
||||
// Assert the expected categories
|
||||
foreach ($data2 as $cat => $data) {
|
||||
$this->assertConfig($uid, $cat, $expect[$cat]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testSetGetWithoutDB(int $uid, $data)
|
||||
{
|
||||
$this->configModel->shouldReceive('isConnected')
|
||||
->andReturn(false)
|
||||
->times(2);
|
||||
|
||||
parent::testSetGetWithoutDB($uid, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testSetGetWithDB(int $uid, $data)
|
||||
{
|
||||
$this->configModel->shouldReceive('isConnected')
|
||||
->andReturn(true)
|
||||
->times(2);
|
||||
|
||||
parent::testSetGetWithDB($uid, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testGetWithRefresh(int $uid, $data)
|
||||
{
|
||||
$this->configModel->shouldReceive('isConnected')
|
||||
->andReturn(true)
|
||||
->times(3);
|
||||
|
||||
// mocking one get without result
|
||||
$this->configModel->shouldReceive('get')
|
||||
->with($uid, 'test', 'it')
|
||||
->andReturn(null)
|
||||
->once();
|
||||
|
||||
// mocking the data get
|
||||
$this->configModel->shouldReceive('get')
|
||||
->with($uid, 'test', 'it')
|
||||
->andReturn($data)
|
||||
->once();
|
||||
|
||||
// mocking second get
|
||||
$this->configModel->shouldReceive('get')
|
||||
->with($uid, 'test', 'not')
|
||||
->andReturn(null)
|
||||
->once();
|
||||
|
||||
parent::testGetWithRefresh($uid, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testDeleteWithoutDB(int $uid, $data)
|
||||
{
|
||||
$this->configModel->shouldReceive('isConnected')
|
||||
->andReturn(false)
|
||||
->times(3);
|
||||
|
||||
parent::testDeleteWithoutDB($uid, $data);
|
||||
}
|
||||
|
||||
public function testDeleteWithDB()
|
||||
{
|
||||
$this->configModel->shouldReceive('isConnected')
|
||||
->andReturn(true)
|
||||
->times(5);
|
||||
|
||||
// mocking one get without result
|
||||
$this->configModel->shouldReceive('get')
|
||||
->with(42, 'test', 'it')
|
||||
->andReturn(null)
|
||||
->once();
|
||||
|
||||
parent::testDeleteWithDB();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue