Allow (int)0 in coomments count in entry feed #2292

Merged
merged 3 commits into from Sep 10, 2012

Projects

None yet

4 participants

@AndrejAndb

I think empty() is not required. And with it the value of (int)0 is not allowed

@travisbot

This pull request passes (merged 49be449 into 3a4cee6).

@travisbot

This pull request passes (merged e868ba8 into 3a4cee6).

@weierophinney weierophinney commented on the diff Sep 4, 2012
tests/ZendTest/Feed/Writer/EntryTest.php
@@ -521,6 +521,13 @@ public function testSetsCommentCount()
$this->assertEquals(10, $entry->getCommentCount());
}
+ public function testSetsCommentCount0()
+ {
+ $entry = new Writer\Entry;
+ $entry->setCommentCount(0);
@weierophinney
weierophinney Sep 4, 2012 Zend Framework member

You need to test all possible types here -- array(), '', 0, 0.0, false, and null would all have passed before. Test those values as well, and if it still passes, you're good. :)

@travisbot

This pull request passes (merged ccc2ae5 into 3a4cee6).

@AndrejAndb

done :)
but array(), '', true, false, and null not allowed. allowed only positive integer and zero. or float like 1.0 , 2.0....

@padraic
Member
padraic commented Sep 8, 2012

Should probably just use ctype_digits() - floats would also be invalid technically

@AndrejAndb

i think allowing 1.0 - its not bad.
and just use ctype_digits() - not work, need some:
(!ctype_digit((string)$count) || !is_numeric($count) || (int)$count != $count)

@weierophinney weierophinney commented on the diff Sep 10, 2012
tests/ZendTest/Feed/Writer/EntryTest.php
+ {
+ $entry = new Writer\Entry;
+ foreach (array(0, 0.0, 1, PHP_INT_MAX) as $testCase) {
+ $entry->setCommentCount($testCase);
+ $this->assertEquals((int)$testCase, $entry->getCommentCount());
+ }
+ }
+
+ public function testSetsCommentCountDisallowed()
+ {
+ $entry = new Writer\Entry;
+ foreach (array(1.1, -1, -PHP_INT_MAX, array(), '', false, true, new \stdClass, null) as $testCase) {
+ try {
+ $entry->setCommentCount($testCase);
+ $this->fail();
+ } catch (Writer\Exception\ExceptionInterface $e) {
@weierophinney
weierophinney Sep 10, 2012 Zend Framework member

Use setExpectedException and a dataProvider instead of foreach and try/catch

@weierophinney weierophinney added a commit that referenced this pull request Sep 10, 2012
@weierophinney weierophinney [#2292] Better testing practices
- Used data providers to clean up the tests so that they focus on intent
- Used setExpectedException instead of try/catch/fail
07f3eb4
@weierophinney weierophinney merged commit ccc2ae5 into zendframework:master Sep 10, 2012

1 check passed

Details default The Travis build passed
@weierophinney
Member

I took care of the test cleanup, and merged to release and master.

@weierophinney weierophinney added a commit to zendframework/zend-feed that referenced this pull request May 15, 2015
@weierophinney weierophinney [zendframework/zendframework#2292] Better testing practices
- Used data providers to clean up the tests so that they focus on intent
- Used setExpectedException instead of try/catch/fail
5207b7a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment