Permalink
Browse files

Fixed a couple of missing $propertyPath variables and added tests for…

… everything that was not covered yet
  • Loading branch information...
1 parent 83ac660 commit d444f1d931a87161f03bd17367a36b13167899b4 @edorian edorian committed Sep 5, 2012
Showing with 88 additions and 7 deletions.
  1. +3 −3 lib/Assert/Assertion.php
  2. +9 −2 phpunit.xml.dist
  3. +76 −2 tests/Assert/Tests/AssertTest.php
View
@@ -257,7 +257,7 @@ static public function length($value, $length, $message = null, $propertyPath =
}
/**
- * Assert that string value is at least of a minimum length.
+ * Assert that a string is at least $minLength chars long.
*
* @param mixed $value
* @param int $minLength
@@ -276,7 +276,7 @@ static public function minLength($value, $minLength, $message = null, $propertyP
}
/**
- * Assert that string value is not longer than a maximum length.
+ * Assert that string value is not longer than $maxLength chars.
*
* @param mixed $value
* @param integer $maxLength
@@ -380,7 +380,7 @@ static public function choice($value, array $choices, $message = null, $property
*/
static public function inArray($value, array $choices, $message = null, $propertyPath = null)
{
- static::choice($value, $choices, $message);
+ static::choice($value, $choices, $message, $propertyPath);
}
/**
View
@@ -1,8 +1,15 @@
<?xml version="1.0" ?>
-<phpunit bootstrap="tests/bootstrap.php">
+<phpunit bootstrap="tests/bootstrap.php" backupGlobals="false">
<testsuites>
<testsuite name="Assertion">
- <directory suffix="Test.php">./tests</directory>
+ <directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
+
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">./lib/</directory>
+ </whitelist>
+ </filter>
+
</phpunit>
@@ -132,12 +132,27 @@ public function testInvalidMinLength()
Assertion::minLength("foo", 4);
}
+ public function testValidMinLength()
+ {
+ Assertion::minLength("foo", 3);
+ Assertion::minLength("foo", 1);
+ Assertion::minLength("foo", 0);
+ Assertion::minLength("", 0);
+ }
+
public function testInvalidMaxLength()
{
$this->setExpectedException('Assert\AssertionFailedException', null, Assertion::INVALID_MAX_LENGTH);
Assertion::maxLength("foo", 2);
}
+ public function testValidMaxLength()
+ {
+ Assertion::maxLength("foo", 10);
+ Assertion::maxLength("foo", 3);
+ Assertion::maxLength("", 0);
+ }
+
public function testInvalidBetweenLengthMin()
{
$this->setExpectedException('Assert\AssertionFailedException', null, Assertion::INVALID_MIN_LENGTH);
@@ -191,7 +206,13 @@ public function testValidChoice()
Assertion::choice("foo", array("foo"));
}
- public function testValidInarray()
+ public function testInvalidInArray()
+ {
+ $this->setExpectedException('Assert\AssertionFailedException', null, Assertion::INVALID_CHOICE);
+ Assertion::inArray("bar", array("baz"));
+ }
+
+ public function testValidInArray()
{
Assertion::inArray("foo", array("foo"));
}
@@ -209,6 +230,35 @@ public function testValidNumeric()
Assertion::numeric(1.23);
}
+ static public function dataInvalidArray()
+ {
+ return array(
+ array(null),
+ array(false),
+ array("test"),
+ array(1),
+ array(1.23),
+ array(new \StdClass),
+ array(fopen('php://memory', 'r')),
+ );
+ }
+
+ /**
+ * @dataProvider dataInvalidArray
+ */
+ public function testInvalidArray($value)
+ {
+ $this->setExpectedException('Assert\AssertionFailedException', null, Assertion::INVALID_ARRAY);
+ Assertion::isArray($value);
+ }
+
+ public function testValidArray()
+ {
+ Assertion::isArray(array());
+ Assertion::isArray(array(1,2,3));
+ Assertion::isArray(array(array(),array()));
+ }
+
public function testInvalidKeyExists()
{
$this->setExpectedException('Assert\AssertionFailedException', null, Assertion::INVALID_KEY_EXISTS);
@@ -220,7 +270,7 @@ public function testValidKeyExists()
Assertion::keyExists(array("foo" => "bar"), "foo");
}
- public function testInvalidnotBlank()
+ public function testInvalidNotBlank()
{
$this->setExpectedException('Assert\AssertionFailedException', null, Assertion::INVALID_NOT_BLANK);
Assertion::notBlank("");
@@ -416,6 +466,30 @@ public function testDirectory()
Assertion::directory(__DIR__ . '/does-not-exist');
}
+ public function testReadable()
+ {
+ Assertion::readable(__FILE__);
+
+ $this->setExpectedException('Assert\AssertionFailedException', null, Assertion::INVALID_READABLE);
+ Assertion::readable(__DIR__ . '/does-not-exist');
+ }
+
+ public function testWriteable()
+ {
+ Assertion::writeable(sys_get_temp_dir());
+
+ $this->setExpectedException('Assert\AssertionFailedException', null, Assertion::INVALID_WRITEABLE);
+ Assertion::writeable(__DIR__ . '/does-not-exist');
+ }
+
+ /**
+ * @expectedException \BadMethodCallException
+ * @expectedExceptionMessage No assertion
+ */
+ public function testFailedNullOrMethodCall()
+ {
+ Assertion::NullOrAssertionDoesNotExist();
+ }
}
class ChildStdClass extends \stdClass

0 comments on commit d444f1d

Please sign in to comment.