Skip to content

Commit

Permalink
hand-merge the 'profile perform()' changes from tzappa; refs #85, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Jan 19, 2015
2 parents 60c824f + 7cf2af9 commit 2592555
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/ExtendedPdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,10 @@ public function perform($statement, array $values = array())
public function prepare($statement, $options = array())
{
$this->connect();
return $this->pdo->prepare($statement, $options);
$this->beginProfile(__FUNCTION__);
$sth = $this->pdo->prepare($statement, $options);
$this->endProfile($statement, $options);
return $sth;
}

/**
Expand Down
22 changes: 17 additions & 5 deletions tests/unit/src/ProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testGetPdo()
$lazy_pdo = $this->pdo->getPdo();
$this->assertInstanceOf('PDO', $lazy_pdo);
}

public function testProfiling()
{
$this->pdo->setProfiler(new Profiler);
Expand All @@ -35,7 +35,8 @@ public function testProfiling()
$this->pdo->fetchAll("SELECT 3 FROM pdotest", array('zim' => 'gir'));

$profiles = $this->pdo->getProfiler()->getProfiles();
$this->assertEquals(3, count($profiles));
// 1 x query(), 1 x exec(), and 2 x fetchAll() which is executed as prepare() and perform()
$this->assertEquals(4, count($profiles));

// get the profiles, remove stuff that's variable
$actual = $this->pdo->getProfiler()->getProfiles();
Expand All @@ -56,6 +57,11 @@ public function testProfiling()
'bind_values' => array(),
),
2 => array(
'function' => 'prepare',
'statement' => 'SELECT 3 FROM pdotest',
'bind_values' => array(),
),
3 => array(
'function' => 'perform',
'statement' => 'SELECT 3 FROM pdotest',
'bind_values' => array(
Expand All @@ -79,7 +85,7 @@ public function testResetProfiles()
// activate
$this->pdo->getProfiler()->setActive(true);

$this->pdo->query("SELECT 1 FROM pdotest");
$this->pdo->query("SELECT 1 FROM pdotest");

$profiles = $this->pdo->getProfiler()->getProfiles();
$this->assertEquals(1, count($profiles));
Expand Down Expand Up @@ -108,7 +114,8 @@ public function testResetProfiles()
$this->pdo->fetchAll("SELECT 3 FROM pdotest", array('zim' => 'gir'));

$profiles = $this->pdo->getProfiler()->getProfiles();
$this->assertEquals(2, count($profiles));
// fetchAll() is executed as prepare() and perform()
$this->assertEquals(3, count($profiles));

// get the profiles, remove stuff that's variable
$actual = $this->pdo->getProfiler()->getProfiles();
Expand All @@ -117,13 +124,18 @@ public function testResetProfiles()
unset($actual[$key]['trace']);
}

$expect = array(
$expect = array(
0 => array(
'function' => 'exec',
'statement' => 'SELECT 2 FROM pdotest',
'bind_values' => array(),
),
1 => array(
'function' => 'prepare',
'statement' => 'SELECT 3 FROM pdotest',
'bind_values' => array(),
),
2 => array(
'function' => 'perform',
'statement' => 'SELECT 3 FROM pdotest',
'bind_values' => array(
Expand Down

0 comments on commit 2592555

Please sign in to comment.