Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带出口的Mock方法_Php_Unit Testing_Wordpress_Mocking - Fatal编程技术网

Php 带出口的Mock方法

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

我正在尝试测试一个重定向和退出的方法(退出是必要的)

1.Approach=>在我的第一种方法中,我打算从RedirectToHome返回一个值(我知道它不会在死后返回任何东西)。只是为了让测试起作用。
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