Browse Source

Updated and fixed type-o in tests.

Eugene Ritter 8 years ago
parent
commit
a93b0ff5be

+ 0 - 6
src/Database/Statement/PDOStatement.php

@@ -96,9 +96,6 @@ class PDOStatement extends StatementDecorator
         if ($type === static::FETCH_TYPE_ASSOC) {
             return $this->_statement->fetch(PDO::FETCH_ASSOC);
         }
-        if ($type === static::FETCH_TYPE_OBJ) {
-            return $this->_statement->fetch(PDO::FETCH_OBJ);
-        }
 
         return $this->_statement->fetch($type);
     }
@@ -125,9 +122,6 @@ class PDOStatement extends StatementDecorator
         if ($type === static::FETCH_TYPE_ASSOC) {
             return $this->_statement->fetchAll(PDO::FETCH_ASSOC);
         }
-        if ($type === static::FETCH_TYPE_OBJ) {
-            return $this->_statement->fetchAll(PDO::FETCH_OBJ);
-        }
 
         return $this->_statement->fetchAll($type);
     }

+ 3 - 0
src/Database/Statement/StatementDecorator.php

@@ -210,6 +210,9 @@ class StatementDecorator implements StatementInterface, Countable, IteratorAggre
     }
 
     /**
+     * Returns the next row in a result set as an associative array. Calling this function is the same as calling
+     * $statement->fetch(StatementDecorator::FETCH_TYPE_ASSOC). If no results are found false is returned.
+     *
      * @return array|false Result array containing columns and values an an associative array or false if no results
      */
     public function fetchAssoc()

+ 24 - 1
tests/TestCase/Database/QueryTest.php

@@ -4724,6 +4724,29 @@ class QueryTest extends TestCase
     }
 
     /**
+     * Test that fetchColumn() will return false if $position is not set.
+     * @throws \Exception
+     * @return void
+     */
+    public function testFetchColumnReturnsFalse()
+    {
+        $this->loadFixtures('Profiles');
+        $query = new Query($this->connection);
+        $query
+            ->select([
+                'id',
+                'user_id',
+                'is_active'
+            ])
+            ->from('profiles')
+            ->where(['id' => 2])
+            ->limit(1);
+        $statement = $query->execute();
+        $results = $statement->fetchColumn(3);
+        $this->assertFalse($results);
+    }
+
+    /**
      * Test that calling fetchAssoc, fetchColum and fetchObject in sequence
      * alters the fetched data to the correct types and values.
      * @return void
@@ -4746,6 +4769,6 @@ class QueryTest extends TestCase
         $results = $statement->fetchAssoc();
         $this->assertSame('2', $results['id']);
         $results = $statement->fetchColumn(0);
-        $this->assertSame('3', $results[0]);
+        $this->assertSame('3', $results);
     }
 }