/** * @covers BindParamGenerator::update_set_values */ public function test_update_set_values() { $gen = new BindParamGenerator(); $gen->update_set_values(array('field1' => 'value1', 'field2' => 'value2', 'field3' => 'value3')); $param = $gen->generate(); $actual = $param->getPhraseStr(); $expected = "field1=:field1_0,field2=:field2_1,field3=:field3_2"; $this->assertEquals($expected, $actual); $actual = $param->getParamArray(); $expected = array('field1_0' => 'value1', 'field2_1' => 'value2', 'field3_2' => 'value3'); $this->assertEquals($expected, $actual); }
/** * @covers SQLAdapter::__construct * @covers SQLAdapter::select * @covers SQLAdapter::update */ public function test_update() { $config = new PDOConfig(array('database' => 'test', 'pass' => '')); $pdo = new PDOExtended($config); # # update # $adapter = new SQLAdapter($pdo); $generator = new BindParamGenerator(); $generator->update_set_values(array('FIELD1' => 'f4_1_update', 'FIELD2' => 'f4_2_update', 'FIELD3' => 'f4_3_update'))->equal_('ID', 4); $response = $adapter->update('TBL_TEST', $generator->generate()); $actual = $response->getErrorCode(); $expected = '00000'; $this->assertEquals($expected, $actual, __CLASS__ . "::" . __METHOD__ . ": line " . __LINE__); # # Select an updated data # $adapter = new SQLAdapter($pdo); $generator = new BindParamGenerator(); $generator->equal_('ID', 4); $response = $adapter->select('TBL_TEST', array('ID', 'FIELD1', 'FIELD3'), $generator->generate()); $actual = $response->fetchAll(); $expected = array(0 => array('ID' => '4', 'FIELD1' => 'f4_1_update', 'FIELD3' => 'f4_3_update')); $this->assertEquals($expected, $actual, __CLASS__ . "::" . __METHOD__ . ": line " . __LINE__); }