PHPUnit中使用shouldReceive进行随机输入的模拟方法

I am using Laravel 4 with PHPUnit 3.7.38. I have a class that uses a randomly generated value for input. I use str_random(100). I want to unit test it; however, everytime, I try to use shouldReceive on the method, I get an error saying that the value does not match the expected value. This makes sense since it randomly generates the value before testing it. I can not refactor the original code and I can not throw an exception halting the code because there is more to test after this code in the same function. I have tried mocking the str_random function; however, that throws another error. I'm really not sure what to do or if there is a good solution at this point in time. My code looks like:

class OriginalClass {

public function someFunction{

$randomCode = str_random(100);

    anotherFunction(array($name, $lastName, $randomCode), $anotherValue)

    }

}



class OriginalClassTest {



        $this->MockObject
            ->shouldReceive('anotherFunction')
            ->with(array('Jon', 'Smith', '11155488321'), '49')
            ->andReturn('Output');

        $this->assertEquals('Output', $this
            ->MockObject
            ->anotherFunction(array('Jon', 'Smith', '11155488321'), '49')); 
}

By the time the function is called a newly generated $randomCode has been created and I get the error

"Mockery\Exception\NoMatchingExpectationException : No matching handler found for Mockery_1_MockObject::anotherFunction(array('Jon', 'Smith', 'newly generated randomCode'), '49')"

You're not testing the str_random function. So your test, in plain english should read:

when str_random returns "ABCD", the "anotherFunction" should be called with "ABCD" as the $randomCode argument.

In other words, you need to get control over the random string in the test, and make sure of that value is used when calling the other function. You can do that by using a class that will provide the random string, and mocking it in the class, or using some other trick like this one.

If you already tried this and got an error, please post the error so we can help with it.