Permalink
Browse files

fix bug with boolean value because no return FALSE value

  • Loading branch information...
stood committed Jan 26, 2014
1 parent feb6604 commit 19ac478c920ff061504c1fd7738fd32c010d99b1
@@ -35,9 +35,7 @@ public function format(PDOStatement $stmt)
throw new PropelException('Cannot use limit() in conjunction with with() on a one-to-many relationship. Please remove the with() call, or the limit() call.');
}
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
- if (false !== $rowArray = $this->getStructuredArrayFromRow($row)) {
- $collection[] = $rowArray;
- }
+ $collection[] = $this->getStructuredArrayFromRow($row);
}
$stmt->closeCursor();
@@ -49,9 +47,7 @@ public function formatOne(PDOStatement $stmt)
$this->checkInit();
$result = null;
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
- if (false !== $rowArray = $this->getStructuredArrayFromRow($row)) {
- $result = $rowArray;
- }
+ $result = $this->getStructuredArrayFromRow($row);
}
$stmt->closeCursor();
@@ -29,7 +29,7 @@ public function testFormatWithOneRowAndValueIsNotZero()
$books = $formatter->format($stmt);
$this->assertInstanceOf('PropelCollection', $books);
$this->assertCount(4, $books);
- $this->assertSame('1', $books[0]);
+ $this->assertEquals('1', $books[0]);
}
public function testFormatWithOneRowAndValueEqualsZero()
@@ -43,30 +43,57 @@ public function testFormatWithOneRowAndValueEqualsZero()
$books = $formatter->format($stmt);
$this->assertInstanceOf('PropelCollection', $books);
$this->assertCount(4, $books);
- $this->assertSame('0', $books[0]);
+ $this->assertEquals('0', $books[0]);
}
public function testFormatOneWithOneRowAndValueIsNotZero()
{
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
- $stmt = $con->query('SELECT 1 FROM book LIMIT 0, 1');
+ $stmt = $con->query('SELECT 1 FROM book LIMIT 1 OFFSET 0');
$formatter = new PropelSimpleArrayFormatter();
$formatter->init(new ModelCriteria('bookstore', 'Book'));
$book = $formatter->formatOne($stmt);
- $this->assertSame('1', $book);
+ $this->assertEquals('1', $book);
}
public function testFormatOneWithOneRowAndValueEqualsZero()
{
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
- $stmt = $con->query('SELECT 0 FROM book LIMIT 0, 1');
+ $stmt = $con->query('SELECT 0 FROM book LIMIT 1 OFFSET 0');
$formatter = new PropelSimpleArrayFormatter();
$formatter->init(new ModelCriteria('bookstore', 'Book'));
$book = $formatter->formatOne($stmt);
- $this->assertSame('0', $book);
+ $this->assertEquals('0', $book);
+ }
+
+ public function testFormatOneWithOneRowAndValueBooleanEqualsFalse()
+ {
+ $con = Propel::getConnection(BookPeer::DATABASE_NAME);
+ $stmt = $con->query('SELECT false FROM book LIMIT 1 OFFSET 0');
+
+ $formatter = new PropelSimpleArrayFormatter();
+ $formatter->init(new ModelCriteria('bookstore', 'Book'));
+
+ $book = $formatter->formatOne($stmt);
+ $this->assertNotNull($book);
+ $this->assertSame(false, (bool)$book);
+ }
+
+ public function testFormatWithOneRowAndValueBooleanEqualsFalse()
+ {
+ $con = Propel::getConnection(BookPeer::DATABASE_NAME);
+ $stmt = $con->query('SELECT false FROM book');
+
+ $formatter = new PropelSimpleArrayFormatter();
+ $formatter->init(new ModelCriteria('bookstore', 'Book'));
+
+ $books = $formatter->format($stmt);
+ $this->assertInstanceOf('PropelCollection', $books);
+ $this->assertCount(4, $books);
+ $this->assertSame(false, (bool)$books[0]);
}
}

0 comments on commit 19ac478

Please sign in to comment.