Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix bug with boolean value because no return FALSE value
  • Loading branch information
stood committed Feb 21, 2014
1 parent feb6604 commit 19ac478
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
8 changes: 2 additions & 6 deletions runtime/lib/formatter/PropelSimpleArrayFormatter.php
Expand Up @@ -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();

Expand All @@ -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();

Expand Down
Expand Up @@ -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()
Expand All @@ -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.