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

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

require_once 'PHPUnit/Framework/TestCase.php';

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

	/**
	 * @var PHPStopFlood_Container_File
	 */
	private $_container;
	private $_testData = array("testkey" => "testvalue", "testkey2" => 20);
	

	/**
	 * Prepares the environment before running a test.
	 */
	protected function setUp() {
		parent::setUp();
		$this->_container = new PHPStopFlood_Container_File(array("logs_dir" => dirname(__FILE__).'/FileContainerTestDir'));	
	}

	/**
	 * Cleans up the environment after running a test.
	 */
	protected function tearDown() {
		$this->_container = null;
		parent::tearDown();
	}
	
	public function testIncorrectLogsdir() {
		$this->setExpectedException('PHPStopFlood_Exception');
		new PHPStopFlood_Container_File(array("logs_dir" => "C:\\UnexistentDirLaRTaE"));
	}
	
	public function testDirNameOk() {
		$temp = new PHPStopFlood_Container_File(array("logs_dir" => "C:\\Temp"));
		$logDir = $this->getObjectAttribute($temp, '_logs_dir');
		$this->assertTrue($logDir === 'C:/Temp/');
	}
	
	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