Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limiting length of getCallerName return value to avoid issue when storing logs and screenshots #1070

Merged
merged 2 commits into from
Nov 14, 2023

Conversation

lk77
Copy link
Contributor

@lk77 lk77 commented Nov 14, 2023

Hello,

I have some dusk tests that fails when there is console logs, because the filename is too long

ErrorException : file_put_contents(/var/www/html/tests/Browser/console/Tests_Browser_Pages_SomeFolder_MoreFolders_MyFolder_MyTestClass_testFunction-0.log): Failed to open stream: File name too long

it happens when the test class is in a deep subfolder, in my case i have 5 folders, and also the name of the test itself is pretty long,

i propose to limit the number of characters of the return value of the ProvidesBrowser::getCallerName function

/**
 * Get the browser caller name.
 *
 * @return string
 */
protected function getCallerName()
{
    $name = version_compare(Version::id(), '10', '>=')
        ? $this->name()
        : $this->getName(false); // @phpstan-ignore-line

    return str_replace('\\', '_', substr(get_class($this), 0, 70)).'_'.substr($name, 0, 70);
}

both the class name and the test name will be limited to 70 characters

i added a test, to verify that the test name is correctly truncated,

to test that the class name is correctly truncated would require the creation of another test class with a very long name,

i don't know if it's something you want to do.

@taylorotwell taylorotwell merged commit 99df89a into laravel:7.x Nov 14, 2023
21 checks passed
@ziadoz
Copy link
Contributor

ziadoz commented Feb 8, 2024

@lk77 I'm working on a PR that adds data sets to filenames for tests using data providers. Do you have any idea what the maximum file length is? And what operating system this issue occurs on? I just want to make sure I'm not re-introducing this bug.

@lk77
Copy link
Contributor Author

lk77 commented Feb 9, 2024

@ziadoz it's 255, but for the whole path, that's why i limited the filename to 140 to be sure there is enough for the directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants