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

require_once '../Container/MySQL.php';
require_once '../PHPStopFlood.php';

require_once 'PHPUnit/Framework/TestCase.php';

/**
 * PHPStopFlood_Container_File test case.
 */
class PHPStopFlood_Container_MySQL_Test extends PHPUnit_Framework_TestCase {

	/**
	 * @var PHPStopFlood_Container_MySQL
	 */
	private $_container;

	private $_testData = array ("testkey" => "testvalue", "testkey2" => 20);

	/**
	 * Prepares the environment before running a test.
	 */
	protected function setUp() {
		parent::setUp();
		$link = mysql_connect('localhost', 'root');
		mysql_select_db('test');
		$this->_container = new PHPStopFlood_Container_MySQL(
			array ("lifetime" => 1, 'link_identifier' => $link));
	}

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

	public function testReadWrite() {
		$this->_container->write("Test", $this->_testData);
		$this->assertEquals($this->_testData, $this->_container->read("Test"));
	}

	public function testGC() {
		$this->_container->gc(1);
		$this->assertEquals($this->_testData, $this->_container->read("Test"));
		sleep(2);
		$this->_container->gc(1);
		$this->assertEquals(array (), $this->_container->read("Test"));
	}

}

Return current item: PHPStopFlood