I’m trying to test a method that redirects and exits (exit is necessary).
1.Approach => In my first approach I intend to make return a value from RedirectToHome (I know it nevers returns any stuff as it dies). Is just for the test to work.
2. Is there a better way to test this method?
class MyClass {
public function ExecuteProcess() {
if (condition1) {
// Do some stuff
} else {
// 1. Approach
return $this->RedirectToHome();
// 2. Approach ?
}
}
public function RedirectToHome() {
wp_redirect();
exit();
}
}
And the Test Code:
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