Skip to content

Commit f147c66

Browse files
committed
ci: write test for the boolean rule
1 parent d61090c commit f147c66

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/Rules/BooleanTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Rakit\Validation\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Rakit\Validation\Rules\Boolean;
7+
8+
class BooleanTest extends TestCase
9+
{
10+
public function setUp()
11+
{
12+
$this->rule = new Boolean;
13+
}
14+
15+
public function testValids()
16+
{
17+
$this->assertTrue($this->rule->check(\true));
18+
$this->assertTrue($this->rule->check(\false));
19+
$this->assertTrue($this->rule->check(1));
20+
$this->assertTrue($this->rule->check(0));
21+
$this->assertTrue($this->rule->check('1'));
22+
$this->assertTrue($this->rule->check('0'));
23+
$this->assertTrue($this->rule->check('y'));
24+
$this->assertTrue($this->rule->check('n'));
25+
}
26+
27+
public function testInvalids()
28+
{
29+
$this->assertFalse($this->rule->check(11));
30+
$this->assertFalse($this->rule->check([]));
31+
$this->assertFalse($this->rule->check('foo123'));
32+
$this->assertFalse($this->rule->check('123foo'));
33+
$this->assertFalse($this->rule->check([123]));
34+
$this->assertFalse($this->rule->check('123.456'));
35+
$this->assertFalse($this->rule->check('-123.456'));
36+
}
37+
}

0 commit comments

Comments
 (0)