diff --git a/README.md b/README.md index 267e96a6..86b27191 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,11 @@ Matchers ### Booleans * `false` - Always fail. +* `? is a boolean` - Assert a value is true or false. + * `? is a bool` * `? is false` - Assert value is false. +* `? is not a boolean` - Assert a value is not true or false. + * `? is not a bool` * `? is true` - Assert a value is true. * `true` - Always pass. diff --git a/src/Concise/Matcher/IsABoolean.php b/src/Concise/Matcher/IsABoolean.php new file mode 100644 index 00000000..7ac4765f --- /dev/null +++ b/src/Concise/Matcher/IsABoolean.php @@ -0,0 +1,24 @@ + 'Assert a value is true or false.', + '? is a bool' => 'Assert a value is true or false.', + ); + } + + public function match($syntax, array $data = array()) + { + return is_bool($data[0]); + } + + public function getTags() + { + return array(Tag::BOOLEANS); + } +} diff --git a/src/Concise/Matcher/IsNotABoolean.php b/src/Concise/Matcher/IsNotABoolean.php new file mode 100644 index 00000000..b8fe9892 --- /dev/null +++ b/src/Concise/Matcher/IsNotABoolean.php @@ -0,0 +1,24 @@ + 'Assert a value is not true or false.', + '? is not a bool' => 'Assert a value is not true or false.', + ); + } + + public function match($syntax, array $data = array()) + { + return !parent::match(null, $data); + } + + public function getTags() + { + return array(Tag::BOOLEANS); + } +} diff --git a/tests/Concise/Matcher/IsABooleanTest.php b/tests/Concise/Matcher/IsABooleanTest.php new file mode 100644 index 00000000..3e76f65d --- /dev/null +++ b/tests/Concise/Matcher/IsABooleanTest.php @@ -0,0 +1,32 @@ +matcher = new IsABoolean(); + } + + public function testTrueIsABoolean() + { + $this->assert(true, is_a_boolean); + } + + public function testAStringIsNotABoolean() + { + $this->assertFailure("true", is_a_boolean); + } + + public function testFalseIsABoolean() + { + $this->assert(false, is_a_boolean); + } + + public function testAlternativeShorterSyntax() + { + $this->assert(true, is_a_bool); + } +} diff --git a/tests/Concise/Matcher/IsNotABooleanTest.php b/tests/Concise/Matcher/IsNotABooleanTest.php new file mode 100644 index 00000000..016e3fd1 --- /dev/null +++ b/tests/Concise/Matcher/IsNotABooleanTest.php @@ -0,0 +1,32 @@ +matcher = new IsNotABoolean(); + } + + public function testTrueIsABoolean() + { + $this->assertFailure(true, is_not_a_boolean); + } + + public function testAStringIsNotABoolean() + { + $this->assert("true", is_not_a_boolean); + } + + public function testFalseIsABoolean() + { + $this->assertFailure(false, is_not_a_boolean); + } + + public function testAlternativeShorterSyntax() + { + $this->assertFailure(true, is_not_a_bool); + } +} diff --git a/wiki b/wiki index 2a497658..a241f94a 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 2a497658cf861d0c13de28ad48d7159e59b17f07 +Subproject commit a241f94a6112d27d6daa6c168b807a87d6dd3403