Skip to content

Commit

Permalink
Upgrade to Aura.Sql 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aik099 committed Mar 28, 2024
1 parent 40cff27 commit bcaf1bd
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 13 additions & 16 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 84 additions & 1 deletion src/SVNBuddy/Database/StatementProfiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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.
*
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 = [])
{

}

}
23 changes: 21 additions & 2 deletions tests/SVNBuddy/Database/StatementProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -186,7 +188,7 @@ public function testIgnoredDuplicateStatementsAppearInVerboseOutput()
->writeln(array(
'',
'<debug>[db, 5s]: IGNORE ME "bb"</debug>',
'<debug>[db origin]: ' . __FILE__ . ':197</debug>',
'<debug>[db origin]: ' . __FILE__ . ':199</debug>',
))
->shouldBeCalled();
$this->statementProfiler->setIO($io->reveal());
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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());
}

}

0 comments on commit bcaf1bd

Please sign in to comment.