คำตอบข้างต้นส่วนใหญ่บ่งชี้ว่าการเยาะเย้ยตัวสร้างตัวเลขแบบสุ่มเป็นวิธีที่จะไป แต่ฉันก็แค่ใช้ฟังก์ชั่นที่สร้างขึ้นใน mt_rand การอนุญาตให้มีการเยาะเย้ยอาจหมายถึงการเขียนคลาสใหม่เพื่อต้องการให้เครื่องสร้างตัวเลขสุ่มถูกฉีดเข้าไปในเวลาก่อสร้าง  
หรืออย่างนั้นฉันก็คิด!  
หนึ่งในผลที่ตามมาจากการเพิ่มเนมสเปซคือการเยาะเย้ยในฟังก์ชั่น PHP ได้กลายเป็นเรื่องยากที่จะเรียบง่าย หาก SUT อยู่ในเนมสเปซที่กำหนดสิ่งที่คุณต้องทำคือกำหนดฟังก์ชั่น mt_rand ของคุณเองในการทดสอบหน่วยภายใต้เนมสเปซนั้นและจะใช้แทนฟังก์ชั่น PHP ในตัวตลอดระยะเวลาการทดสอบ  
นี่คือชุดการทดสอบที่สรุปแล้ว: 
namespace gordian\reefknot\util;
/**
 * The following function will take the place of mt_rand for the duration of 
 * the test.  It always returns the number exactly half way between the min 
 * and the max.
 */
function mt_rand ($min = 42, $max = NULL)
{
    $min    = intval ($min);
    $max    = intval ($max);
    $max    = $max < $min? $min: $max;
    $ret    = round (($max - $min) / 2) + $min;
    //fwrite (STDOUT, PHP_EOL . PHP_EOL . $ret . PHP_EOL . PHP_EOL);
    return ($ret);
}
/**
 * Override the password character pool for the test 
 */
class PasswordSubclass extends Password
{
    const CHARLIST  = 'AAAAAAAAAA';
}
/**
 * Test class for Password.
 * Generated by PHPUnit on 2011-12-17 at 18:10:33.
 */
class PasswordTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var gordian\reefknot\util\Password
     */
    protected $object;
    const PWMIN = 15;
    const PWMAX = 20;
    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp ()
    {
    }
    /**
     * Tears down the fixture, for example, closes a network connection.
     * This method is called after a test is executed.
     */
    protected function tearDown ()
    {
    }
    public function testGetPassword ()
    {
        $this -> object = new PasswordSubclass (self::PWMIN, self::PWMAX);
        $pw = $this -> object -> getPassword ();
        $this -> assertTrue ((bool) preg_match ('/^A{' . self::PWMIN . ',' . self::PWMAX . '}$/', $pw));
        $this -> assertTrue (strlen ($pw) >= self::PWMIN);
        $this -> assertTrue (strlen ($pw) <= self::PWMAX);
        $this -> assertTrue ($pw === $this -> object -> getPassword ());
    }
    public function testGetPasswordFixedLen ()
    {
        $this -> object = new PasswordSubclass (self::PWMIN, self::PWMIN);
        $pw = $this -> object -> getPassword ();
        $this -> assertTrue ($pw === 'AAAAAAAAAAAAAAA');
        $this -> assertTrue ($pw === $this -> object -> getPassword ());
    }
    public function testGetPasswordFixedLen2 ()
    {
        $this -> object = new PasswordSubclass (self::PWMAX, self::PWMAX);
        $pw = $this -> object -> getPassword ();
        $this -> assertTrue ($pw === 'AAAAAAAAAAAAAAAAAAAA');
        $this -> assertTrue ($pw === $this -> object -> getPassword ());
    }
    public function testInvalidLenThrowsException ()
    {
        $exception  = NULL;
        try
        {
            $this -> object = new PasswordSubclass (self::PWMAX, self::PWMIN);
        }
        catch (\Exception $e)
        {
            $exception  = $e;
        }
        $this -> assertTrue ($exception instanceof \InvalidArgumentException);
    }
}
ฉันคิดว่าฉันพูดถึงเรื่องนี้เพราะฟังก์ชั่นภายในของ PHP ที่สำคัญคือการใช้ namespaces ที่ไม่ได้เกิดขึ้นกับฉัน ขอบคุณทุกคนสำหรับความช่วยเหลือในเรื่องนี้