在我的设置中,该info命令显示以下内容:
[keys] => 1128
[expires] => 1125
Run Code Online (Sandbox Code Playgroud)
我想找到没有失效日期的那3个密钥.我已经检查过文档无济于事.有任何想法吗?
假设我有以下课程:
class Foo
{
static function bar($inputs)
{
return $something;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,在测试类中,我有以下结构:
class FooTest extends PHPUnit_Framework_TestCase
{
function testBar()
{
$result = Foo::bar($sample_data_1);
$this->assertSomething($result);
$result = Foo::bar($sample_data_2);
$this->assertSomething($result);
$result = Foo::bar($sample_data_3);
$this->assertSomething($result);
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个很好的结构吗?我应该testBar()分成3个独立的功能吗?为什么?为什么不?
无论memcached服务器是否可用,我都希望确保我的代码始终按预期工作.
我的大多数功能看起来像这样:
function foo($parameter,$force = FALSE)
{
$result = Cache::get('foo_'.$parameter);
if (empty($result) || $force)
{
// Do stuff with the DB...
$result = "something";
Cache::put('foo_'.$parameter,$result,$timeout);
}
return $result;
}
Run Code Online (Sandbox Code Playgroud)
现在在TestCase中,我这样做:
class MyClassTest extends PHPUnit_Framework_TestCase {
function testFoo()
{
$result = $myClass->foo($parameter);
$this->assertSomething($result);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以在PHPUnit中全局禁用缓存,setUp()如下所示:
class MyClassTest extends PHPUnit_Framework_TestCase {
protected function setUp()
{
Cache::disable();
}
}
Run Code Online (Sandbox Code Playgroud)
在呼叫之后Cache::disable(),所有呼叫Cache::get()将false在该请求期间返回.现在,我想在这个类中运行两次所有测试,一次使用Cache::disable();,一次不使用.
有关如何做到这一点的任何想法?
我正在使用以下函数来展平多维数组:
function flatten($array, $prefix = '') {
$result = array();
foreach($array as $key=>$value) {
if(is_array($value)) {
$result = $result + flatten($value, $prefix . $key . '.');
}
else {
$result[$prefix . $key] = $value;
}
}
return $result;
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个匹配函数,unflatten它将反转该过程(例如,如果密钥中包含一个子数组,则创建一个子数组.).有任何想法吗?
我正在使用以下代码填充__all__我的模块__init__.py,如果有更有效的方法,我正在徘徊。有任何想法吗?
import fnmatch
import os
__all__ = []
for root, dirnames, filenames in os.walk(os.path.dirname(__file__)):
root = root[os.path.dirname(__file__).__len__():]
for filename in fnmatch.filter(filenames, "*.py"):
__all__.append(os.path.join(root, filename[:-3]))
Run Code Online (Sandbox Code Playgroud)