Example #1
0
 /**
  * Test if we can change ID to a new value that is not yet reserved.
  */
 public function testChangeIdToNewRecord()
 {
     $chekhov = new Writer($this->connection, $this->pool);
     $chekhov->setName('Anton Chekhov');
     $chekhov->setBirthday(new DateValue('1860-01-29'));
     $chekhov->save();
     $this->assertFalse($chekhov->isPrimaryKeyModified());
     $this->assertSame(4, $chekhov->getId());
     $this->assertEquals(1, $this->connection->executeFirstCell('SELECT COUNT(`id`) AS "row_count" FROM `writers` WHERE `id` = ?', 4));
     $this->assertEquals(0, $this->connection->executeFirstCell('SELECT COUNT(`id`) AS "row_count" FROM `writers` WHERE `id` = ?', 18));
     // Update primary key and save the object
     $chekhov->setId(18);
     $this->assertTrue($chekhov->isPrimaryKeyModified());
     $chekhov->save();
     $this->assertEquals(0, $this->connection->executeFirstCell('SELECT COUNT(`id`) AS "row_count" FROM `writers` WHERE `id` = ?', 4));
     $this->assertEquals(1, $this->connection->executeFirstCell('SELECT COUNT(`id`) AS "row_count" FROM `writers` WHERE `id` = ?', 18));
 }