PHPUnit只测试一些参数

For example, if there is the method
public function validate($param1, $param2) { // validate $param1 // validate $param2 }

Can I just test $param1 to be validated??

I mean something like mocking the method so when validating $param2, it will always return TRUE.. So it just validate the $param1..
Is it able to do that?

Don't mock your own code that is about to be tested.

If you have written a method that needs two parameters and will validate them, you have to provide two values for every test.

If this is annoying, because the two parameters don't have anything in common besides being validated in the same method, this is a true sign for badly designed code. If it is annoying to test something, then it probably is annoying to use that code as well.

Take these hints as tasks to improve the code. If you have two absolutely independent values that can be validated separately, then do separate them. Have a validation class for each one of them, test the validation thoroughly there. Then have another class that accepts these two validators, and test that with one call of the method, the first parameter is passed to the first validator (mocked!), and the second one to the second validator (also mocked). Done!

You end up with one class resembling something like a form with multiple fields, and two individual validators that can be easily reused.

If validation of $param1 is not realted with the validation of $param2 (are not dependant), I would refactor your public API to look something like this.

private function validateSingleParam($aParam)
{
    // perform $aParam validation
}

public function validate($params)
{
    foreach ($params as $param) {
        $this->validateSingleParam($param);
    }
}

This way you can validate (and test) any number of params.