如何使用ExpectOutputString PHPunits?

问题描述 投票:0回答:1

这是我的第一个问题。

我安装了作曲家(1.10.5),fatfree-core(3.7)和phpunit(9.1.3),然后转到TDD。

所有工作,但如果我使用$ this-> expectOutputString();我断言:0-不起作用。

我发现是:

> $f3 = Base::instance();
> 
> $f3 -> mock ('GET /'); // <= it is problem

    <?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';
        }
    [...]

CMD:

 @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.

Base heve finall类,在嘲笑自己之前,我编辑了基本核心并删除了finall,但是现在这不是一个好主意。基本(无脂肪)具有模拟选项。

您有一个如何使它变得更好的想法吗?-无需修改无脂肪和phpunit文件?我想使用phpunit进行测试,并且将编程环境置于无脂肪状态。

phpunit tdd fat-free-framework
1个回答
0
投票

使用getActualOutputForAssertion()获取输出,然后在其返回值上使用常规断言。但是,如果测试中的代码行为异常(仅)关闭其自身的输出缓冲区,那么这将对您没有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.