为什么PHPUnit报告错误的uid(0而不是1000)以及如何解决这个问题?

I'm writing unit tests for my library and I've found something I don't understand.

PHPunit is reporting uid 0 instead of 1000 when calling the function getmyuid(). I'm running as user 'vagrant' and regular code is reporting the correct uid (1000).

PHPUnit test code (tests/UidTest.php):

<?php
class UidTest extends \PHPUnit\Framework\TestCase
{
    public function test_uid_1000(): void
    {
        $this->assertEquals(1000, getmyuid());
    }

    public function test_uid_0(): void
    {
        $this->assertEquals(0, getmyuid());
    }
}

phpunit tests/UidTest.php

yields:

UidTest::test_uid_1000 Failed asserting that 0 matches expected 1000.

My regular script (testuid.php) reports the correct uid:

<?php
var_dump(getmyuid());

php testuid.php

yields:

int(1000)

My questions are:

Why is getmyuid() in phpunit reporting uid 0 instead of 1000?

How can I force getmyuid() in phpunit to report the correct uid 1000?