shivammathur / setup-php

GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.
https://setup-php.com
MIT License
2.91k stars 340 forks source link

Testing tmp dir in MacOS and Windows runners #764

Closed joanhey closed 1 year ago

joanhey commented 1 year ago

Describe the bug Testing with Pest, that a temp file exist. First we create the temp file:

$tmp_file = \tempnam(\sys_get_temp_dir(), 'php');
\file_put_contents($tmp_file,$data);

Later we check that the file exist in the temp file, as the file name is random, we test that the path start with the temp dir:

expect($response->getBody()->getContents())
        ->toBeJson()
        ->json()
        ->toHaveCount(1)
        ->toHaveKey($data['file'])
        ->{$data['file']}
            ->toMatchArray($data['expect'])
            ->toHaveKey('tmp_name')
        ->{$data['file']}->tmp_name
            ->toStartWith(
                is_link(sys_get_temp_dir()) // GH Actions
                ? readlink(sys_get_temp_dir())
                : sys_get_temp_dir()
            );

})->with('UPLOAD');

Tried to read symlinks, but also fail.

For create the file and test, we use in both sys_get_temp_dir().

I read about in: https://github.com/actions/runner-images/issues/712 https://github.com/actions/toolkit/issues/518

But without a way to fix it.

Windows: image

MacOS: image

Any help will be appreciated.

Version

Runners

Operating systems Ubuntu OK MacOS and Windows fail

PHP versions 8.1, 8.2, 8.3

To Reproduce .yml file

Expected behavior That the tmp dir is the same to test it.

Screenshots/Logs With Ubuntu is OK.

MacOS image

Windows image

Additional context Check in win-mac branch: https://github.com/joanhey/AdapterMan/tree/win-mac

Are you willing to submit a PR?

shivammathur commented 1 year ago

@joanhey

Please use realpath, realpath(sys_get_temp_dir()) should return actual paths.

Test workflow: https://github.com/shivammathur/test-setup-php/actions/runs/6077310018/workflow

joanhey commented 1 year ago

I changed in Pest test the toStartWith() with toBeFile() and worked without problems.

But I will test the realpath() to test it also.

joanhey commented 1 year ago

Yes, is working withrealpath(). https://github.com/joanhey/AdapterMan/actions/runs/6077354164/job/16486891097

Thank You !!!