Ejemplo n.º 1
0
 /**
  * @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));
 }
Ejemplo n.º 2
0
 /**
  * @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);
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
 /**
  * @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;
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 /**
  * @covers PDOK\Connector::inTransaction
  */
 public function testInTransactionReturnsFalseWhenDisconnected()
 {
     $conn = new \PDOK\Connector('sqlite::memory:');
     $this->assertFalse($conn->inTransaction());
 }
Ejemplo n.º 7
0
 /**
  * @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);
 }
Ejemplo n.º 8
0
 function __destruct()
 {
     --static::$ref;
     parent::__destruct();
 }
Ejemplo n.º 9
0
 /**
  * @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);
 }