Improve & fixing Tests
This commit is contained in:
parent
486f139342
commit
c293eadb78
|
@ -50,8 +50,10 @@ class JitConfiguration extends Configuration
|
||||||
|
|
||||||
$config = $this->configModel->load($cat);
|
$config = $this->configModel->load($cat);
|
||||||
|
|
||||||
foreach ($config[$cat] as $key => $value) {
|
if (!empty($config[$cat])) {
|
||||||
$this->in_db[$cat][$key] = true;
|
foreach ($config[$cat] as $key => $value) {
|
||||||
|
$this->in_db[$cat][$key] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the whole category out of the DB into the cache
|
// load the whole category out of the DB into the cache
|
||||||
|
|
|
@ -11,7 +11,7 @@ abstract class DbaConfig
|
||||||
|
|
||||||
public function __construct(Database $dba)
|
public function __construct(Database $dba)
|
||||||
{
|
{
|
||||||
$this->dba = $dba;
|
$this->dba = $dba;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,12 +5,15 @@
|
||||||
|
|
||||||
namespace Friendica\Test;
|
namespace Friendica\Test;
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App\Mode;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\App\Router;
|
||||||
use Friendica\Factory;
|
use Friendica\Core\Config\Cache\ConfigCache;
|
||||||
|
use Friendica\Database\Database;
|
||||||
|
use Friendica\Factory\ConfigFactory;
|
||||||
|
use Friendica\Factory\DBFactory;
|
||||||
|
use Friendica\Factory\ProfilerFactory;
|
||||||
use Friendica\Util\BasePath;
|
use Friendica\Util\BasePath;
|
||||||
use Friendica\Util\Config\ConfigFileLoader;
|
use Friendica\Util\Config\ConfigFileLoader;
|
||||||
use Friendica\Util\Logger\VoidLogger;
|
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use PHPUnit\DbUnit\DataSet\YamlDataSet;
|
use PHPUnit\DbUnit\DataSet\YamlDataSet;
|
||||||
use PHPUnit\DbUnit\TestCaseTrait;
|
use PHPUnit\DbUnit\TestCaseTrait;
|
||||||
|
@ -25,6 +28,33 @@ abstract class DatabaseTest extends MockedTest
|
||||||
{
|
{
|
||||||
use TestCaseTrait;
|
use TestCaseTrait;
|
||||||
|
|
||||||
|
/** @var Database */
|
||||||
|
protected static $dba;
|
||||||
|
|
||||||
|
/** @var BasePath */
|
||||||
|
protected static $basePath;
|
||||||
|
|
||||||
|
/** @var Mode */
|
||||||
|
protected static $mode;
|
||||||
|
|
||||||
|
/** @var ConfigCache */
|
||||||
|
protected static $configCache;
|
||||||
|
|
||||||
|
/** @var Profiler */
|
||||||
|
protected static $profiler;
|
||||||
|
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
parent::setUpBeforeClass();
|
||||||
|
|
||||||
|
self::$basePath = BasePath::create(dirname(__DIR__));
|
||||||
|
self::$mode = new Mode(self::$basePath);
|
||||||
|
$configLoader = new ConfigFileLoader(self::$basePath, self::$mode);
|
||||||
|
self::$configCache = ConfigFactory::createCache($configLoader);
|
||||||
|
self::$profiler = ProfilerFactory::create(self::$configCache);
|
||||||
|
self::$dba = DBFactory::init(self::$configCache, self::$profiler, $_SERVER);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get database connection.
|
* Get database connection.
|
||||||
*
|
*
|
||||||
|
@ -42,27 +72,13 @@ abstract class DatabaseTest extends MockedTest
|
||||||
$this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
|
$this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$basePath = BasePath::create(dirname(__DIR__));
|
if (!self::$dba->isConnected()) {
|
||||||
$mode = new App\Mode($basePath);
|
if (!self::$dba->connect()) {
|
||||||
$configLoader = new ConfigFileLoader($basePath, $mode);
|
$this->markTestSkipped('Could not connect to the database.');
|
||||||
$config = Factory\ConfigFactory::createCache($configLoader);
|
}
|
||||||
|
|
||||||
$profiler = \Mockery::mock(Profiler::class);
|
|
||||||
|
|
||||||
DBA::connect(
|
|
||||||
$config,
|
|
||||||
$profiler,
|
|
||||||
new VoidLogger(),
|
|
||||||
getenv('MYSQL_HOST'),
|
|
||||||
getenv('MYSQL_USERNAME'),
|
|
||||||
getenv('MYSQL_PASSWORD'),
|
|
||||||
getenv('MYSQL_DATABASE'));
|
|
||||||
|
|
||||||
if (!DBA::connected()) {
|
|
||||||
$this->markTestSkipped('Could not connect to the database.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->createDefaultDBConnection(DBA::getConnection(), getenv('MYSQL_DATABASE'));
|
return $this->createDefaultDBConnection(self::$dba->getConnection(), getenv('MYSQL_DATABASE'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -49,18 +49,13 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$basePath = BasePath::create(dirname(__DIR__) . '/../');
|
$configModel = new \Friendica\Model\Config\Config(self::$dba);
|
||||||
$mode = new App\Mode($basePath);
|
$config = Factory\ConfigFactory::createConfig(self::$configCache, $configModel);
|
||||||
$router = new App\Router();
|
Factory\ConfigFactory::createPConfig(new Config\Cache\PConfigCache());
|
||||||
$configLoader = new ConfigFileLoader($basePath, $mode);
|
$logger = Factory\LoggerFactory::create('test', self::$dba, $config, self::$profiler);
|
||||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
|
||||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
|
||||||
$database = Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
|
||||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
|
||||||
Factory\ConfigFactory::createPConfig($configCache, new Config\Cache\PConfigCache());
|
|
||||||
$logger = Factory\LoggerFactory::create('test', $database, $config, $profiler);
|
|
||||||
$baseUrl = new BaseURL($config, $_SERVER);
|
$baseUrl = new BaseURL($config, $_SERVER);
|
||||||
$this->app = new App($database, $config, $mode, $router, $baseUrl, $logger, $profiler, false);
|
$router = new App\Router();
|
||||||
|
$this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, false);
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
|
|
@ -252,6 +252,20 @@ abstract class ConfigurationTest extends MockedTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the configuration load without result
|
||||||
|
*/
|
||||||
|
public function testLoadWrong()
|
||||||
|
{
|
||||||
|
$this->configModel->shouldReceive('isConnected')->andReturn(true)->once();
|
||||||
|
$this->configModel->shouldReceive('load')->withAnyArgs()->andReturn([])->once();
|
||||||
|
|
||||||
|
$this->testedConfig = $this->getInstance();
|
||||||
|
$this->assertInstanceOf(ConfigCache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
|
$this->assertEmpty($this->testedConfig->getCache()->getAll());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the configuration get() and set() methods without adapter
|
* Test the configuration get() and set() methods without adapter
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,26 +6,19 @@ use Friendica\Core\Config;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Factory;
|
use Friendica\Factory;
|
||||||
use Friendica\Test\DatabaseTest;
|
use Friendica\Test\DatabaseTest;
|
||||||
use Friendica\Util\BasePath;
|
|
||||||
use Friendica\Util\BaseURL;
|
use Friendica\Util\BaseURL;
|
||||||
use Friendica\Util\Config\ConfigFileLoader;
|
|
||||||
|
|
||||||
class DBATest extends DatabaseTest
|
class DBATest extends DatabaseTest
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$basePath = BasePath::create(dirname(__DIR__) . '/../../');
|
$configModel = new \Friendica\Model\Config\Config(self::$dba);
|
||||||
$mode = new App\Mode($basePath);
|
$config = Factory\ConfigFactory::createConfig(self::$configCache, $configModel);
|
||||||
$router = new App\Router();
|
Factory\ConfigFactory::createPConfig(new Config\Cache\PConfigCache());
|
||||||
$configLoader = new ConfigFileLoader($basePath, $mode);
|
$logger = Factory\LoggerFactory::create('test', self::$dba, $config, self::$profiler);
|
||||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
|
||||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
|
||||||
$database = Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
|
||||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
|
||||||
Factory\ConfigFactory::createPConfig($configCache, new Config\Cache\PConfigCache());
|
|
||||||
$logger = Factory\LoggerFactory::create('test', $database, $config, $profiler);
|
|
||||||
$baseUrl = new BaseURL($config, $_SERVER);
|
$baseUrl = new BaseURL($config, $_SERVER);
|
||||||
$this->app = new App($database, $config, $mode, $router, $baseUrl, $logger, $profiler, false);
|
$router = new App\Router();
|
||||||
|
$this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, false);
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
|
|
@ -7,26 +7,19 @@ use Friendica\Core\Config\Cache\PConfigCache;
|
||||||
use Friendica\Database\DBStructure;
|
use Friendica\Database\DBStructure;
|
||||||
use Friendica\Factory;
|
use Friendica\Factory;
|
||||||
use Friendica\Test\DatabaseTest;
|
use Friendica\Test\DatabaseTest;
|
||||||
use Friendica\Util\BasePath;
|
|
||||||
use Friendica\Util\BaseURL;
|
use Friendica\Util\BaseURL;
|
||||||
use Friendica\Util\Config\ConfigFileLoader;
|
|
||||||
|
|
||||||
class DBStructureTest extends DatabaseTest
|
class DBStructureTest extends DatabaseTest
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$basePath = BasePath::create(dirname(__DIR__) . '/../../');
|
$configModel = new \Friendica\Model\Config\Config(self::$dba);
|
||||||
$mode = new App\Mode($basePath);
|
$config = Factory\ConfigFactory::createConfig(self::$configCache, $configModel);
|
||||||
$router = new App\Router();
|
Factory\ConfigFactory::createPConfig(new PConfigCache());
|
||||||
$configLoader = new ConfigFileLoader($basePath, $mode);
|
$logger = Factory\LoggerFactory::create('test', self::$dba, $config, self::$profiler);
|
||||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
|
||||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
|
||||||
$database = Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
|
||||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
|
||||||
Factory\ConfigFactory::createPConfig($configCache, new PConfigCache());
|
|
||||||
$logger = Factory\LoggerFactory::create('test', $database, $config, $profiler);
|
|
||||||
$baseUrl = new BaseURL($config, $_SERVER);
|
$baseUrl = new BaseURL($config, $_SERVER);
|
||||||
$this->app = new App($database, $config, $mode, $router, $baseUrl, $logger, $profiler, false);
|
$router = new App\Router();
|
||||||
|
$this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, false);
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue