testing code that uses apc
Moderator: General Moderators
testing code that uses apc
Is there a way to mock apc?
Re: testing code that uses apc
Do you suggest writing it to a file?php_east wrote:http://www.php.net/manual/en/ref.apc.php#74032
The problem is with a class like this:
Code: Select all
class ApcAdapter
{
public function store($key, $var) {
apc_store($key, $var);
}
}
Re: testing code that uses apc
ah, when you say mock i thought you meant mimicking apc, if so that would be it. but i see now you meant a class to do the same as apc. how about using sessions to mock its behavior ?
Re: testing code that uses apc
actually, if you think about it, it is all finally in a file.koen.h wrote:Do you suggest writing it to a file?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: testing code that uses apc
Wrap the APC functions in a class and then mock the class. It could use a file or a database.
(#10850)
Re: testing code that uses apc
Actually the current class is like an apc wrapper. I would have to create a similare one as the one under testing.arborint wrote:Wrap the APC functions in a class and then mock the class. It could use a file or a database.
Re: testing code that uses apc
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: testing code that uses apc
I'd do as arborint says. Create a KeyCache API, or something to that effect:
Then make an APC implementation of this (you could also have MemCache and XCache implementation, or even File and DB..).
Now, your unit tests need not worry about APC, they only need to worry about the KeyCache interface, which is easy to mock. If the cache is provided by some sort of factory (KeyCacheProvider?) then you have the control to decouple the instantiation of a specific keycache in any code that uses it, and therefore have the control to substitute in your Mock.
Code: Select all
interface KeyCache {
const LIFETIME_DEFAULT = 3600;
function put($key, $value, $lifetime = self::LIFETIME_DEFAULT);
function has($key);
function get($key);
function clear($key);
}Now, your unit tests need not worry about APC, they only need to worry about the KeyCache interface, which is easy to mock. If the cache is provided by some sort of factory (KeyCacheProvider?) then you have the control to decouple the instantiation of a specific keycache in any code that uses it, and therefore have the control to substitute in your Mock.