pluf2

pluf2 Git Source Tree


Root/src/Pluf/Tests/Cache/File.php

<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Plume Framework, a simple PHP Application Framework.
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
#
# Plume Framework is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Plume Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# ***** END LICENSE BLOCK ***** */

class Pluf_Tests_Cache_File extends UnitTestCase {

    private $_config;

    private $_arrayData = array(
        'hello' => 'world',
        'foo'   => false,
        0 => array('foo', 'bar')
    );

    public function __construct()
    {
        parent::__construct('Test the File cache API.');
    }

    public function setUp()
    {
        $this->_config = $GLOBALS['_PX_config']; // backup
        $GLOBALS['_PX_config']['cache_engine']  = 'Pluf_Cache_File';
        $GLOBALS['_PX_config']['cache_timeout'] = 5;
        $GLOBALS['_PX_config']['cache_file_folder'] = '/tmp/pluf_unittest_cache';
    }

    public function tearDown()
    {
        $GLOBALS['_PX_config'] = $this->_config;
    }

    public function testConstructor()
    {
        unset($GLOBALS['_PX_config']['cache_file_folder']);
        try {
            $cache = Pluf_Cache::factory();
        } catch (Pluf_Exception_SettingError $e) {
            $this->pass();
            return;
        }
        $this->fail('An exception as not been raised, "cache_file_folder" setting not defined.');
    }

    public function testBasic()
    {
        $cache = Pluf_Cache::factory();
        $success = $cache->set('test1', 'foo1');
        $this->assertTrue($success);
        $this->assertEqual('foo1', $cache->get('test1'));
    }

    public function testGetUnknownKey()
    {
        $cache = Pluf_Cache::factory();
        $this->assertNull(null, $cache->get('unknown'));
    }

    public function testGetDefault()
    {
        $cache = Pluf_Cache::factory();
        $this->assertEqual('default', $cache->get('unknown', 'default'));
    }

    public function testSerialized()
    {
        $cache = Pluf_Cache::factory();
        $success = $cache->set('array', $this->_arrayData);
        $this->assertTrue($success);
        $this->assertCopy($this->_arrayData, $cache->get('array'));

        $obj = new stdClass();
        $obj->foo = 'bar';
        $obj->hello = 'world';
        $success = $cache->set('object', $obj);
        $this->assertTrue($success);
        $this->assertCopy($obj, $cache->get('object'));

        unset($obj);
        $this->assertIsA($cache->get('object'), 'stdClass');
        $this->assertEqual('world', $cache->get('object')->hello);
    }
}

Archive Download this file

Branches

Number of commits:
Page rendered in 0.06402s using 11 queries.