/** * @covers PDOK\Connector::setAttribute */ public function testConnectedSetAttribute() { $c = new Connector('sqlite::memory:'); $c->connect(); $this->assertEquals(0, $c->getAttribute(\PDO::ATTR_CASE)); $c->setAttribute(\PDO::ATTR_CASE, \PDO::CASE_UPPER); $this->assertEquals(\PDO::CASE_UPPER, $c->getAttribute(\PDO::ATTR_CASE)); }
/** * @covers PDOK\Connector::query() * @covers PDOK\Connector::prepare() */ function testCustomStatementReturn() { $statementClass = __NAMESPACE__ . '\\ConnectorStatementTestStatement'; $connector = new \PDOK\Connector('sqlite::memory:'); $connector->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array($statementClass)); $connector->exec("CREATE TABLE foo(id INTEGER);"); $stmt = $connector->prepare('SELECT * FROM foo'); $this->assertInstanceOf('PDOK\\StatementWrapper', $stmt); $this->assertInstanceOf($statementClass, $stmt->statement); $stmt = $connector->query('SELECT * FROM foo'); $this->assertInstanceOf('PDOK\\StatementWrapper', $stmt); $this->assertInstanceOf($statementClass, $stmt->statement); }
public function testAttributesSurviveDisconnection() { $expected = \PDO::CASE_UPPER; $conn = new \PDOK\Connector('sqlite::memory:'); $conn->setAttribute(\PDO::ATTR_CASE, $expected); $this->assertEquals($expected, $conn->getAttribute(\PDO::ATTR_CASE)); $conn->connect(); $this->assertEquals($expected, $conn->getAttribute(\PDO::ATTR_CASE)); $conn->disconnect(); $this->assertEquals($expected, $conn->getAttribute(\PDO::ATTR_CASE)); $conn->connect(); $this->assertEquals($expected, $conn->getAttribute(\PDO::ATTR_CASE)); }
/** * @param PDOK\Connector|array Database connector * @param Amiss\Mapper */ public function __construct($connector, $mapper) { if (!$connector instanceof Connector) { $connector = Connector::create($connector); } $this->connector = $connector; $this->mapper = $mapper; }
public function getConnector() { $connection = $this->info; $connector = \PDOK\Connector::create($connection); $hash = spl_object_hash($connector); if (isset($this->connections[$hash])) { throw new \UnexpectedValueException(); } $this->connections[$hash] = $connector; return $connector; }
/** * @covers PDOK\Connector::inTransaction */ public function testInTransactionReturnsFalseWhenDisconnected() { $conn = new \PDOK\Connector('sqlite::memory:'); $this->assertFalse($conn->inTransaction()); }
/** * @covers PDOK\Connector::createPDO */ public function testCreatePDOConnectionStatements() { $conn = \PDOK\Connector::create(array('dsn' => 'sqlite::memory:', 'connectionStatements' => array('CREATE TABLE foo(id INT);', 'INSERT INTO foo VALUES(1);', 'INSERT INTO foo VALUES(2);'))); $rows = $conn->query("SELECT * FROM foo")->fetchAll(\PDO::FETCH_COLUMN, 0); $this->assertEquals(array(1, 2), $rows); }
function __destruct() { --static::$ref; parent::__destruct(); }
/** * @covers PDOK\Connector::create */ public function testCreateDsnOverridesHost() { $value = 'mysql:host=localhost;dbname=foobar'; $conn = \PDOK\Connector::create(array('dsn' => $value, 'host' => 'whoopee')); $this->assertEquals($value, $conn->dsn); }