diff options
author | Joas Schilling <coding@schilljs.com> | 2016-10-28 13:48:58 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-11-02 20:30:37 +0100 |
commit | 2c4035e80679b6ebf8e56d86f88701f3ddb65bec (patch) | |
tree | a1bd0571d1bc4eab25ad28f4120bfae4582de637 | |
parent | cd13f50a3f1fbcae757672b4a471d8fbcf959b08 (diff) | |
download | nextcloud-server-2c4035e80679b6ebf8e56d86f88701f3ddb65bec.tar.gz nextcloud-server-2c4035e80679b6ebf8e56d86f88701f3ddb65bec.zip |
Inject config and logger
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/private/DB/Connection.php | 6 | ||||
-rw-r--r-- | lib/private/DB/QueryBuilder/QueryBuilder.php | 22 | ||||
-rw-r--r-- | tests/lib/DB/QueryBuilder/QueryBuilderTest.php | 24 | ||||
-rw-r--r-- | tests/lib/Security/CredentialsManagerTest.php | 12 |
4 files changed, 51 insertions, 13 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index dfe2e86b617..497ff0c8a26 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -67,7 +67,11 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection { * @return \OCP\DB\QueryBuilder\IQueryBuilder */ public function getQueryBuilder() { - return new QueryBuilder($this); + return new QueryBuilder( + $this, + \OC::$server->getSystemConfig(), + \OC::$server->getLogger() + ); } /** diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php index aefc84f9c9a..d5dd9cf0366 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -31,16 +31,24 @@ use OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder; use OC\DB\QueryBuilder\ExpressionBuilder\MySqlExpressionBuilder; use OC\DB\QueryBuilder\ExpressionBuilder\OCIExpressionBuilder; use OC\DB\QueryBuilder\ExpressionBuilder\PgSqlExpressionBuilder; +use OC\SystemConfig; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryFunction; use OCP\DB\QueryBuilder\IParameter; use OCP\IDBConnection; +use OCP\ILogger; class QueryBuilder implements IQueryBuilder { /** @var \OCP\IDBConnection */ private $connection; + /** @var SystemConfig */ + private $systemConfig; + + /** @var ILogger */ + private $logger; + /** @var \Doctrine\DBAL\Query\QueryBuilder */ private $queryBuilder; @@ -56,10 +64,14 @@ class QueryBuilder implements IQueryBuilder { /** * Initializes a new QueryBuilder. * - * @param \OCP\IDBConnection $connection + * @param IDBConnection $connection + * @param SystemConfig $systemConfig + * @param ILogger $logger */ - public function __construct(IDBConnection $connection) { + public function __construct(IDBConnection $connection, SystemConfig $systemConfig, ILogger $logger) { $this->connection = $connection; + $this->systemConfig = $systemConfig; + $this->logger = $logger; $this->queryBuilder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection); $this->helper = new QuoteHelper(); } @@ -139,7 +151,7 @@ class QueryBuilder implements IQueryBuilder { * @return \Doctrine\DBAL\Driver\Statement|int */ public function execute() { - if (\OC::$server->getConfig()->getSystemValue('log_query', false)) { + if ($this->systemConfig->getValue('log_query', false)) { $params = []; foreach ($this->getParameters() as $placeholder => $value) { if (is_array($value)) { @@ -149,12 +161,12 @@ class QueryBuilder implements IQueryBuilder { } } if (empty($params)) { - \OC::$server->getLogger()->debug('DB QueryBuilder: \'{query}\'', [ + $this->logger->debug('DB QueryBuilder: \'{query}\'', [ 'query' => $this->getSQL(), 'app' => 'core', ]); } else { - \OC::$server->getLogger()->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [ + $this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [ 'query' => $this->getSQL(), 'params' => implode(', ', $params), 'app' => 'core', diff --git a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php index 3c10d25c535..171b44fe92d 100644 --- a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php @@ -25,7 +25,9 @@ use Doctrine\DBAL\Query\Expression\CompositeExpression; use OC\DB\QueryBuilder\Literal; use OC\DB\QueryBuilder\Parameter; use OC\DB\QueryBuilder\QueryBuilder; +use OC\SystemConfig; use OCP\IDBConnection; +use OCP\ILogger; /** * Class QueryBuilderTest @@ -41,11 +43,19 @@ class QueryBuilderTest extends \Test\TestCase { /** @var IDBConnection */ protected $connection; + /** @var SystemConfig|\PHPUnit_Framework_MockObject_MockObject */ + protected $config; + + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + protected $logger; + protected function setUp() { parent::setUp(); $this->connection = \OC::$server->getDatabaseConnection(); - $this->queryBuilder = new QueryBuilder($this->connection); + $this->config = $this->createMock(SystemConfig::class); + $this->logger = $this->createMock(ILogger::class); + $this->queryBuilder = new QueryBuilder($this->connection, $this->config, $this->logger); } protected function createTestingRows($appId = 'testFirstResult') { @@ -166,7 +176,9 @@ class QueryBuilderTest extends \Test\TestCase { } public function dataSelect() { - $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection()); + $config = $this->createMock(SystemConfig::class); + $logger = $this->createMock(ILogger::class); + $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger); return [ // select('column1') [['configvalue'], ['configvalue' => '99']], @@ -232,7 +244,9 @@ class QueryBuilderTest extends \Test\TestCase { } public function dataSelectAlias() { - $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection()); + $config = $this->createMock(SystemConfig::class); + $logger = $this->createMock(ILogger::class); + $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger); return [ ['configvalue', 'cv', ['cv' => '99']], [$queryBuilder->expr()->literal('column1'), 'thing', ['thing' => 'column1']], @@ -301,7 +315,9 @@ class QueryBuilderTest extends \Test\TestCase { } public function dataAddSelect() { - $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection()); + $config = $this->createMock(SystemConfig::class); + $logger = $this->createMock(ILogger::class); + $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger); return [ // addSelect('column1') [['configvalue'], ['appid' => 'testFirstResult', 'configvalue' => '99']], diff --git a/tests/lib/Security/CredentialsManagerTest.php b/tests/lib/Security/CredentialsManagerTest.php index cffcc02817c..38da26a21a9 100644 --- a/tests/lib/Security/CredentialsManagerTest.php +++ b/tests/lib/Security/CredentialsManagerTest.php @@ -21,6 +21,8 @@ namespace Test\Security; +use OC\SystemConfig; +use OCP\ILogger; use \OCP\Security\ICrypto; use \OCP\IDBConnection; use \OC\Security\CredentialsManager; @@ -45,7 +47,7 @@ class CredentialsManagerTest extends \Test\TestCase { $this->manager = new CredentialsManager($this->crypto, $this->dbConnection); } - private function getQeuryResult($row) { + private function getQueryResult($row) { $result = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement') ->disableOriginalConstructor() ->getMock(); @@ -87,12 +89,16 @@ class CredentialsManagerTest extends \Test\TestCase { ->willReturn(json_encode('bar')); $qb = $this->getMockBuilder('\OC\DB\QueryBuilder\QueryBuilder') - ->setConstructorArgs([$this->dbConnection]) + ->setConstructorArgs([ + $this->dbConnection, + $this->createMock(SystemConfig::class), + $this->createMock(ILogger::class), + ]) ->setMethods(['execute']) ->getMock(); $qb->expects($this->once()) ->method('execute') - ->willReturn($this->getQeuryResult(['credentials' => 'baz'])); + ->willReturn($this->getQueryResult(['credentials' => 'baz'])); $this->dbConnection->expects($this->once()) ->method('getQueryBuilder') |