Exemplo n.º 1
0
 public function testUpdate()
 {
     $db = $this->getDb();
     $table = new SqlTable($db, 'Foo');
     $selection = new UpdateSelectionBuilder($table);
     $selection = $selection->set('a', 'foo');
     // Update all
     $db->expects($this->exactly(3))->method('execute')->withConsecutive([$this->equalTo('UPDATE {Foo} SET a = "foo", b = "baz", c = a + b')], [$this->equalTo('UPDATE {Foo} SET a = "foo" WHERE group = "user" ORDER BY name DESC')], [$this->equalTo('UPDATE {Foo} SET a = "foo" LIMIT 10')])->willReturn(0);
     $selection->set('b', 'baz')->set('c', E::e('a + b'))->update();
     // Update with predicate and ordering
     $selection->where('group = "user"')->orderByDescending('name')->update();
     // Update with limit
     $selection->limit(10)->update();
 }
Exemplo n.º 2
0
 public function testUpdate()
 {
     $data = [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar'], ['id' => 3, 'name' => 'foobar']];
     // Update all
     $source = new ArrayDataSource($data);
     $selection = new UpdateSelectionBuilder($source);
     $selection->set('name', 'baz')->update();
     foreach ($source->getData() as $record) {
         $this->assertEquals('baz', $record['name']);
     }
     // Update using expression
     $selection = new UpdateSelectionBuilder($source);
     $selection->set('name', E::e('id'))->update();
     foreach ($source->getData() as $record) {
         $this->assertEquals($record['id'], $record['name']);
     }
 }