Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Currently you sometimes have to use --php=path-to-php
in order to let run-tests.sh know where PHP is because the custom crafted code used to automatically detect the php runtime fails on some circumstances.
Plus, the current implementation fails when the PHP runtime definition includes arguments in itself.
Proposed resolution
Use Symfony's PhpExecutableFinder() to find out the current PHP runtime and do not escape the runtime itself when preparing the command.
Remaining tasks
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#42 | 2748883-42.patch | 1.07 KB | neclimdul |
#32 | use_the_php_binary-2748883-32.patch | 2.21 KB | pk188 |
#28 | use_the_php_binary-2748883-28.patch | 1.88 KB | Munavijayalakshmi |
#27 | use_the_php_binary-2748883-27.patch | 1.9 KB | david_garcia |
#19 | use_the_php_binary-2748883-19.patch | 2.08 KB | david_garcia |
Comments
Comment #3
generalredneckThis has been implemented in #2624926: Refactor run-tests.sh for Console component. for Drupal 8. Maybe the effort should be consolidated to there? Unless we feel like there should be a incremental fix.
Comment #4
dawehnerIf #2624926: Refactor run-tests.sh for Console component. is also fixing this, it seems to do too much, doesn't it?
Comment #5
cilefen CreditAttribution: cilefen commentedYes, it seems maybe out of scope. Just a note for anyone fixing this: Unlike in the D7 issue where we must add a conditional for the constant in order to support PHP < 5.4, for D8 we can simply replace the conditional looking for the "_" environment variable with one looking for the constant. Are we interested in (EDITED) deprecating --php as useless?
Comment #6
generalredneckTechnically, having --php around allows you to use a different version of PHP to test against. So for example... if we have php 5.4 as our Global php, we could use php 5.6 to test against by defining --php
With that said, I can see the other side of it... if you want to use php 5.6... run the script in php 5.6... It really depends on how the CI is set up and if it actually uses this script and/or the --php argument when testing patches and commits.
Comment #7
dawehneryou can do the same easily by using the right php binary right from the start. Note: This is a bit of a bad one anyway, as the webserver might still run in a different environment.
Comment #8
cilefen CreditAttribution: cilefen commentedTrue. And we can't just remove --php anyway in case anyone depends on it and it would break existing workflows. But we could toy with deprecating it. But why stress over it, because #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase).
Comment #9
generalredneck@dawehner,
your comment is redundant to what I said in the second part of my comment.
Comment #10
dawehnerOH yeah you are right.
Comment #11
generalredneckRegardless, lets start with having --php in the patch... that will be a starting point and have a patch for those who need this.
Comment #12
Mile23The testbot uses --php to force the php version.
If it's not present, you'd want the same binary as the one you're running under, which isn't always what PHP_BINARY tells you. PHP doesn't set it from the currently-running binary, it sets it through some shell that doesn't see your
.profile
, so it could pick up the wrong one, depending.That's why
getenv('_')
is present, too. We want that. :-)This is also a problem for the simpletest UI runner: #2476139-17: Fix UI test fail in SimpleTestBrowserTest
Don't remove this.
Comment #13
Mile23Comment #14
generalredneckI would like to see a proof of a PHP constant set in a .profile. If you have some documentation of how PHP_BINARY is set, please share.
In fact the _ variable doesn't exist on Windows and a few other Operating Systems without installing shell.
Comment #15
Mile23I mean that if you have two PHP binaries, as you do with a MAMP setup, then you're going to set a path to the MAMP binary in your PATH env. This leads to a problem when PHP is executed by the server, because
exec()
doesn't look at *your* shell dot files, it looks at some shell somewhere's dot files. At least as near as I can tell. Under CLIPHP_BINARY
seems to do the right thing since it's executing as the same user.So I was mistaken about the CLI, having experimented with it a bit.
Comment #16
david_garcia CreditAttribution: david_garcia commentedElaborated on the original patch to make sure the same ini file that was used when calling the tests.
This also unveiled the fact that $php does not need to be escaped when building the shell command, as it is not being used like an argument there.
Comment #18
droplet CreditAttribution: droplet commentedShould we use
\Symfony\Component\Process\PhpExecutableFinder
instead?Comment #19
david_garcia CreditAttribution: david_garcia commented@droplet That is so very true. Let's get rid of this old custom crafted logic.
It also ensure that the php runtime is generated including parameters (such as the php ini file, etc.).
Did not interdiff because the patch is mostly all new.
Comment #20
david_garcia CreditAttribution: david_garcia commentedAnd this is how you make sure this is working as expected:
https://ci.appveyor.com/project/david-garcia-garcia/drupalcore-windows-t...
Comment #21
droplet CreditAttribution: droplet commentedThanks @david_garcia! The patch looks good to me.
Comment #22
david_garcia CreditAttribution: david_garcia commentedFor the same reasons that in #2748883: Use the PHP_BINARY constant in addition to --php in run-tests.sh, tests not working by default in a platform that has > 80% of desktop market share make this major.
Without this fix, the testing script is unable to find the PHP executable on Windows.
Comment #23
david_garcia CreditAttribution: david_garcia commentedComment #24
alexpott@Mile23 has said that we want this. Since @Mile23 helps maintain DrupalCI we probably should have a good reason to remove this. As far as I can see, this change is not actually required to fix the problem. Why not leave that in?
Comment #25
david_garcia CreditAttribution: david_garcia commented@alexpott, @Mile23 PhpExecutableFinder() has a more elaborate logic to detect the php runtime, and it makes sense to use an upstream tool to do this.
It's true that PhpExecutableFinder() does not consider getenv('_'). Looking at the implementation, PHP_BINARY is only used when running in cli, cli-server and phpdbg, plus it has additional checks. So it looks they added some logic to ensure that PHP_BINARY is only used when it is trully reliable.
If something is broken or no totally correct in PhpExecutableFinder() it would make more sense to fix that upstream, as PhpExecutableFinder() is used in other places of Drupal core.
Comment #26
alexpott@david_garcia but the use of _ is specific to run-tests so not appropriate for an upstream fix - because PhpExecutableFinder is designed to work regardless of SAPI where run-tests.sh is designed to work from the CLI where the _ environment variable will be set on linux.
Comment #27
david_garcia CreditAttribution: david_garcia commentedBrought back evnget('_'). Don't really like it, but will do no harm.
Comment #28
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedRerolled the patch.
Comment #29
droplet CreditAttribution: droplet commentedRTBC again. This is useful for Windows.
Comment #30
alexpottI really don't know why we're removing this. It was added in #311160: Enhance run_tests.sh by automatically using right php interpreter and it is not part of doing better detection. I'm all for better detection on windows but there's no need to make unnecessary changes to a script that is used in people's build processes. There's no comment as to why this is breaking anything. As far as I can see, it is not. What is fixing things is the use of Symfony's php executable finder.
The indentation is incorrect here.
Comment #31
droplet CreditAttribution: droplet commentedHmm. I think we should put SUDO_COMMAND after PhpExecutableFinder as the last attempt if we still want to keep it.
For example, if we must run with sudo on the previous command but PHP does not.
(so this is a bug acutally)
And I guess it explained why only run-tests.sh on scripts folder missing
#!/usr/bin/env php
. So people don't run:sudo bash ./run-tests.sh
Comment #32
pk188 CreditAttribution: pk188 at OpenSense Labs commentedFixed #30
Comment #33
alexpottLet's not change this order.
Also @pk188 that's not quite what @droplet was suggesting. However I think doing the smallest possible change here is advisable and not worry too much about SUDO_COMMAND and whether it works.
Let's just use Symfony's thing in the else case and be done.
Comment #34
droplet CreditAttribution: droplet commentedSKIPPED THE PATCH, SEE NEXT COMMENT
OK. Not well coded but it works.
I suggested dropping a @deprecated and @todo over there to remove it at some point. ( I didn't add to current patch )
_ and SUDO_COMMAND was a hack to cheating while we do not PHP_BINARY in the old day (Just introduced from
PHP5.2PHP5.4)Comment #35
droplet CreditAttribution: droplet commentedComment #38
Mile23You know how phpunit does it?
SebastianBergmann\Environment\Runtime->getBinary()
which uses both$_SERVER['_']
andPHP_BINARY
.Experimentation tells me that this runs into the problem of double
escapeshellarg()
in combination withrun-tests.sh
.Therefore if we want to benefit from not having to maintain this hunk of code in the future, we should rename
global $php
toglobal $escaped_php
, adjustsimpletest_script_command()
to acknowledge that it's already escaped, and rawk on.Now, will it blend? Let's find out. I had a problem with lots of failing tests locally with unmodified run-tests.sh, so I'm not sure what will happen here.
If it explodes too much, please ignore. :-)
run-tests.sh already warns the user if phpunit is not available, but sebastianbergmann/environment isn't, strictly speaking, the same as phpunit. We might need to explicitly declare it as a dev dependency. Or not.
Comment #42
neclimdulyowza, means if you use have multiple version of php installed you call different versions and run the
quitesuite against different verions :( :(. The indeed is major.Things at least in the simpletest.module code have changed quite a bit but for the better, specifically fixing the Windows bug in #22, just linux didn't get the fix. We can just use the same code that makes windows work to resolve the php executable for all platforms and that should take care of it.
I've no idea what's going on in run-tests though so... maybe this is all that's needed now since everything is getting switched to phpunit tests?
Comment #52
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
With simpletest being removed in D10 is this still relevant?
If so please update IS with the rescope.