duankeng9477 2019-01-04 10:44
浏览 51

为什么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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料