/**
  * Test replace mode.
  */
 public function testReplace()
 {
     $last_insert_id = $this->connection->insert('writers', ['id' => 1, 'name' => 'Anton Chekhov', 'birthday' => new DateTime('1860-01-29')], ConnectionInterface::REPLACE);
     $this->assertEquals(1, $last_insert_id);
     $this->assertEquals(3, $this->connection->executeFirstCell('SELECT COUNT(`id`) AS "row_count" FROM `writers`'));
     $this->assertEquals(['id' => 1, 'name' => 'Anton Chekhov', 'birthday' => '1860-01-29'], $this->connection->executeFirstRow('SELECT * FROM `writers` WHERE `id` = ?', $last_insert_id));
 }
 /**
  * Test if objects are properly created by value stored in a field.
  */
 public function testExecuteLoadObjectFromField()
 {
     // ---------------------------------------------------
     //  Add type field
     // ---------------------------------------------------
     $this->connection->execute('ALTER TABLE `writers` ADD `type` VARCHAR(255)  NULL DEFAULT ? AFTER `id`;', '\\ActiveCollab\\DatabaseConnection\\Test\\Fixture\\Writer');
     $this->assertEquals(['id' => 1, 'type' => '\\ActiveCollab\\DatabaseConnection\\Test\\Fixture\\Writer', 'name' => 'Leo Tolstoy', 'birthday' => '1828-09-09'], $this->connection->executeFirstRow('SELECT * FROM `writers` WHERE `id` = ?', 1));
     // ---------------------------------------------------
     //  Use type field to know which objects to create
     // ---------------------------------------------------
     $result = $this->connection->advancedExecute('SELECT * FROM `writers` ORDER BY `id`', null, ConnectionInterface::LOAD_ALL_ROWS, ConnectionInterface::RETURN_OBJECT_BY_FIELD, 'type');
     $this->assertInstanceOf('\\ActiveCollab\\DatabaseConnection\\Result\\Result', $result);
     $this->assertCount(3, $result);
     /** @var \ActiveCollab\DatabaseConnection\Test\Fixture\Writer[] $writers */
     $writers = [];
     foreach ($result as $row) {
         $writers[] = $row;
     }
     $this->assertCount(3, $writers);
     $this->assertInstanceOf('ActiveCollab\\DatabaseConnection\\Test\\Fixture\\Writer', $writers[0]);
     $this->assertEquals(1, $writers[0]->getId());
     $this->assertEquals('Leo Tolstoy', $writers[0]->getName());
     $this->assertEquals('1828-09-09', $writers[0]->getBirthday()->format('Y-m-d'));
     $this->assertInstanceOf('ActiveCollab\\DatabaseConnection\\Test\\Fixture\\Writer', $writers[1]);
     $this->assertEquals(2, $writers[1]->getId());
     $this->assertEquals('Alexander Pushkin', $writers[1]->getName());
     $this->assertEquals('1799-06-06', $writers[1]->getBirthday()->format('Y-m-d'));
     $this->assertInstanceOf('ActiveCollab\\DatabaseConnection\\Test\\Fixture\\Writer', $writers[2]);
     $this->assertEquals(3, $writers[2]->getId());
     $this->assertEquals('Fyodor Dostoyevsky', $writers[2]->getName());
     $this->assertEquals('1821-11-11', $writers[2]->getBirthday()->format('Y-m-d'));
 }
 /**
  * Test execute first row.
  */
 public function testExecuteFirstRow()
 {
     $this->assertEquals(['id' => 1, 'name' => 'Leo Tolstoy', 'birthday' => '1828-09-09'], $this->connection->executeFirstRow('SELECT * FROM `writers` ORDER BY `id`'));
 }