]> git.mxchange.org Git - friendica.git/commitdiff
Improve & fixing Tests
authorPhilipp Holzer <admin+github@philipp.info>
Thu, 4 Jul 2019 19:39:49 +0000 (21:39 +0200)
committerPhilipp Holzer <admin+github@philipp.info>
Sun, 14 Jul 2019 20:12:11 +0000 (22:12 +0200)
src/Core/Config/JitConfiguration.php
src/Model/Config/DbaConfig.php
tests/DatabaseTest.php
tests/include/ApiTest.php
tests/src/Core/Config/ConfigurationTest.php
tests/src/Database/DBATest.php
tests/src/Database/DBStructureTest.php

index f8260c9e476f927b3da907187b5f422b4a777e18..e5b7b5e47c9f2a7d2e104f028917ef79cb9cd752 100644 (file)
@@ -50,8 +50,10 @@ class JitConfiguration extends Configuration
 
                $config = $this->configModel->load($cat);
 
-               foreach ($config[$cat] as $key => $value) {
-                       $this->in_db[$cat][$key] = true;
+               if (!empty($config[$cat])) {
+                       foreach ($config[$cat] as $key => $value) {
+                               $this->in_db[$cat][$key] = true;
+                       }
                }
 
                // load the whole category out of the DB into the cache
index bbd62c7cbe1e64af6fb01e1de60db3755899656d..aa6a1f3e278f2a0b400e9f95249c1874615065ad 100644 (file)
@@ -11,7 +11,7 @@ abstract class DbaConfig
 
        public function __construct(Database $dba)
        {
-               $this->dba    = $dba;
+               $this->dba = $dba;
        }
 
        /**
index b3418c20f4024878c9999ebf9f6d908d6374335b..999da871dbb047ef8386bee002bcfe611344827e 100644 (file)
@@ -5,12 +5,15 @@
 
 namespace Friendica\Test;
 
-use Friendica\App;
-use Friendica\Database\DBA;
-use Friendica\Factory;
+use Friendica\App\Mode;
+use Friendica\App\Router;
+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\Config\ConfigFileLoader;
-use Friendica\Util\Logger\VoidLogger;
 use Friendica\Util\Profiler;
 use PHPUnit\DbUnit\DataSet\YamlDataSet;
 use PHPUnit\DbUnit\TestCaseTrait;
@@ -25,6 +28,33 @@ abstract class DatabaseTest extends MockedTest
 {
        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.
         *
@@ -42,27 +72,13 @@ abstract class DatabaseTest extends MockedTest
                        $this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
                }
 
-               $basePath = BasePath::create(dirname(__DIR__));
-               $mode = new App\Mode($basePath);
-               $configLoader = new ConfigFileLoader($basePath, $mode);
-               $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.');
+               if (!self::$dba->isConnected()) {
+                       if (!self::$dba->connect()) {
+                               $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'));
        }
 
        /**
index 94557ac69c234b46b78a1bb48f8608d9c94632f1..17b7469fa111116b4a8711bceda4f53847f4d44c 100644 (file)
@@ -49,18 +49,13 @@ class ApiTest extends DatabaseTest
         */
        public function setUp()
        {
-               $basePath = BasePath::create(dirname(__DIR__) . '/../');
-               $mode = new App\Mode($basePath);
-               $router = new App\Router();
-               $configLoader = new ConfigFileLoader($basePath, $mode);
-               $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);
+               $configModel = new \Friendica\Model\Config\Config(self::$dba);
+               $config = Factory\ConfigFactory::createConfig(self::$configCache, $configModel);
+               Factory\ConfigFactory::createPConfig(new Config\Cache\PConfigCache());
+               $logger = Factory\LoggerFactory::create('test', self::$dba, $config, self::$profiler);
                $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();
 
index b9546cea7f392834691257a37243771bba02af1e..2191d86f1cbe9b0ca663286f5ac87a78d2df7288 100644 (file)
@@ -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
         *
index 84d17dc899842577ba4beaa5bab27f946a2d861a..24f723e5a09486c64820c2ff8d430974c7534e7c 100644 (file)
@@ -6,26 +6,19 @@ use Friendica\Core\Config;
 use Friendica\Database\DBA;
 use Friendica\Factory;
 use Friendica\Test\DatabaseTest;
-use Friendica\Util\BasePath;
 use Friendica\Util\BaseURL;
-use Friendica\Util\Config\ConfigFileLoader;
 
 class DBATest extends DatabaseTest
 {
        public function setUp()
        {
-               $basePath = BasePath::create(dirname(__DIR__) . '/../../');
-               $mode = new App\Mode($basePath);
-               $router = new App\Router();
-               $configLoader = new ConfigFileLoader($basePath, $mode);
-               $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);
+               $configModel = new \Friendica\Model\Config\Config(self::$dba);
+               $config = Factory\ConfigFactory::createConfig(self::$configCache, $configModel);
+               Factory\ConfigFactory::createPConfig(new Config\Cache\PConfigCache());
+               $logger = Factory\LoggerFactory::create('test', self::$dba, $config, self::$profiler);
                $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();
 
index b005d8d53de60d5b897af99a4d620a6a77c570b7..51707873cb2e335445cafe4f5db0d4ce0b852ca4 100644 (file)
@@ -7,26 +7,19 @@ use Friendica\Core\Config\Cache\PConfigCache;
 use Friendica\Database\DBStructure;
 use Friendica\Factory;
 use Friendica\Test\DatabaseTest;
-use Friendica\Util\BasePath;
 use Friendica\Util\BaseURL;
-use Friendica\Util\Config\ConfigFileLoader;
 
 class DBStructureTest extends DatabaseTest
 {
        public function setUp()
        {
-               $basePath = BasePath::create(dirname(__DIR__) . '/../../');
-               $mode = new App\Mode($basePath);
-               $router = new App\Router();
-               $configLoader = new ConfigFileLoader($basePath, $mode);
-               $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);
+               $configModel = new \Friendica\Model\Config\Config(self::$dba);
+               $config = Factory\ConfigFactory::createConfig(self::$configCache, $configModel);
+               Factory\ConfigFactory::createPConfig(new PConfigCache());
+               $logger = Factory\LoggerFactory::create('test', self::$dba, $config, self::$profiler);
                $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();
        }