/** * Prepares an Entity for use in the application. * * @param \Rawebone\Ormish\Entity $entity * @param \Rawebone\Ormish\GatewayInterface $gateway * @param \Rawebone\Ormish\Database $db * @param boolean $readOnly */ public function prepare(Entity $entity, GatewayInterface $gateway, Database $db, $readOnly) { $shadow = (bool) $readOnly ? new NullShadow() : new Shadow(); $shadow->update($entity->all()); $entity->letDatabase($db); $entity->letShadow($shadow); $entity->letGateway($gateway); }
function it_should_prepare_an_entity_with_a_real_shadow(Entity $ent, GatewayInterface $gate, Database $db) { $readOnly = false; $ent->all()->willReturn(array())->shouldBeCalled(); $ent->letDatabase($db)->shouldBeCalled(); $ent->letGateway($gate)->shouldBeCalled(); $ent->letShadow(Argument::type('Rawebone\\Ormish\\Utilities\\Shadow'))->shouldBeCalled(); $this->prepare($ent, $gate, $db, $readOnly); }
/** * @param \Rawebone\Ormish\Entity $ent * @param \Rawebone\Ormish\Table $tbl * @param \Rawebone\Ormish\SqlGeneratorInterface $gen * @param \Rawebone\Ormish\Executor $ex */ function it_should_try_to_insert_and_fail($ent, $tbl, $gen, $ex) { $tbl->readOnly()->willReturn(false); $tbl->id()->willReturn("id"); $tbl->table()->willReturn("table"); $ent->id = null; $ent->all()->willReturn(array()); $gen->insert("table", array())->willReturn(array("query", array())); $ex->exec("query", array())->willThrow(new ExecutionException("", "", "", array())); $this->run($ent)->shouldReturn(false); }
protected function tryInsert($id, Entity $entity) { list($query, $params) = $this->generator->insert($this->table->table(), $entity->all()); $this->executor->exec($query, $params); $entity->{$id} = (int) $this->executor->lastInsertId(); }