Regex to test changing return values in PHPUnit

Code
<?php

use PHPUnit\Framework\TestCase;

class RegexTest extends TestCase
{
    public function testCreateId() : void
    {
        $p = '/^id_[\da-f]{13}$/';
        
        $foo = $this->createMock('Foo');
        $foo->expects($this->once())
            ->method('useId')
            ->with(new PHPUnit\Framework\Constraint\RegularExpression($p))
            ->will($this->returnValue(true));
        
        $bar = new Bar($foo);
        $id = $bar->createId();
        
        $this->assertMatchesRegularExpression($p, $id);
    }
}

// class to test
class Bar
{
    private $foo;
    
    public function __construct(Foo $foo)
    {
        $this->foo = $foo;
    }
    
    public function createId()
    {
        $id = uniqid('id_');
        $this->foo->useId($id);
        
        return $id;
    }
}

// dependency of Bar
class Foo
{
    public function useId($id)
    {
        // ... doing stuff with id
        return true;
    }
}
Result
Time: 00:00.007, Memory: 18.00 MB

OK (1 test, 0 assertions)
Used Versions
PHP 8.3, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8