Php 带出口的Mock方法
我正在尝试测试一个重定向和退出的方法(退出是必要的) 1.Approach=>在我的第一种方法中,我打算从RedirectToHome返回一个值(我知道它不会在死后返回任何东西)。只是为了让测试起作用。Php 带出口的Mock方法,php,unit-testing,wordpress,mocking,Php,Unit Testing,Wordpress,Mocking,我正在尝试测试一个重定向和退出的方法(退出是必要的) 1.Approach=>在我的第一种方法中,我打算从RedirectToHome返回一个值(我知道它不会在死后返回任何东西)。只是为了让测试起作用。 2.有没有更好的方法来测试这个方法 class MyClass { public function ExecuteProcess() { if (condition1) { // Do some stuff } else { // 1. Approac
2.有没有更好的方法来测试这个方法
class MyClass {
public function ExecuteProcess() {
if (condition1) {
// Do some stuff
} else {
// 1. Approach
return $this->RedirectToHome();
// 2. Approach ?
}
}
public function RedirectToHome() {
wp_redirect();
exit();
}
}
以及测试代码:
public function test_MyClass() {
$mock = $this->getMockBuilder('MyClass')
->setMethods(array('RedirectToHome'))
->getMock();
$mock->expects($this->once())
->method('RedirectToHome')
->will($this->returnValue(true))
$mock->ExecuteProcess();
// Asert