When the test suite is run on PHP 7.3, there is a warning due to changes in PHP 7.3:

exception: [Deprecated] Line 3015 of modules/simpletest/drupal_web_test_case.php:
strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

If the second parameter (needle) of the strpos call is an integer, PHP uses the chr() value of that integer, which is likely not the intended behavior. Because of this, PHP now warnings when it sees an integer. The caller is now responsible to call chr() if intended.

CommentFileSizeAuthor
#14 3020771.patch1.69 KBpol
#8 3020771-8.patch1.7 KBpol
#4 3020771-4.patch657 bytesayesh
#2 3020771-2.patch639 bytesayesh

Comments

Ayesh created an issue. See original summary.

ayesh’s picture

StatusFileSize
new639 bytes
ayesh’s picture

Assigned: ayesh » Unassigned
ayesh’s picture

StatusFileSize
new657 bytes
sjerdo’s picture

Status: Active » Needs work

I don't think the latest patch is the intended behavior for assertRaw. The method is for checking if a value is displayed at the page result. New behavior checks if the chr result is displayed, which doesn't equal the integer. E.g. chr(98) equals 'b'

Also this fix doesn't check for other types like floats. For instance in the following test is assert that floating number -1234.56 is displayed at the page: https://cgit.drupalcode.org/drupal/tree/modules/field/modules/number/num...

To avoid this and keep the current behavior we should cast the second argument passed to strpos ($raw) to a string.

ayesh’s picture

Hello @sjerdo thanks for your reply
My first patch in #2 was with an explicit string cast, but it had a few test failures.

The second patch (#4) didn't fix the PHP warning with strpos() either. I will try a few more approaches later today.

sjerdo’s picture

Hi @Ayesh, my guess is the patch in #2 is correct and the failing test may be broken all along.
Just tried the strpos() method for a float needle and it seems like the decimals aren't accounted for! Check this test code snippet: https://3v4l.org/sT9CU
Seems like the test without string cast accepts all texts containing a dot.

pol’s picture

Status: Needs work » Needs review
StatusFileSize
new1.7 KB

Hi all,

I'm testing the patches locally and I re-rolled a version of the patch.

I will consolidate all the PHP 7.3 patches in a custom project of mine that you can find here: https://github.com/drupol/dockerdrupal7runnerngninxphpfpm

Basically, it allows you to test D7 with docker without changing anything locally.
With only 3 commands, you can get a D7 site setup with PHP 7.3.

Feel free to use it!

sjerdo’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me! +1
The check in method assertRaw is now correct for decimal numbers and the bug in the number test has been fixed.

sjerdo’s picture

Did a quick check in D8: This bug has already been fixed there: #2279339: NumberFieldTest is slightly and subtly broken

mfb’s picture

👍 Looks good to me, I reran the 7.3 tests and now down to just #3009351: "session_id(): Cannot change session id"

pol’s picture

Assigned: Unassigned » pol
Issue tags: +Pending Drupal 7 commit

Cool ! Moving this forward.

fabianx’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/modules/field/modules/number/number.test
@@ -69,7 +69,7 @@ class NumberFieldTestCase extends DrupalWebTestCase {
-    $this->assertRaw(round($value, 2), 'Value is displayed.');
+    $this->assertRaw(round($value, 4), 'Value is displayed.');

We should be fixing this in the same way as Drupal 8 did, e.g. just removing the round completely to match code and make further syncs easier.

The rest is good to go though.

pol’s picture

Status: Needs work » Needs review
StatusFileSize
new1.69 KB

Patch updated based on feedback from #13.

sjerdo’s picture

Status: Needs review » Reviewed & tested by the community

Looking good!

pol’s picture

Updating credits.

  • Pol committed 9661e7c on 7.x
    Issue #3020771 by Ayesh, Pol, sjerdo: [PHP 7.3] strpos explicit string...
pol’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

joseph.olstad’s picture

Assigned: pol » Unassigned
Issue tags: -Pending Drupal 7 commit

This is fixed, thanks again everyone!

Removing the pending commit tag (it was already committed).