Skip to content

Commit

Permalink
Adds LoggingPdo helper, adds test for pulling internal logger
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobemerick committed Dec 18, 2015
1 parent 0d805c2 commit d019cbb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/PhpQuickProfiler.php
Expand Up @@ -17,7 +17,7 @@
class PhpQuickProfiler
{

/** @var integer */
/** @var double */
protected $startTime;

/** @var Console */
Expand Down
3 changes: 2 additions & 1 deletion tests/bootstrap.php
@@ -1,4 +1,5 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/function-overrides.php';
require_once __DIR__ . '/helpers/function-overrides.php';
require_once __DIR__ . '/helpers/LoggingPdo.php';
10 changes: 10 additions & 0 deletions tests/helpers/LoggingPdo.php
@@ -0,0 +1,10 @@
<?php

namespace Particletree\Pqp;

use PDO;

class LoggingPdo extends PDO
{
public $queries = array();
}
File renamed without changes.
14 changes: 12 additions & 2 deletions tests/unit/PhpQuickProfilerTest.php
Expand Up @@ -2,7 +2,6 @@

namespace Particletree\Pqp;

use PDO;
use PHPUnit_Framework_Testcase;
use ReflectionClass;
use ReflectionMethod;
Expand All @@ -14,7 +13,7 @@ class PhpQuickProfilerTest extends PHPUnit_Framework_TestCase

public static function setUpBeforeClass()
{
self::$dbConnection = new PDO('sqlite::memory:');
self::$dbConnection = new LoggingPdo('sqlite::memory:');
$createTable = "
CREATE TABLE IF NOT EXISTS `testing` (
`id` integer PRIMARY KEY AUTOINCREMENT,
Expand Down Expand Up @@ -131,6 +130,17 @@ public function testGatherQueryData()
}
}

public function testGatherQueryDataInternalProfiler()
{
$profiledQueries = $this->dataProfiledQueries();
$dbConnection = self::$dbConnection;
$dbConnection->queries = $profiledQueries;
$profiler = new PhpQuickProfiler();
$profiler->gatherQueryData($dbConnection);

$this->assertAttributeSame($profiledQueries, 'profiledQueries', $profiler);
}

/**
* @dataProvider dataProfiledQueries
*/
Expand Down

0 comments on commit d019cbb

Please sign in to comment.