Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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);
 }