Skip to content

Fix benchmark.php CSV path validation for non-existent files#1085

Merged
colinodell merged 2 commits into2.7from
copilot/fix-1068
Jul 20, 2025
Merged

Fix benchmark.php CSV path validation for non-existent files#1085
colinodell merged 2 commits into2.7from
copilot/fix-1068

Conversation

Copy link
Contributor

Copilot AI commented Jul 20, 2025

The benchmark script (tests/benchmark/benchmark.php) was failing with a "Path cannot be empty" error when users specified a non-existent CSV file via the --csv option.

Problem

When running:

php tests/benchmark/benchmark.php --csv non-exist.csv

The script would crash with:

Fatal error: Uncaught ValueError: Path must not be empty in /app/tests/benchmark/benchmark.php:123

Root Cause

The issue occurred because realpath() returns false when called on a non-existent file path, but the code was passing this false value directly to fopen(), which expects a valid path string.

// Before fix - realpath() could return false
$stream = realpath($config['csv']);
$fd = @fopen($stream, 'w+'); // fopen(false, 'w+') fails

Solution

Added validation after the realpath() call to check if the result is false or an empty string, and display a proper "path not found" error message before attempting to call fopen().

// After fix - validate realpath() result
$stream = realpath($config['csv']);

if ($stream === false || $stream === '') {
    $usage(
        $config,
        'path not found: %s',
        $config['csv']
    );
}

$fd = @fopen($stream, 'w+'); // Only called with valid path

Testing

  • ✅ Non-existent files now show proper error: "Error: path not found: non-exist.csv"
  • ✅ Valid files continue to work correctly
  • ✅ File descriptor usage (e.g., --csv 1) continues to work
  • ✅ Minimal change: only 8 lines added, 0 lines removed

Fixes #1068.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/Nyholm/psr7/zipball/a71f2b11690f4b24d099d6b16690a90ae14fc6f3
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5b5e3821314f947dd040c70f7992a64eac89025c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/amphp/amp/zipball/7cf7fef3d667bfe4b2560bc87e67d5387a7bcde9
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/amphp/pipeline/zipball/7b52598c2e9105ebcddf247fc523161581930367
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/amphp/process/zipball/52e08c09dec7511d5fbc1fb00d3e4e79fc77d58d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/amphp/serialization/zipball/693e77b2fb0b266c3c7d622317f881de44ae94a1
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/amphp/socket/zipball/58e0422221825b79681b72c50c47a930be7bf1e1
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/amphp/sync/zipball/217097b785130d77cfcc58ff583cf26cd1770bf1
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/cebe/markdown/zipball/9bac5e971dd391e2802dca5400bbeacbaea9eb86
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/composer/ca-bundle/zipball/d665d22c417056996c59019579f1967dfe5c1e82
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/composer/package-versions-deprecated/zipball/b4f54f74ef3453349c24a845d22392cd31e65f1d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/dflydev/dflydev-dot-access-data/zipball/a23a2bf4f31d3518f3ecb38660c95715dfead60f
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/doctrine/deprecations/zipball/459c2f5dd3d6a4633d3b5f46ee2b1c40f57d3f38
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/doctrine/lexer/zipball/31ad66abc0fc9e1a1f2d9bc6a42668d2fbbcd6dd
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/guzzle/promises/zipball/7c69f28996b0a6920945dd20b3857e499d9ca96c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/guzzle/psr7/zipball/c2270caaabe631b3b44c85f99e5a04bbb8060d16
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/kelunik/certificate/zipball/7e00d498c264d5eb4f78c69f41c8bd6719c0199e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/lanthaler/IRI/zipball/cbd44fa913e00ea624241b38cefaa99da8d71341
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/lanthaler/JsonLD/zipball/537e68e87a6bce23e57c575cd5dcac1f67ce25d8
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/michelf/php-markdown/zipball/eb176f173fbac58a045aff78e55f833264b34e71
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/nette/schema/zipball/da801d52f0354f70a638673c4a0f04e16529431d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/nette/utils/zipball/e67c4061eb40b9c113b218214e42cb5a0dda28f2
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/oscarotero/html-parser/zipball/10f3219267a365d9433f2f7d1694209c9d436c8d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/92dde6a5919e34835c506ac8c523ef095a95ed62
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/679e3ce485b99e84c775d28e2e96fade9a7fb50a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/phpstan/phpstan/zipball/fcf8b71aeab4e1a1131d1783cef97b23a51b87a9
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/revoltphp/event-loop/zipball/09bf1bf7f7f574453efe43044b06fafe12216eb3
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/schmittjoh/metadata/zipball/7ca240dcac0c655eb15933ee55736ccd2ea0d7a6
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c687e3387b99f5b03b6caa64c74b63e2936ff874
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/staabm/side-effects-detector/zipball/d8334211a140ce329c13726d4a715adbddd0a163
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/thephpleague/config/zipball/754b3604fb2984c71f4af4a9cbe7b57f346ec1f3
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/C6dhOY /usr/bin/composer install --no-dev (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/JBMcx2 /usr/bin/composer install --no-interaction (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: colinodell <202034+colinodell@users.noreply.github.com>
Copilot AI changed the title [WIP] tests/benchmark/benchmark.php failed when specifying a non-exist output csv file Fix benchmark.php CSV path validation for non-existent files Jul 20, 2025
Copilot AI requested a review from colinodell July 20, 2025 10:57
@colinodell colinodell marked this pull request as ready for review July 20, 2025 11:06
@colinodell colinodell enabled auto-merge July 20, 2025 11:06
@colinodell colinodell disabled auto-merge July 20, 2025 11:19
@colinodell colinodell merged commit 37d451e into 2.7 Jul 20, 2025
33 checks passed
@colinodell colinodell deleted the copilot/fix-1068 branch July 20, 2025 11:21
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.

tests/benchmark/benchmark.php failed when specifying a non-exist output csv file

2 participants