コード例 #1
0
 /**
  * Test if NULL value is not cast to other native types.
  */
 public function testNullRemainsNull()
 {
     $caster = new ValueCaster();
     $this->assertEquals(ValueCaster::CAST_INT, $caster->getTypeByFieldName('project_leader_id'));
     $row = ['project_leader_id' => null];
     $caster->castRowValues($row);
     $this->assertArrayHasKey('project_leader_id', $row);
     $this->assertNull($row['project_leader_id']);
 }
コード例 #2
0
 /**
  * Test execute.
  */
 public function testExecuteWithCustomCaster()
 {
     $result = $this->connection->execute('SELECT * FROM `writers` ORDER BY `id`');
     $this->assertInstanceOf('\\ActiveCollab\\DatabaseConnection\\Result\\Result', $result);
     $this->assertCount(3, $result);
     $caster = new ValueCaster(['id' => ValueCaster::CAST_STRING, 'birthday' => ValueCaster::CAST_DATE]);
     $this->assertEquals(ValueCaster::CAST_STRING, $caster->getTypeByFieldName('id'));
     $this->assertEquals(ValueCaster::CAST_DATE, $caster->getTypeByFieldName('birthday'));
     $result->setValueCaster($caster);
     $writers = [];
     foreach ($result as $row) {
         $writers[] = $row;
     }
     $this->assertCount(3, $writers);
     $this->assertSame('1', $writers[0]['id']);
     $this->assertSame('Leo Tolstoy', $writers[0]['name']);
     $this->assertSame('1828-09-09', $writers[0]['birthday']->format('Y-m-d'));
     $this->assertSame('2', $writers[1]['id']);
     $this->assertSame('Alexander Pushkin', $writers[1]['name']);
     $this->assertSame('1799-06-06', $writers[1]['birthday']->format('Y-m-d'));
     $this->assertSame('3', $writers[2]['id']);
     $this->assertSame('Fyodor Dostoyevsky', $writers[2]['name']);
     $this->assertSame('1821-11-11', $writers[2]['birthday']->format('Y-m-d'));
 }