Problem/Motivation

#2244447: Translation of low-level info/annotations leads to circular dependencies introduced \Drupal\Core\StringTranslation\TranslationWrapper, which implements __toString() in order to be usable with code that expects strings. However, strpos() doesn't cast values to strings, but does a type check first and if the needle is not a string, it casts it to an integer. This causes some web tests to fail, as WebTestBase::assertText() uses strpos() internally.

Proposed resolution

Explicitly cast the needle to a string in WebTestBase::assertText(), as the $text parameter is documented as being text anyway.

Remaining tasks

None.

User interface changes

None.

API changes

None.

CommentFileSizeAuthor
#6 drupal_2282453_6.patch766 bytesXano
#1 drupal_2282453_1.patch1.45 KBXano
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Xano’s picture

Status: Active » Needs review
FileSize
1.45 KB
sun’s picture

The type-cast makes sense to me, but the phpDoc adjustment slightly seems to contradict the functional change? ;)

Xano’s picture

The argument was supposed to be a string anyway, so the patch also makes that clear on top of the actual change, just so people don't figure they can use integers, because the code uses strpos() internally anyway.

alexpott’s picture

I agree with @sun the phpDoc does not make sense - now it is a string or and object the implements __toString().

Xano’s picture

If we follow that reasoning, we would never be allowed to type hint on strings, as any object can implement __toString() and pretend to be a string.

Xano’s picture

FileSize
766 bytes

I just want to see this fixed, as this breaks my tests. I won't block this on documentation changes.

realityloop’s picture

Status: Needs review » Reviewed & tested by the community

this is straighforward, logical, and passes tests.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

Status: Fixed » Closed (fixed)

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