symfony / panther

A browser testing and web crawling library for PHP and Symfony
MIT License
2.9k stars 213 forks source link

Fix screenshot name for tests with data provider #510

Closed trakos closed 2 years ago

trakos commented 2 years ago

Fixes https://github.com/symfony/panther/issues/481

When using panther for tests with data provider, I've noticed that screenshots are not being made. While debugging I've noticed that there's an exception that's ignored by phpunit:

file_put_contents(data/panther_screenshots/2021-11-03_05-26-28_failure_AcmetTest-EndToEnd-TestCases-Orders-Admin-AddOrderTest__testAddOrder with data set "europe" ('TESTCLIENTAT', AcmeTest-EndToEnd-Library-Modules-Orders-Admin-Add-Models-Initial-TransferObject-BillingInformation Object (...), AcmeTest-EndToEnd-Library-Modules-Orders-Admin-Add-Models-Initial-TransferObject-ShippingAddress Object (...), 'PayU - transfer', 'Courier')-0.png): failed to open stream: File name too long

Apparently phpunit attaches all arguments to the test name when using toString method. To avoid that, we would have to use some methods marked as internal that might change without deprecation period. So, instead, I've added slugification of the test name, and cut it to the first 150 characters (with all the other segments total filename length is now max 235 characters).

trakos commented 2 years ago

I've fixed coding style violation (double quotes instead of single quotes).

trakos commented 2 years ago

I've rebased and changed target to 1.x

dunglas commented 2 years ago

Thanks!

tboyer-debuT commented 2 years ago

Hi !

Maybe it's an oversight for the slash character, but i think this line should be :

strtr($test, ['\\' => '-', ':' => '_', '/' => '-']),

in https://github.com/symfony/panther/blob/aeda2f11ac9a6236ac65f310fb21248c722ddcd6/src/ServerExtension.php#L89

trakos commented 2 years ago

@tboyer-debuT my change was only merged into 1.x branch, you can see it here: https://github.com/symfony/panther/blob/a923ff6d1f6a8034e9ae50d2c186bda1a36d951f/src/ServerExtension.php#L97

It removes slashes from the string, so they no longer break tests. I suppose it should be incorporated into main branch as well, so that it would be available in version 2 as well, but I don't know if that's planned.

Right now it hasn't been released yet, so it's available only on dev-1.x.