Phpunit with output buffering

I am trying to integrate PHPunit into a large project, everything seems fine, except that all methods that rely on ob_start () will lead to risky testing.

Reading online seems to be risky tests - these are tests that execute code that is not covered by the testing method. However, I did not use the @covers annotation at all, and this only happens on ob_start ().

So a few questions:

  • Can this problem be solved?
  • Is there something inherently wrong with ob_start when it comes to testing?
  • Is there any way around this (if this is not possible to solve).

If used, a framework is used whose views are returned (instead of being sent to the browser), Codeigniter is a classic example where you can return views. The views returned depend on ob_start (). Many thanks!

+5
source share
1 answer

The solution is twice as it revolves around the two problems that I had.

  • As for the specific problem, using the views in the structure (codeigniter), I just used mock for the bootloader, so I implemented an empty function that does not actually load and output html.
  • Regarding the actual problem that I ran into the behavior of PHPunit, it seems that PHPunit (4.5) would consider the test to be risky when using ob_start and ob_clean, but when using ob_get_clean the testing works as expected. I am not sure why, since I was not immersed in the code itself, but this allowed it for me.
+3
source

Source: https://habr.com/ru/post/1216142/


All Articles