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

Running a binary from a script with @php fails on Windows #11490

Closed
gilbertsoft opened this issue Jun 1, 2023 · 2 comments
Closed

Running a binary from a script with @php fails on Windows #11490

gilbertsoft opened this issue Jun 1, 2023 · 2 comments
Labels
Milestone

Comments

@gilbertsoft
Copy link

gilbertsoft commented Jun 1, 2023

My composer.json:

{
	"name": "vendor/package",
	"description": "",
	"require": {
		"php": "^7.4 || ^8.0",
		"phpunit/phpunit": "^8.5.14 || ^9.5.5"
	},
	"require-dev": {
		"composer/composer": "^2.0",
		"phpspec/prophecy-phpunit": "^1.1 || ^2.0.2"
	},
	"minimum-stability": "dev",
	"prefer-stable": true,
	"scripts": {
		"tools:tests:unit": "@php phpunit --testsuite \"Unit Test Suite\""
	}
}

Output of composer diagnose:

Checking platform settings: OK
Checking git settings: OK git version 2.40.1
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com oauth access: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 2.5.7
PHP version: 8.1.10
PHP binary path: C:\PHP\current\php.exe
OpenSSL version: OpenSSL 1.1.1q  5 Jul 2022
cURL version: 7.77.0 libz 1.2.12 ssl OpenSSL/1.1.1q
zip: extension present, unzip not available, 7-Zip present (7z)

When I run this command:

composer ci:tests:unit -vvv

I get the following output:

> tools:tests:unit: @php phpunit --testsuite "Unit Test Suite"
Executing command (CWD): C:\PHP\current\php.exe -d allow_url_fopen=1 -d disable_functions="" -d memory_limit=1536M C:\Users\<my user>\Dev\PhpDevTools\phpunit-tools\vendor\bin\phpunit.BAT --testsuite "Unit Test Suite"
@ECHO OFF
setlocal DISABLEDELAYEDEXPANSION
SET BIN_TARGET=%~dp0/phpunit
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
php "%BIN_TARGET%" %*

And I expected this to happen:

Instead of running the phpunit binary, the content of the proxy file phpunit.bat is printed. The problem is located in the EventDispatcher (

// match somename (not in quote, and not a qualified path) and if it is not a valid path from CWD then try to find it
// in $PATH. This allows support for `@php foo` where foo is a binary name found in PATH but not an actual relative path
$matched = Preg::isMatchStrictGroups('{^[^\'"\s/\\\\]+}', $pathAndArgs, $match);
if ($matched && !file_exists($match[0])) {
$finder = new ExecutableFinder;
if ($pathToExec = $finder->find($match[0])) {
$pathAndArgs = $pathToExec . substr($pathAndArgs, strlen($match[0]));
}
}
) where the .BAT extension is added.

A quick workaround for me was to define the full relative path to the phpunit:

"scripts": {
	"tools:tests:unit": "@php vendor/bin/phpunit --testsuite \"Unit Test Suite\""
}

Discovered today while running CI on a Windows runner at GH, works fine on Linux and Mac, see workflow run (https://github.com/PhpDevTools/phpunit-tools/actions/runs/5142833446/jobs/9258327038), step Unit Tests.

@gilbertsoft gilbertsoft changed the title Running a binary from a script with @php fails on Winddows Running a binary from a script with @php fails on Windows Jun 1, 2023
@Seldaek
Copy link
Member

Seldaek commented Jun 6, 2023

Weird tho that it wouldn't find it in the PATH with phpunit, because I assume both phpunit and phpunit.bat exist..

In any case we probably should fix this if possible because executing a .bat with php never makes sense.

@Seldaek Seldaek added the Bug label Jun 6, 2023
@Seldaek Seldaek added this to the 2.5 milestone Jun 6, 2023
@Seldaek Seldaek closed this as completed in 3ae662f Jun 9, 2023
@gilbertsoft
Copy link
Author

Thanks for the quick fix @Seldaek . I can confirm, with 2.5.8 it works like expected now on Windows.

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

No branches or pull requests

2 participants