Skip to content

Commit

Permalink
add method getPdo() to get the underlying/decorated instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Mar 27, 2014
1 parent 5e3ae7b commit a8c1d32
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/ExtendedPdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,19 @@ public function getDsn()
return $this->dsn;
}

/**
*
* Returns the underlying PDO connection object.
*
* @return PDO
*
*/
public function getPdo()
{
$this->connect();
return $this->pdo;
}

/**
*
* Returns the profiler object.
Expand Down
9 changes: 9 additions & 0 deletions src/ExtendedPdoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ public function fetchValue($statement, array $values = array());
*/
public function getDsn();

/**
*
* Returns the underlying PDO connection object.
*
* @return PDO
*
*/
public function getPdo();

/**
*
* Returns the profiler object.
Expand Down
2 changes: 2 additions & 0 deletions tests/src/AbstractExtendedPdoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ protected function insert(array $data)
$this->pdo->perform($stm, $data);
}

abstract public function testGetPdo();

public function testErrorCodeAndInfo()
{
$actual = $this->pdo->errorCode();
Expand Down
11 changes: 9 additions & 2 deletions tests/src/DecoratedPdoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@

class DecoratedPdoTest extends AbstractExtendedPdoTest
{
protected $decorated_pdo;

protected function newExtendedPdo()
{
$pdo = new PDO('sqlite::memory:');
return new ExtendedPdo($pdo);
$this->decorated_pdo = new PDO('sqlite::memory:');
return new ExtendedPdo($this->decorated_pdo);
}

public function testGetPdo()
{
$this->assertSame($this->decorated_pdo, $this->pdo->getPdo());
}
}
7 changes: 7 additions & 0 deletions tests/src/ExtendedPdoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ protected function newExtendedPdo()
$attributes
);
}

public function testGetPdo()
{
$lazy_pdo = $this->pdo->getPdo();
$this->assertInstanceOf('PDO', $lazy_pdo);
$this->assertNotSame($this->pdo, $lazy_pdo);
}
}

0 comments on commit a8c1d32

Please sign in to comment.