Beispiel #1
0
 public function test_should_lock_optimistically()
 {
     $Account1 = new BankAccount(array('balance' => 2000));
     $this->assertEqual($Account1->lock_version, 1, 'Version attribute initially starts at 1.');
     $Account1->save();
     $this->assertEqual($Account1->lock_version, 1, 'We are now on Version 1.');
     $Account2 = new BankAccount($Account1->getId());
     $this->assertEqual($Account2->lock_version, 1, 'We reloaded Version 1.');
     $Account1->balance = 5;
     $Account1->save();
     $this->assertEqual($Account1->lock_version, 2, 'We are now on Version 2.');
     $Account2->balance = 3000000;
     $this->assertUpcomingError('Attempted to update a stale object');
     $this->assertFalse($Account2->save(), 'We cant save because version number is wrong.');
     $Account1->balance = 1000;
     $this->assertTrue($Account1->save());
     $Account3 = new BankAccount($Account1->getId());
     $this->assertEqual($Account3->balance, 1000);
     $this->assertEqual($Account3->lock_version, 3, 'We are now on Version 3.');
 }