* @copyright Copyright (c) 2006-2012 Jonathan Stoppani * @version 1.0 * @license http://www.opensource.org/licenses/MIT MIT License * @link https://github.com/GaretJax/phpbrowscap/ */ class TestCase extends \PHPUnit_Framework_TestCase { /** * @var string */ protected $cacheDir; protected function createCacheDir() { $cacheDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'browscap_testing'; if (!is_dir($cacheDir)) { if (false === @mkdir($cacheDir, 0777, true)) { throw new \RuntimeException(sprintf('Unable to create the "%s" directory', $cacheDir)); } } $this->cacheDir = $cacheDir; return $this->cacheDir; } protected function createBrowscap() { $cacheDir = $this->createCacheDir(); return new Browscap($cacheDir); } /** * removes the temporary cache directory */ protected function removeCacheDir() { if (isset($this->cacheDir) && is_dir($this->cacheDir)) { @rmdir($this->cacheDir); $this->cacheDir = null; } } /** * Tears down the fixture, for example, close a network connection. * This method is called after a test is executed. */ protected function tearDown() { $this->removeCacheDir(); } }