Beispiel #1
0
 public function testCreateStatement()
 {
     $driver = new Sqlsrv(array());
     $resource = sqlsrv_connect($this->variables['hostname'], array('UID' => $this->variables['username'], 'PWD' => $this->variables['password']));
     $driver->getConnection()->setResource($resource);
     $stmt = $driver->createStatement('SELECT 1');
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Statement', $stmt);
     $stmt = $driver->createStatement($resource);
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Statement', $stmt);
     $this->setExpectedException('Zend\\Db\\Adapter\\Exception\\InvalidArgumentException', 'only accepts an SQL string or a Sqlsrv resource');
     $driver->createStatement(new \stdClass());
 }
Beispiel #2
0
 /**
  * @param \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv|\Zend\Db\Adapter\Driver\Pdo\Pdo||resource|\PDO $driver
  * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
  * @return $this
  */
 public function setDriver($driver)
 {
     // handle Zend_Db drivers
     if ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Sqlsrv') {
         /** @var $driver \Zend\Db\Adapter\Driver\DriverInterface */
         $this->resource = $driver->getConnection()->getResource();
         return $this;
     }
     // handle
     if ($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'sqlsrv') {
         $this->resource = $driver;
         return $this;
     }
     throw new Exception\InvalidArgumentException('$driver must be a Sqlsrv PDO Zend\\Db\\Adapter\\Driver or Sqlsrv PDO instance');
 }
 /**
  * @covers Zend\Db\Adapter\Driver\Sqlsrv\Connection::prepare
  */
 public function testPrepare()
 {
     $sqlsrv = new Sqlsrv($this->variables);
     $connection = $sqlsrv->getConnection();
     $statement = $connection->prepare('SELECT \'foo\'');
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Statement', $statement);
 }
Beispiel #4
0
 /**
  * @depends testRegisterConnection
  * @covers Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getConnection
  */
 public function testGetConnection($mockConnection)
 {
     $conn = new \Zend\Db\Adapter\Driver\Sqlsrv\Connection(array());
     $this->sqlsrv->registerConnection($conn);
     $this->assertSame($conn, $this->sqlsrv->getConnection());
 }