Skip to content
Permalink
Browse files

Update usage of Query() class and fix insertion errors.

Fix errors inserting records (there are still remaining issues with
SQLite).
  • Loading branch information...
markstory committed May 26, 2013
1 parent 69f35d1 commit 9d985a8d42483ab7ee28272cd64576426e77856a
Showing with 33 additions and 14 deletions.
  1. +26 −10 lib/Cake/Test/TestCase/TestSuite/TestFixtureTest.php
  2. +7 −4 lib/Cake/TestSuite/Fixture/TestFixture.php
@@ -386,13 +386,21 @@ public function testInsert() {
->with('articles', ['name', 'created'], ['string', 'datetime'])
->will($this->returnSelf());
$expected = [
['Gandalf', '2009-04-28 19:20:00'],
['Captain Picard', '2009-04-28 19:20:00'],
['Chewbacca', '2009-04-28 19:20:00']
['name' => 'Gandalf', 'created' => '2009-04-28 19:20:00'],
['name' => 'Captain Picard', 'created' => '2009-04-28 19:20:00'],
['name' => 'Chewbacca', 'created' => '2009-04-28 19:20:00']
];
$query->expects($this->once())
$query->expects($this->at(1))
->method('values')
->with($expected[0])
->will($this->returnSelf());
$query->expects($this->at(2))
->method('values')
->with($expected[1])
->will($this->returnSelf());
$query->expects($this->at(3))
->method('values')
->with($expected)
->with($expected[2])
->will($this->returnSelf());
$query->expects($this->once())
@@ -422,13 +430,21 @@ public function testInsertStrings() {
->will($this->returnSelf());
$expected = [
['Mark Doe', 'mark.doe@email.com', null],
['John Doe', 'john.doe@email.com', 20],
['Jane Doe', 'jane.doe@email.com', 30],
['name' => 'Mark Doe', 'email' => 'mark.doe@email.com', 'age' => null],
['name' => 'John Doe', 'email' => 'john.doe@email.com', 'age' => 20],
['name' => 'Jane Doe', 'email' => 'jane.doe@email.com', 'age' => 30],
];
$query->expects($this->once())
$query->expects($this->at(1))
->method('values')
->with($expected[0])
->will($this->returnSelf());
$query->expects($this->at(2))
->method('values')
->with($expected[1])
->will($this->returnSelf());
$query->expects($this->at(3))
->method('values')
->with($expected)
->with($expected[2])
->will($this->returnSelf());
$query->expects($this->once())
@@ -156,6 +156,7 @@ protected function _schemaFromFields() {
if ($field === 'constraints' || $field === 'indexes') {
continue;
}
// TODO issue E_USER_NOTICE if a column defines 'key'
$this->_schema->addColumn($field, $data);
}
if (!empty($this->fields['constraints'])) {
@@ -256,7 +257,6 @@ public function drop(Connection $db) {
}
$this->created = array_diff($this->created, [$db->configKeyName]);
} catch (\Exception $e) {
var_dump($e);
return false;
}
return true;
@@ -273,8 +273,11 @@ public function insert(Connection $db) {
if (isset($this->records) && !empty($this->records)) {
list($fields, $values, $types) = $this->_getRecords();
$query = $db->newQuery()
->insert($this->table, $fields, $types)
->values($values);
->insert($this->table, $fields, $types);
foreach ($values as $row) {
$query->values($row);
}
$result = $query->execute();
@@ -306,7 +309,7 @@ protected function _getRecords() {
}
$default = array_fill_keys($fields, null);
foreach ($this->records as $record) {
$values[] = array_values(array_merge($default, $record));
$values[] = array_merge($default, $record);
}
return [$fields, $values, $types];
}

0 comments on commit 9d985a8

Please sign in to comment.
You can’t perform that action at this time.