Skip to content

Commit

Permalink
Merge pull request #173 from elliotchance/1.4/173-is-a-boolean
Browse files Browse the repository at this point in the history
? is a boolean
  • Loading branch information
elliotchance committed Sep 13, 2014
2 parents 7a6064c + 455f5b5 commit 3c739b5
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
24 changes: 24 additions & 0 deletions src/Concise/Matcher/IsABoolean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Concise\Matcher;

class IsABoolean extends AbstractMatcher
{
public function supportedSyntaxes()
{
return array(
'? is a boolean' => '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);
}
}
24 changes: 24 additions & 0 deletions src/Concise/Matcher/IsNotABoolean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Concise\Matcher;

class IsNotABoolean extends IsABoolean
{
public function supportedSyntaxes()
{
return array(
'? is not a boolean' => '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);
}
}
32 changes: 32 additions & 0 deletions tests/Concise/Matcher/IsABooleanTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Concise\Matcher;

class IsABooleanTest extends AbstractMatcherTestCase
{
public function setUp()
{
parent::setUp();
$this->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);
}
}
32 changes: 32 additions & 0 deletions tests/Concise/Matcher/IsNotABooleanTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Concise\Matcher;

class IsNotABooleanTest extends AbstractMatcherTestCase
{
public function setUp()
{
parent::setUp();
$this->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);
}
}
2 changes: 1 addition & 1 deletion wiki
Submodule wiki updated from 2a4976 to a241f9

0 comments on commit 3c739b5

Please sign in to comment.