Exemplo n.º 1
0
 /**
  * @covers Veles\DataBase\Adapters\PdoAdapter::escape
  *
  * @expectedException \Veles\DataBase\Exceptions\DbException
  */
 public function testEscapeException()
 {
     $exception_msg = 'SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer';
     $resource = $this->getMockBuilder('\\PDO')->disableOriginalConstructor()->setMethods(['quote'])->getMock();
     $resource->expects($this->once())->method('quote')->will($this->throwException(new \PDOException($exception_msg)));
     $conn = $this->getMockBuilder('\\Veles\\DataBase\\Connections\\PdoConnection')->setConstructorArgs(['master'])->setMethods(['getResource'])->getMock();
     $conn->expects($this->once())->method('getResource')->willReturn($resource);
     $pool = $this->getMockBuilder('\\Veles\\DataBase\\ConnectionPools\\ConnectionPool')->setMethods(['getConnection'])->getMock();
     $pool->expects($this->once())->method('getConnection')->willReturn($conn);
     $this->object->setPool($pool);
     $this->object->escape('string');
 }
Exemplo n.º 2
0
    public function run()
    {
        $this->prepareTables();
        $repeats = $this->getRepeats();
        $value1 = 'string one';
        $value2 = 'string two';
        $value3 = 'string three';
        $bar = new CliProgressBar($repeats);
        for ($i = 1; $i <= $repeats; ++$i) {
            Timer::start();
            $sql = '
				INSERT INTO test (txt) VALUES
					(?),
					(?),
					(?)
			';
            Db::query($sql, [$value1, $value2, $value3]);
            Timer::stop();
            $bar->update($i);
        }
        $this->addResult('Real', Timer::get());
        PdoAdapter::instance()->getConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
        Timer::reset();
        $bar = new CliProgressBar($repeats);
        for ($i = 1; $i <= $repeats; ++$i) {
            Timer::start();
            $sql = '
				INSERT INTO test (txt) VALUES
					(?),
					(?),
					(?)
			';
            Db::query($sql, [$value1, $value2, $value3]);
            Timer::stop();
            $bar->update($i);
        }
        $this->addResult('Emulated', Timer::get());
        $this->cleanup();
    }