diff --git a/tests/KabanosTest.php b/tests/KabanosTest.php new file mode 100644 index 0000000..682bc7d --- /dev/null +++ b/tests/KabanosTest.php @@ -0,0 +1,70 @@ +assertTrue(class_exists('Kabanos')); + } + + public function setUp() + { + $this->kabanos = new Kabanos; + } + + public function providerData() + { + return array( + array('phpunit#1', 10, 5, 123), + array('phpunit#2', 60, 10, 123), + array('phpunit#3', 120, 15, 123) + ); + } + + /** + * @dataProvider providerData + */ + public function testCheck($type, $second, $limit, $userId) + { + // it ok + for($a = 0; $a < $limit; $a++) { + $res = $this->kabanos->check($type, array($second => $limit), $userId); + } + $this->assertFalse( $res ); + + // banned + $res = $this->kabanos->check($type, array($second => $limit), $userId); + $this->assertArrayHasKey($second, $res); + + // cleaning data + $this->kabanos->removeBan($type, $second, $userId); + } + + /** + * @dataProvider providerData + */ + public function testCheckBan($type, $second, $limit, $userId) + { + // banned + for($a = 0; $a < $limit+1; $a++) { + $res = $this->kabanos->check($type, array($second => $limit), $userId); + } + $this->assertArrayHasKey($second, $res); + + // cleaning data + $this->kabanos->removeBan($type, $second, $userId); + } +} + \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..3b0d4ed --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,2 @@ +