Location: PHPKode > scripts > PHPStopFlood > phpstopflood/_tests/PHPStopFloodTest.php
<?php

require_once '../PHPStopFlood.php';

require_once 'PHPUnit/Framework/TestCase.php';

/**
 * PHPStopFlood test case.
 */
class PHPStopFloodTest extends PHPUnit_Framework_TestCase {

	/**
	 * @var PHPStopFlood
	 */
	private $PHPStopFlood;

	/**
	 * Prepares the environment before running a test.
	 */
	protected function setUp() {
		parent::setUp();
		$this->PHPStopFlood = new PHPStopFlood('File', array("logs_dir" => "C:\\Temp"));
	}

	/**
	 * Cleans up the environment after running a test.
	 */
	protected function tearDown() {
		$this->PHPStopFlood = null;
		parent::tearDown();
	}

	public function testSetLifetimeStringGiven() {
		$this->setExpectedException('PHPStopFlood_Exception');
		$this->PHPStopFlood->setLifetime("Tester");
	}

	public function testSetLifetimeNegativeGiven() {
		$this->PHPStopFlood->setLifetime(- 12);
		$this->assertAttributeEquals(12, '_lifetime', $this->PHPStopFlood);
	}

	public function testSetProbabilityStringGiven() {
		$this->setExpectedException('PHPStopFlood_Exception');
		$this->PHPStopFlood->setProbability("Tester");
	}

	public function testSetProbabilityNegativeGiven() {
		$this->PHPStopFlood->setProbability(- 10);
		$this->assertAttributeEquals(0.1, '_gcProbability', $this->PHPStopFlood);
	}

	public function testSetProbabilityGreaterThan100() {
		$this->PHPStopFlood->setProbability(500);
		
		$constraint = $this->attributeEqualTo('_gcProbability', 1);
		$this->assertThat($this->PHPStopFlood, $constraint);
	}

}

Return current item: PHPStopFlood