/** * @test */ public function itShouldBeAbleToWriteCommentInQuery() { $valueArray = array('user_id' => 1, 'name' => 'Nil', 'contact' => '*****@*****.**'); $this->query->setTable('user')->setComment('This is a comment')->setValues($valueArray); $expected = "-- This is a comment\n" . 'REPLACE INTO user (user.user_id, user.name, user.contact) VALUES (:v1, :v2, :v3)'; $this->assertSame($expected, $this->writer->write($this->query)); $this->assertEquals(\array_values($valueArray), \array_values($this->query->getValues())); $expected = array(':v1' => 1, ':v2' => 'Nil', ':v3' => '*****@*****.**'); $this->assertEquals($expected, $this->writer->getValues()); }
/** * @param Insert $insert * * @throws QueryException * * @return string */ public function write(Insert $insert) { $columns = $insert->getColumns(); if (empty($columns)) { throw new QueryException('No columns were defined for the current schema.'); } $columns = $this->writeQueryColumns($columns); $values = $this->writeQueryValues($insert->getValues()); $table = $this->writer->writeTable($insert->getTable()); $comment = AbstractBaseWriter::writeQueryComment($insert); return $comment . "INSERT INTO {$table} ({$columns}) VALUES ({$values})"; }
/** * @test */ public function itShouldSetValues() { $values = ['user_id' => 1, 'username' => 'nilportugues']; $this->query->setValues($values); $this->assertSame($values, $this->query->getValues()); }