set() public method

Set field value.
public set ( string | array $field, mixed $value = null )
$field string | array
$value mixed
Ejemplo n.º 1
0
 public function testUpdateArray()
 {
     $a = ['user' => [1 => ['name' => 'John', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'Jones']]];
     $p = new Persistence_Array($a);
     $m = new Model($p, 'user');
     $m->addField('name');
     $m->addField('surname');
     $m->load(1);
     $m['name'] = 'Peter';
     $m->save();
     $m->load(2);
     $m['surname'] = 'Smith';
     $m->save();
     $m['surname'] = 'QQ';
     $m->save();
     $this->assertEquals(['user' => [1 => ['name' => 'Peter', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'QQ']]], $a);
     $m->unload();
     $m->set(['name' => 'Foo', 'surname' => 'Bar']);
     $m->save();
     $this->assertEquals(['user' => [1 => ['name' => 'Peter', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'QQ'], 3 => ['name' => 'Foo', 'surname' => 'Bar', 'id' => 3]]], $a);
 }
Ejemplo n.º 2
0
 /**
  * @expectedException Exception
  */
 public function testException3()
 {
     $m = new Model();
     $m->set(4, 5);
 }
Ejemplo n.º 3
0
 public function testEmptyValues()
 {
     $a = ['types' => [1 => $v = ['id' => 1, 'string' => '', 'notype' => '', 'date' => '', 'datetime' => '', 'time' => '', 'boolean' => '', 'integer' => '', 'money' => '', 'float' => '', 'array' => '', 'object' => '']]];
     $this->setDB($a);
     date_default_timezone_set('Asia/Seoul');
     $db = new Persistence_SQL($this->db->connection);
     $m = new Model($db, ['table' => 'types']);
     $m->addField('string', ['type' => 'string']);
     $m->addField('notype');
     $m->addField('date', ['type' => 'date']);
     $m->addField('datetime', ['type' => 'datetime']);
     $m->addField('time', ['type' => 'time']);
     $m->addField('boolean', ['type' => 'boolean']);
     $m->addField('integer', ['type' => 'integer']);
     $m->addField('money', ['type' => 'money']);
     $m->addField('float', ['type' => 'float']);
     $m->addField('array', ['type' => 'array']);
     $m->addField('object', ['type' => 'object']);
     $m->load(1);
     // Only
     $this->assertSame('', $m['string']);
     $this->assertSame('', $m['notype']);
     $this->assertSame(null, $m['date']);
     $this->assertSame(null, $m['datetime']);
     $this->assertSame(null, $m['time']);
     $this->assertSame(null, $m['boolean']);
     $this->assertSame(null, $m['integer']);
     $this->assertSame(null, $m['money']);
     $this->assertSame(null, $m['float']);
     $this->assertSame(null, $m['array']);
     $this->assertSame(null, $m['object']);
     unset($v['id']);
     $m->set($v);
     $this->assertSame('', $m['string']);
     $this->assertSame('', $m['notype']);
     $this->assertSame(null, $m['date']);
     $this->assertSame(null, $m['datetime']);
     $this->assertSame(null, $m['time']);
     $this->assertSame(null, $m['boolean']);
     $this->assertSame(null, $m['integer']);
     $this->assertSame(null, $m['money']);
     $this->assertSame(null, $m['float']);
     $this->assertSame(null, $m['array']);
     $this->assertSame(null, $m['object']);
     $this->assertEquals([], $m->dirty);
     $m->save();
     $this->assertEquals($a, $this->getDB());
     $m->duplicate()->save();
     $a['types'][2] = ['id' => 2, 'string' => '', 'notype' => '', 'date' => null, 'datetime' => null, 'time' => null, 'boolean' => null, 'integer' => null, 'money' => null, 'float' => null, 'array' => null, 'object' => null];
     $this->assertEquals($a, $this->getDB());
 }