diff --git a/composer.json b/composer.json index 4b2d447..9149ca1 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": "^5.6|>=7.0.8", "symfony/process": "^3.4", "console-helpers/console-kit": "^0.1@dev", - "aura/sql": "^2.5", + "aura/sql": "^3.0 || ^4.0 || ^5.0", "padraic/phar-updater": "dev-use-curl", "padraic/humbug_get_contents": "^1.0", "console-helpers/db-migration": "^0.1.0", diff --git a/composer.lock b/composer.lock index 5ea5049..82223d4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,34 +4,31 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "089e63225eaa4a0c884e6c056745db6b", + "content-hash": "b5a721a50bd37f8bd2e364a9d58905ad", "packages": [ { "name": "aura/sql", - "version": "2.6.0", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/auraphp/Aura.Sql.git", - "reference": "16206efbe5ba63603fe3b18ba54a4c5296cd5f3e" + "reference": "88d8b8ed1bcfd588a649fdc7e7ac89ec047abbca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/auraphp/Aura.Sql/zipball/16206efbe5ba63603fe3b18ba54a4c5296cd5f3e", - "reference": "16206efbe5ba63603fe3b18ba54a4c5296cd5f3e", + "url": "https://api.github.com/repos/auraphp/Aura.Sql/zipball/88d8b8ed1bcfd588a649fdc7e7ac89ec047abbca", + "reference": "88d8b8ed1bcfd588a649fdc7e7ac89ec047abbca", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=5.6.0", + "psr/log": "^1.0 || ^2.0" }, "require-dev": { - "phpunit/phpunit": "~5.7 || ~4.8" + "pds/skeleton": "~1.0", + "yoast/phpunit-polyfills": "~1.0" }, "type": "library", - "extra": { - "aura": { - "type": "library" - } - }, "autoload": { "psr-4": { "Aura\\Sql\\": "src/" @@ -39,7 +36,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-2-Clause" + "MIT" ], "authors": [ { @@ -47,7 +44,7 @@ "homepage": "https://github.com/auraphp/Aura.Sql/contributors" } ], - "description": "A PDO extension that provides lazy connections, array quoting, identifier quoting, query profiling, value binding, and convenience methods for common fetch styles. Because it extends PDO, existing code that uses PDO can use this without any changes to the existing code.", + "description": "A PDO extension that provides lazy connections, array quoting, query profiling, value binding, and convenience methods for common fetch styles. Because it extends PDO, existing code that uses PDO can use this without any changes to the existing code.", "homepage": "https://github.com/auraphp/Aura.Sql", "keywords": [ "mysql", @@ -62,9 +59,9 @@ ], "support": { "issues": "https://github.com/auraphp/Aura.Sql/issues", - "source": "https://github.com/auraphp/Aura.Sql/tree/2.x" + "source": "https://github.com/auraphp/Aura.Sql/tree/3.1.0" }, - "time": "2018-08-15T13:33:56+00:00" + "time": "2022-04-28T05:11:23+00:00" }, { "name": "composer/ca-bundle", diff --git a/src/SVNBuddy/Database/StatementProfiler.php b/src/SVNBuddy/Database/StatementProfiler.php index 1f43831..f51310a 100644 --- a/src/SVNBuddy/Database/StatementProfiler.php +++ b/src/SVNBuddy/Database/StatementProfiler.php @@ -11,8 +11,11 @@ namespace ConsoleHelpers\SVNBuddy\Database; -use Aura\Sql\ProfilerInterface; +use Aura\Sql\Profiler\ProfilerInterface; use ConsoleHelpers\ConsoleKit\ConsoleIO; +use Psr\Log\LoggerInterface; +use Psr\Log\LogLevel; +use Psr\Log\NullLogger; class StatementProfiler implements ProfilerInterface { @@ -24,6 +27,29 @@ class StatementProfiler implements ProfilerInterface */ protected $active = false; + /** + * Log profile data through this interface. + * + * @var LoggerInterface + */ + protected $logger; + + /** + * The log level for all messages. + * + * @var string + * @see setLogLevel() + */ + protected $logLevel = LogLevel::DEBUG; + + /** + * Sets the format for the log message, with placeholders. + * + * @var string + * @see setLogFormat() + */ + protected $logFormat = '{function} ({duration} seconds): {statement} {backtrace}'; + /** * Retained profiles. * @@ -71,6 +97,7 @@ class StatementProfiler implements ProfilerInterface */ public function __construct() { + $this->logger = new NullLogger(); $this->_backtraceOptions = defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? DEBUG_BACKTRACE_IGNORE_ARGS : 0; } @@ -281,4 +308,60 @@ public function resetProfiles() $this->profiles = array(); } + /** + * @inheritDoc + */ + public function getLogger() + { + return $this->logger; + } + + /** + * @inheritDoc + */ + public function getLogLevel() + { + return $this->logLevel; + } + + /** + * @inheritDoc + */ + public function setLogLevel($logLevel) + { + $this->logLevel = $logLevel; + } + + /** + * @inheritDoc + */ + public function getLogFormat() + { + return $this->logFormat; + } + + /** + * @inheritDoc + */ + public function setLogFormat($logFormat) + { + $this->logFormat = $logFormat; + } + + /** + * @inheritDoc + */ + public function start($function) + { + + } + + /** + * @inheritDoc + */ + public function finish($statement = null, array $values = []) + { + + } + } diff --git a/tests/SVNBuddy/Database/StatementProfilerTest.php b/tests/SVNBuddy/Database/StatementProfilerTest.php index 44e140e..e20ac67 100644 --- a/tests/SVNBuddy/Database/StatementProfilerTest.php +++ b/tests/SVNBuddy/Database/StatementProfilerTest.php @@ -13,6 +13,8 @@ use ConsoleHelpers\SVNBuddy\Database\StatementProfiler; use Prophecy\Argument; +use Psr\Log\LoggerInterface; +use Psr\Log\LogLevel; use Tests\ConsoleHelpers\SVNBuddy\AbstractTestCase; class StatementProfilerTest extends AbstractTestCase @@ -186,7 +188,7 @@ public function testIgnoredDuplicateStatementsAppearInVerboseOutput() ->writeln(array( '', '[db, 5s]: IGNORE ME "bb"', - '[db origin]: ' . __FILE__ . ':197', + '[db origin]: ' . __FILE__ . ':199', )) ->shouldBeCalled(); $this->statementProfiler->setIO($io->reveal()); @@ -214,7 +216,7 @@ public function testVerboseOutput() $io->isVerbose()->willReturn(true)->shouldBeCalled(); // The PHP7 threats multi-line statement position differently in traces. - $expect_line = PHP_VERSION_ID < 70000 ? 234 : 233; + $expect_line = PHP_VERSION_ID < 70000 ? 236 : 235; $io ->writeln(array( @@ -247,5 +249,22 @@ public function testNonVerboseOutput() $this->assertCount(1, $this->statementProfiler->getProfiles()); } + public function testGetLogger() + { + $this->assertInstanceOf(LoggerInterface::class, $this->statementProfiler->getLogger()); + } + + public function testLogLevel() + { + $this->statementProfiler->setLogLevel(LogLevel::ERROR); + $this->assertEquals(LogLevel::ERROR, $this->statementProfiler->getLogLevel()); + } + + public function testLogFormat() + { + $this->statementProfiler->setLogFormat('test'); + $this->assertEquals('test', $this->statementProfiler->getLogFormat()); + } + }