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 用matlab 设计一个不动点迭代法求解非线性方程组的代码
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效