diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2024-01-11 15:32:58 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2024-01-15 15:45:13 -0100 |
commit | f7d0c74b1003af6c47dd6ec74f4ef904a2681d62 (patch) | |
tree | a0bfe1934fbec0ccf6651824589a0e67ae4f9d9f /tests/lib | |
parent | e5ef58b7b9b8f7a232666df17d286d43fb4d1201 (diff) | |
download | nextcloud-server-f7d0c74b1003af6c47dd6ec74f4ef904a2681d62.tar.gz nextcloud-server-f7d0c74b1003af6c47dd6ec74f4ef904a2681d62.zip |
lazy AppConfig
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/AppConfigTest.php | 69 | ||||
-rw-r--r-- | tests/lib/DB/QueryBuilder/FunctionBuilderTest.php | 1 |
2 files changed, 34 insertions, 36 deletions
diff --git a/tests/lib/AppConfigTest.php b/tests/lib/AppConfigTest.php index d4ae66cb2f1..a4d4119ba96 100644 --- a/tests/lib/AppConfigTest.php +++ b/tests/lib/AppConfigTest.php @@ -10,8 +10,9 @@ namespace Test; use OC\AppConfig; -use OC\DB\Connection; use OCP\IConfig; +use OCP\IDBConnection; +use Psr\Log\LoggerInterface; /** * Class AppConfigTest @@ -24,15 +25,17 @@ class AppConfigTest extends TestCase { /** @var \OCP\IAppConfig */ protected $appConfig; - /** @var Connection */ - protected $connection; + protected IDBConnection $connection; + private LoggerInterface $logger; protected $originalConfig; protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->get(Connection::class); + $this->connection = \OC::$server->get(IDBConnection::class); + $this->logger = \OC::$server->get(LoggerInterface::class); + $sql = $this->connection->getQueryBuilder(); $sql->select('*') ->from('appconfig'); @@ -44,20 +47,20 @@ class AppConfigTest extends TestCase { $sql->delete('appconfig'); $sql->execute(); - $this->overwriteService(AppConfig::class, new \OC\AppConfig($this->connection)); + $this->overwriteService(AppConfig::class, new \OC\AppConfig($this->connection, $this->logger)); $sql = $this->connection->getQueryBuilder(); $sql->insert('appconfig') ->values([ 'appid' => $sql->createParameter('appid'), 'configkey' => $sql->createParameter('configkey'), - 'configvalue' => $sql->createParameter('configvalue'), + 'configvalue' => $sql->createParameter('configvalue') ]); $sql->setParameters([ 'appid' => 'testapp', 'configkey' => 'enabled', - 'configvalue' => 'true', + 'configvalue' => 'true' ])->execute(); $sql->setParameters([ 'appid' => 'testapp', @@ -125,12 +128,16 @@ class AppConfigTest extends TestCase { 'appid' => $sql->createParameter('appid'), 'configkey' => $sql->createParameter('configkey'), 'configvalue' => $sql->createParameter('configvalue'), + 'lazy' => $sql->createParameter('lazy'), + 'type' => $sql->createParameter('type'), ]); foreach ($this->originalConfig as $configs) { $sql->setParameter('appid', $configs['appid']) ->setParameter('configkey', $configs['configkey']) - ->setParameter('configvalue', $configs['configvalue']); + ->setParameter('configvalue', $configs['configvalue']) + ->setParameter('lazy', ($configs['lazy'] === '1') ? '1' : '0') + ->setParameter('type', $configs['type']); $sql->execute(); } @@ -139,7 +146,7 @@ class AppConfigTest extends TestCase { } public function testGetApps() { - $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); + $config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); $this->assertEqualsCanonicalizing([ 'anotherapp', @@ -150,7 +157,7 @@ class AppConfigTest extends TestCase { } public function testGetKeys() { - $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); + $config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); $keys = $config->getKeys('testapp'); $this->assertEqualsCanonicalizing([ @@ -163,7 +170,7 @@ class AppConfigTest extends TestCase { } public function testGetValue() { - $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); + $config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); $value = $config->getValue('testapp', 'installed_version'); $this->assertConfigKey('testapp', 'installed_version', $value); @@ -176,7 +183,7 @@ class AppConfigTest extends TestCase { } public function testHasKey() { - $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); + $config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); $this->assertTrue($config->hasKey('testapp', 'installed_version')); $this->assertFalse($config->hasKey('testapp', 'nonexistant')); @@ -184,13 +191,13 @@ class AppConfigTest extends TestCase { } public function testSetValueUpdate() { - $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); + $config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); $this->assertEquals('1.2.3', $config->getValue('testapp', 'installed_version')); $this->assertConfigKey('testapp', 'installed_version', '1.2.3'); $wasModified = $config->setValue('testapp', 'installed_version', '1.2.3'); - if (!(\OC::$server->get(Connection::class) instanceof \OC\DB\OracleConnection)) { + if (!(\OC::$server->get(IDBConnection::class) instanceof \OC\DB\OracleConnection)) { $this->assertFalse($wasModified); } @@ -208,7 +215,7 @@ class AppConfigTest extends TestCase { } public function testSetValueInsert() { - $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); + $config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); $this->assertFalse($config->hasKey('someapp', 'somekey')); $this->assertNull($config->getValue('someapp', 'somekey')); @@ -220,13 +227,13 @@ class AppConfigTest extends TestCase { $this->assertConfigKey('someapp', 'somekey', 'somevalue'); $wasInserted = $config->setValue('someapp', 'somekey', 'somevalue'); - if (!(\OC::$server->get(Connection::class) instanceof \OC\DB\OracleConnection)) { + if (!(\OC::$server->get(IDBConnection::class) instanceof \OC\DB\OracleConnection)) { $this->assertFalse($wasInserted); } } public function testDeleteKey() { - $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); + $config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); $this->assertTrue($config->hasKey('testapp', 'deletethis')); @@ -248,7 +255,7 @@ class AppConfigTest extends TestCase { } public function testDeleteApp() { - $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); + $config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); $this->assertTrue($config->hasKey('someapp', 'otherkey')); @@ -268,7 +275,7 @@ class AppConfigTest extends TestCase { } public function testGetValuesNotAllowed() { - $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); + $config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); $this->assertFalse($config->getValues('testapp', 'enabled')); @@ -276,7 +283,7 @@ class AppConfigTest extends TestCase { } public function testGetValues() { - $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); + $config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); $sql = \OC::$server->getDatabaseConnection()->getQueryBuilder(); $sql->select(['configkey', 'configvalue']) @@ -310,20 +317,10 @@ class AppConfigTest extends TestCase { } public function testGetFilteredValues() { - /** @var \OC\AppConfig|\PHPUnit\Framework\MockObject\MockObject $config */ - $config = $this->getMockBuilder(\OC\AppConfig::class) - ->setConstructorArgs([\OC::$server->get(Connection::class)]) - ->setMethods(['getValues']) - ->getMock(); - - $config->expects($this->once()) - ->method('getValues') - ->with('user_ldap', false) - ->willReturn([ - 'ldap_agent_password' => 'secret', - 's42ldap_agent_password' => 'secret', - 'ldap_dn' => 'dn', - ]); + $config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); + $config->setValue('user_ldap', 'ldap_agent_password', 'secret'); + $config->setValue('user_ldap', 's42ldap_agent_password', 'secret'); + $config->setValue('user_ldap', 'ldap_dn', 'dn'); $values = $config->getFilteredValues('user_ldap'); $this->assertEquals([ @@ -334,8 +331,8 @@ class AppConfigTest extends TestCase { } public function testSettingConfigParallel() { - $appConfig1 = new \OC\AppConfig(\OC::$server->get(Connection::class)); - $appConfig2 = new \OC\AppConfig(\OC::$server->get(Connection::class)); + $appConfig1 = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); + $appConfig2 = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); $appConfig1->getValue('testapp', 'foo', 'v1'); $appConfig2->getValue('testapp', 'foo', 'v1'); diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php index 08392b09d8d..430c7d24950 100644 --- a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php @@ -50,6 +50,7 @@ class FunctionBuilderTest extends TestCase { if ($real) { $this->addDummyData(); $query->where($query->expr()->eq('appid', $query->createNamedParameter('group_concat'))); + $query->orderBy('configkey', 'asc'); } $query->select($query->func()->concat(...$arguments)); |