From 9d985a8d42483ab7ee28272cd64576426e77856a Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 25 May 2013 23:16:55 -0400 Subject: [PATCH] Update usage of Query() class and fix insertion errors. Fix errors inserting records (there are still remaining issues with SQLite). --- .../TestCase/TestSuite/TestFixtureTest.php | 36 +++++++++++++------ lib/Cake/TestSuite/Fixture/TestFixture.php | 11 +++--- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lib/Cake/Test/TestCase/TestSuite/TestFixtureTest.php b/lib/Cake/Test/TestCase/TestSuite/TestFixtureTest.php index f8977c71afc..7bfd191015b 100644 --- a/lib/Cake/Test/TestCase/TestSuite/TestFixtureTest.php +++ b/lib/Cake/Test/TestCase/TestSuite/TestFixtureTest.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()) diff --git a/lib/Cake/TestSuite/Fixture/TestFixture.php b/lib/Cake/TestSuite/Fixture/TestFixture.php index 4f58a1e7f25..18f26b9504b 100644 --- a/lib/Cake/TestSuite/Fixture/TestFixture.php +++ b/lib/Cake/TestSuite/Fixture/TestFixture.php @@ -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]; }