public function testFailedAttemptThenSucceeds() { $this->factory->expects($this->any())->method('create')->will($this->returnValue($this->pdo)); $pdoStatement = $this->getMock(\PDOStatement::class); $pdoStatement->expects($this->any())->method('execute')->will($this->onConsecutiveCalls($this->throwException(new \PDOException()), $this->returnValue(true))); $this->pdo->expects($this->any())->method('prepare')->will($this->returnValue($pdoStatement)); $this->config->expects($this->any())->method('getMaximumAttempts')->will($this->returnValue(2)); $this->assertSame($this->pdo, $this->factory->__invoke($this->config)); }
/** * Set the timezone on the connection. * * @param string $timezone * @return Adapter */ public function setTimezone($timezone) { if ($this->config->getTimezone() !== $timezone) { $this->config->setTimezone($timezone); if ($this->connection) { $this->query('SET time_zone = ?', array($timezone)); } } return $this; }
/** * @expectedException \Phlib\Db\Exception\InvalidArgumentException */ public function testGetDsnWithoutHost() { $config = new Config([]); $config->getDsn(); }
/** * @param Config $config * @return \PDO */ public function create(Config $config) { return new \PDO($config->getDsn(), $config->getUsername(), $config->getPassword(), $config->getOptions()); }