0

In my application I have this weird error when testing only, I am not testing any classes in my Repo folder yet but have this:

Call to undefined method Application_Model_Cache::getInstance() in C:\wamp\www\truCrowd_dev\application\models\Repo\User.php on line 12

My user Repo is:

class Application_Model_Repo_User
{
    private $_database;
    private $_cache   ;

    public function __construct()
    {

        $this->_database   = Application_Model_Database::getInstance();
        $this->_cache      = Application_Model_Cache::getInstance();
        $this->_longCache  = Application_Model_Cache::getInstance(604800);
    }

My cache class is:

class Application_Model_Cache
{
    public static function getInstance($_expiration = 7200)
    {  
        $frontend= array(
        'lifetime' => $_expiration,
        'automatic_serialization' => true
        );

        $backend= array(
        'cache_dir' => './cache/',
        );

        $cache = Zend_Cache::factory('Output',
            'File',
            $frontend,
            $backend
        );
        return $cache;
    }
}

My testing bootstrap is:

<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'production');

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

I Have tried to change the Cache class by having to instantiate it but I get the same result... My Database class has the exact structure but I haven`t gotten this in the past, now that I advanced in development I wanted to make tests and the error appeared

4
  • 1
    Are you mocking the Application_Model_Cache class in any of your tests? depending on the way you're doing that, maybe the mock is being used as a unique instance so the method does not exist. Also, have you tried to isolate the test that makes the error happen? Commented Oct 21, 2013 at 12:30
  • If I am testing the Cache class? Could you explain a bit please? Zend_Cache doesn`t seem (at least to me) to have a singleton implementationso multiple instances can be made... Commented Oct 21, 2013 at 12:56
  • Hacked it by dissabling the cache in my config but still... :| Commented Oct 21, 2013 at 12:59
  • OK, Note to self: Never program at 3 AM else make sure when writing test scripts to append 'Test' in the class name because it will be overwritten... Commented Oct 21, 2013 at 13:27

1 Answer 1

1

You should check whether Application_Model_Cache class is being mocked in any of your tests, and if the mock is not being used when calling the non existent method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.