Beispiel #1
0
 public function testPivotDoNotSortColumnsByColumnHeader()
 {
     // the results are odered by date
     $result = new Result();
     $rows = array(array('company' => 'Foo', 'date' => '30-03-2014', 'amount' => 2), array('company' => 'Bar', 'date' => '30-03-2014', 'amount' => 4), array('company' => 'Qux', 'date' => '30-03-2014', 'amount' => 8), array('company' => 'Foo', 'date' => '06-04-2014', 'amount' => 3), array('company' => 'Bar', 'date' => '06-04-2014', 'amount' => 9), array('company' => 'Qux', 'date' => '06-04-2014', 'amount' => 27), array('company' => 'Foo', 'date' => '13-04-2014', 'amount' => 5), array('company' => 'Bar', 'date' => '13-04-2014', 'amount' => 25), array('company' => 'Qux', 'date' => '13-04-2014', 'amount' => 125));
     foreach ($rows as $row) {
         $result->push(new Row($row));
     }
     $colHeadersField = 'date';
     $rowHeaders = 'company';
     $dataField = 'amount';
     $showTotal = false;
     $pivoter = new Pivoter($result);
     $pivoter->setSortByFirstColumn(false);
     // This would sort Bar, Foo, Qux
     $pivoter->setSortByColumnHeader(false);
     $actual = $pivoter->toPivot($colHeadersField, $rowHeaders, $dataField, $showTotal);
     $expected = array(array('company' => 'Foo', '30-03-2014' => 2, '06-04-2014' => 3, '13-04-2014' => 5), array('company' => 'Bar', '30-03-2014' => 4, '06-04-2014' => 9, '13-04-2014' => 25), array('company' => 'Qux', '30-03-2014' => 8, '06-04-2014' => 27, '13-04-2014' => 125));
     // order of the keys is important!
     // (assertEquals will pass even if they're in the wrong order)
     $this->assertTrue($expected === $actual);
 }
Beispiel #2
0
 protected function setNumRows()
 {
     // oci_num_rows will return the number of fetched rows so far for a SELECT statement
     // for all other query types this is fine
     // If the user has fetched records in a while loop, the num rows will be the amount of rows fetched so far.
     // When the user hasn't fetched anything yet, we will fetch the complete result and return the count.
     $this->numRows = oci_num_rows($this->statement->getResource());
     if ($this->statement->getStatementType() == 'SELECT' && empty($this->numRows)) {
         $this->fetchAll();
         // unlike fetchResult, this will only fetch the result when result is empty
         $this->numRows = $this->result->count();
     }
 }
Beispiel #3
0
 public function testRowAccess()
 {
     $row = $this->resultset->shift();
     $this->assertEquals('bar', $row->two);
 }