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

require_once '../Container/PEAR_MDB.php';
require_once '../PHPStopFlood.php';
require_once 'MDB.php';

require_once 'PHPUnit/Framework/TestCase.php';

/**
 * PHPStopFlood_Container_File test case.
 */
class PHPStopFlood_Container_PEAR_MDB_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();
		$dsn = 'mysql://hide@address.com/test';
		$db = & MDB::connect($dsn);
		
		$this->_container = new PHPStopFlood_Container_PEAR_MDB(array ("db_object" => $db, "lifetime" => 1));
	}

	/**
	 * 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