Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Zend adapter now uses insert method to insert

  • Loading branch information...
commit 33618bf45509bc4d77a267f9e67dc1853178a439 1 parent d6e0b99
@MarcelloDuarte authored
View
14 lib/Phabric/Datasource/Zend.php
@@ -99,23 +99,21 @@ public function insert(Entity $entity, array $data)
{
$name = $entity->getName();
- if (!isset($this->tableMappings[$name])) {
+ if (!$this->verifyTableIsMapped($name)) {
throw new \RuntimeException("The table: $name has not been mapped.");
}
+
+ if (!$this->verifyDataContainsNameCol($name, $data)) {
+ throw new \RuntimeException('Table data does not have required name column');
+ }
$tableName = $this->tableMappings[$name]['tableName'];
$phName = $this->tableMappings[$name]['nameCol'];
-
- if (!is_null($phName) && !isset($data[$phName])) {
- throw new \RuntimeException("Table data does not have required name column [$phName]");
- }
$columns = implode('`,`', array_keys($data));
$values = implode("','", array_values($data));
- $this->connection->query(
- "INSERT INTO (`$columns`) `$name` VALUES ('$values')"
- );
+ $this->connection->insert($tableName, $data);
return $this->connection->lastInsertId();
}
View
21 tests/lib/Phabric/Datasource/ZendTest.php
@@ -120,19 +120,20 @@ public function testInsert()
{
$mEntity = m::mock('\Phabric\Entity');
- $mEntity->shouldReceive('getName')
- ->andReturn('event');
-
- $this->mockedConnection->shouldReceive('query');
- $this->mockedConnection->shouldReceive('lastInsertId')
- ->andReturn(12);
-
$values = array(
'name' => 'PHPNW',
'desc' => 'A Great Conf!',
'date' => '2011-10-08 12:00:00'
);
+ $mEntity->shouldReceive('getName')
+ ->andReturn('event');
+
+ $this->mockedConnection->shouldReceive('insert')
+ ->with('t_event', $values);
+ $this->mockedConnection->shouldReceive('lastInsertId')
+ ->andReturn(12);
+
// Set the table mapping
$this->object->addTableMapping('event', 't_event', 'id', 'name');
@@ -155,7 +156,8 @@ public function testInsertOnUnmappedTable()
'desc' => 'A Great Conf!',
'date' => '2011-10-08 12:00:00');
- $this->mockedConnection->shouldReceive('query');
+ $this->mockedConnection->shouldReceive('insert')
+ ->with('t_event', $values);
$this->mockedConnection->shouldReceive('lastInsertId')
->andReturn(12);
@@ -178,7 +180,8 @@ public function testInsertOnDataWithoutNameColumn()
'desc' => 'A Great Conf!',
'date' => '2011-10-08 12:00:00');
- $this->mockedConnection->shouldReceive('query');
+ $this->mockedConnection->shouldReceive('insert')
+ ->with('t_event', $values);
$this->mockedConnection->shouldReceive('lastInsertId')
->andReturn(12);
Please sign in to comment.
Something went wrong with that request. Please try again.