collision icon indicating copy to clipboard operation
collision copied to clipboard

No documented way to use only the PHPUnit (10) printer

Open Bilge opened this issue 1 year ago • 9 comments

If one wishes to only use the PHPUnit 10 printer, it is unclear how to do this, since there is no extension to bootstrap.

Bilge avatar Dec 01 '23 22:12 Bilge

@Bilge You can use this extension that uses Collision: https://github.com/robiningelbrecht/phpunit-pretty-print

robiningelbrecht avatar Dec 14 '23 17:12 robiningelbrecht

OK, but that seems like it does a lot more than just enable Collision, what with the Chuck Norris quotes and other unnecessary guff.

In reality, isn't this the single and only line that is actually needed to enable the printer?

https://github.com/robiningelbrecht/phpunit-pretty-print/blob/5d42dbf9d92a6299d3307d59b1a67c9eba22e065/src/PhpUnitExtension.php#L35

Bilge avatar Dec 14 '23 19:12 Bilge

@Bilge Everything is disabled by default. And yes that line is the bare minimum you need to run Collision, but I think you need to run it in an PHPUnit extension to make it work.

robiningelbrecht avatar Dec 15 '23 12:12 robiningelbrecht

I imagine you could just run it in the bootstrap file, no?

Bilge avatar Dec 15 '23 12:12 Bilge

@Bilge That might an option as well indeed, never tried this before. Since PHPUnit 10 I tend to work with the "extensions and events" it provides...

robiningelbrecht avatar Dec 15 '23 12:12 robiningelbrecht

It seems this is wrong. There appears to be some autoload trick going on that causes EnsurePrinterIsRegisteredSubscriber::register(); to be called automatically (see Autoload.php). Therefore, the only thing required to enable the printer is to ensure COLLISION_PRINTER environment variable is set (to anything, including nothing).

However, when I do this, although the printer is enabled, the output is messed up as it is now a mish-mash of Collision and PHPUnit output (it outputs the dots (...) between tests). Moreover, the text colour is dark grey which is difficult to read; I don't know if this is intended or not, but it wasn't the case with v6.

image

If I use your extension, the dots go away, but the text is still illegible. Presumably the dots are fixed by instructing PHPUnit to omit its own test output as here: https://github.com/robiningelbrecht/phpunit-pretty-print/blob/5d42dbf9d92a6299d3307d59b1a67c9eba22e065/src/PhpUnitExtension.php#L24C18-L24C39 What is strange about this is that there does not appear to be any equivalent call in Collision itself. But how do we even know Collision v7 even works with PHPUnit, considering its own test suite does not appear to activate the printer at all?


Aside, the text colour in v6 was also grey, but a lot lighter.

image

Bilge avatar Dec 15 '23 13:12 Bilge

@Bilge yeah indeed, you need to disable PHPUnit10's output, forgot about that, sorry.

But how do we even know Collision v7 even works with PHPUnit

Because the extension you are referring to has it's own test suite and proves it works?

robiningelbrecht avatar Dec 15 '23 13:12 robiningelbrecht

Previously non-Laravel projects had the option to use printerClass and enjoy collision. Now it seems that those outside of Laravel (or those who run vendor/bin/phpunit directly rather than through a wrapper function) can't use collision as easily.

srtfisher avatar Apr 22 '24 20:04 srtfisher

Yeah but why wouldn't everyone be using Laravel, the best static framework where everything is static and what even is concurrency safety anyway?

Bilge avatar Apr 22 '24 20:04 Bilge