Exemplo n.º 1
0
    /**
     * INSERT文を実行する
     * @return string INSERT したテーブルの id を返す
     */
    public function insert()
    {
        $keys = array_pluck($this->values, 'key');
        $bindings = array_pluck($this->values, 'value');
        $values_count = count($this->values);
        $keys_str = implode(', ', $keys);
        $placeholder = array();
        foreach (range(1, $values_count) as $i) {
            $placeholder[] = '?';
        }
        $placeholder_str = implode(', ', $placeholder);
        $format = <<<SQL
INSERT INTO {$this->table} (%s) VALUES (%s)
SQL;
        $query = sprintf($format, $keys_str, $placeholder_str);
        $this->reset();
        $this->logs[] = array('query' => $query, 'bindings' => $bindings);
        return $this->DB->insert($query, $bindings);
    }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function insert()
 {
     $pdoStatementMock = m::mock('PDOStatement');
     $pdoStatementMock->shouldReceive('execute');
     $pdoMock = m::mock('PDO');
     $pdoMock->shouldReceive('prepare')->andReturn($pdoStatementMock);
     $pdoMock->shouldReceive('lastInsertId')->andReturn(10);
     $connectorInterfaceMock = m::mock('Poulsen\\Connectors\\ConnectorInterface');
     $connectorInterfaceMock->shouldReceive('connect')->andReturn($pdoMock);
     $factoryMock = m::mock('Poulsen\\Connectors\\ConnectorFactory');
     $factoryMock->shouldReceive('make')->andReturn($connectorInterfaceMock);
     $Manager = new Manager($factoryMock);
     $actual = $Manager->insert('', array());
     $this->assertSame(10, $actual);
 }