我正在使用phpunit框架,我有这样的代码:
public function A() {
try {
(...some code...)
die (json_encode ($data));
}
catch (Exception $e) {
die(false);
}
}
Run Code Online (Sandbox Code Playgroud)
这个函数是通过AJAX调用的,我不能用return替换die.问题是:如何使用这样的代码进行单元测试?
断言,我不能用它.
谢谢.
我的问题是,我如何连接phpunit的clausule中的约束?在虚拟示例中:
$test->expects ($this->once())
->method ('increaseValue')
->with ($this->greaterThan (0)
->will ($this->returnValue (null));
Run Code Online (Sandbox Code Playgroud)
方法increaseValue的参数必须大于0,但如果我需要评估此参数必须小于10.
我如何连接$this->lessThan(10)?
我开发了一种使用@Cacheable注释的方法。代码是:
@Cacheable(value="reporties" , key="{#root.methodName,#manager.name}")
public List<Employee> getReportiesForManager(Employee manager){
// code to fetch reporties its a Spring JDBC call
}
Run Code Online (Sandbox Code Playgroud)
现在,我想在发生一些事件后驱逐此缓存:
之后,与管理器相关的缓存应该被驱逐,这样应用程序将获取新的数据,而不是使用该缓存中现有的数据。我为此开发了以下方法:
@CacheEvict(value="reporties",key="{#name}")
public void evictReportiesCache(String name){}
Run Code Online (Sandbox Code Playgroud)
我在更新管理器及其报告者关系的方法内部调用。然而,这个间歇性地工作,我不确定这是否是逐出缓存的正确方法。Cacheable 也用作#root.methodName密钥的一部分。
有人可以帮我清除缓存吗?