如何使用expectOutputString PHPunits?

如何使用expectOutputString PHPunits?,phpunit,tdd,fat-free-framework,Phpunit,Tdd,Fat Free Framework,这是我的第一个问题 我安装composer(1.10.5)、fatfree core(3.7)和phpunit(9.1.3)并转到TDD 一切正常,但如果我使用$this->expectOutputString(); 我的断言是:0-不起作用 我发现它是: > $f3 = Base::instance(); > > $f3 -> mock ('GET /'); // <= it is problem 基本heve finall类,在我嘲笑自己之前,我编辑基本核心

这是我的第一个问题

我安装composer(1.10.5)、fatfree core(3.7)和phpunit(9.1.3)并转到TDD

一切正常,但如果我使用$this->expectOutputString(); 我的断言是:0-不起作用

我发现它是:

> $f3 = Base::instance();
> 
> $f3 -> mock ('GET /'); // <= it is problem
基本heve finall类,在我嘲笑自己之前,我编辑基本核心并删除finall,但现在这不是个好主意。基本(无脂肪)有模拟选项

你有办法让它变好吗? -不修改无脂肪和phpunit文件?
我想使用phpunit进行测试,并将编程环境设置为无脂肪状态。

使用
getActualOutputForAssertion()
获取输出,然后对其返回值使用常规断言。不过,这对正在测试的行为不端的代码没有帮助,因为这些代码(只)关闭了自己的输出缓冲区。

Wow@SebastianBergmann,我知道你是谁。thx
var\u dump($this->getActualOutputForAssertion())
returnstring(0)”,但我读到,我有线索。在我使用
ob_start()之前
ob\u get\u contents()
但控制台中的操作不起作用:

    <?php 
    [...]
    protected function setUp (): void
        {
            $this->f3 = Base::instance ();
            $this->f3 -> set ('QUIET',TRUE);
            $this->f3 -> config ('config.ini');
            $this->f3 -> mock ('GET /ftp');

            $this -> MainController = new MainController ($this->f3);
        }

        public function testExpectFooActualFoo ()
        {
            $this->expectOutputString ('foo');
            print'foo';
        }
    [...]

 @php ./vendor/phpunit/phpunit/phpunit tests/MainControllerNoStaticTest.php
 PHPUnit 9.1.3 by Sebastian Bergmann and contributors.

 fooR
                        1 / 1 (100%)

 Time: 00:00.052, Memory: 4.00 MB

 There was 1 risky test:

 1) MainControllerNoStaticTest::testExpectFooActualFoo
 Test code or tested code did not (only) close its own output buffers

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.