increment() public method

Defaults to 1 if no value is specified. Throws an exception if the specified field is non-numeric.
public increment ( string $field, integer | string $value = 1 ) : integer
$field string The name of the field to be incremented.
$value integer | string The value to increment the field by. Defaults to `1` if this parameter is not specified.
return integer Returns the current value of `$field`, based on the value retrieved from the data source when the entity was loaded, plus any increments applied. Note that it may not reflect the most current value in the persistent backend data source.
Beispiel #1
0
 public function testIncrement()
 {
     $entity = new Entity(array('data' => array('counter' => 0)));
     $this->assertEqual(0, $entity->counter);
     $entity->increment('counter');
     $this->assertEqual(1, $entity->counter);
     $entity->decrement('counter', 5);
     $this->assertEqual(-4, $entity->counter);
     $this->assertNull($entity->increment);
     $entity->increment('foo');
     $this->assertEqual(1, $entity->foo);
     $this->assertFalse(isset($entity->bar));
     $entity->bar = 'blah';
     $entity->sync();
     $this->expectException("/^Field 'bar' cannot be incremented.\$/");
     $entity->increment('bar');
 }