Problem/Motivation

As title

Proposed resolution

Example:

-    $this->assertTrue(is_string($settings['ajaxPageState']['theme_token']));
+    $this->assertIsString($settings['ajaxPageState']['theme_token']);

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

jungle created an issue. See original summary.

jungle’s picture

Title: Replace assertions involving calls to is_string() assertIsString()/assertIsNotString() » Replace assertions involving calls to is_string() with assertIsString()/assertIsNotString()
mero.s’s picture

Status: Active » Needs review
StatusFileSize
new9.76 KB

Please review patch.

jungle’s picture

StatusFileSize
new9.2 KB
new8.35 KB

Thanks @mero.S!

Checked on my local with regex assert.+is_string, found no more assertions to replace.

Did not mention to remove redundant assertion messages in the IS, my bad, removing it myself.

quietone’s picture

Status: Needs review » Reviewed & tested by the community

Used the regex mentioned in #4 to get a list of all occurances, there were 33. Then applied the patch and ran the grep again, and 19 still found. The 19 are asserts and not subject to change here.As jungle says above, 'found no more assertions to replace.

Also reviewed the patch and found no problems, also all assertion messages removed.

  • catch committed 0dfb1d0 on 9.1.x
    Issue #3131820 by jungle, mero.S, quietone: Replace assertions involving...

  • catch committed 63671bc on 9.0.x
    Issue #3131820 by jungle, mero.S, quietone: Replace assertions involving...
catch’s picture

Title: Replace assertions involving calls to is_string() with assertIsString()/assertIsNotString() » [backport] Replace assertions involving calls to is_string() with assertIsString()/assertIsNotString()
Version: 9.1.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Needs work

Committed/pushed to 9.1.x and 9.0.x, thanks!

Needs a backport for 8.9.x

mondrake’s picture

jungle’s picture

Status: Needs work » Needs review
StatusFileSize
new590 bytes
new9.19 KB

A patch for 8.9.x

Status: Needs review » Needs work

The last submitted patch, 10: 3131820-8.9.x-10.patch, failed testing. View results

jungle’s picture

Status: Needs work » Needs review

Testing failed as expected, see #9 for reasons.

mondrake’s picture

Status: Needs review » Postponed
mondrake’s picture

Status: Postponed » Needs review

Blocker is in.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

#10 is passing on D8.9 now.

xjm’s picture

Title: [backport] Replace assertions involving calls to is_string() with assertIsString()/assertIsNotString() » Replace assertions involving calls to is_string() with assertIsString()/assertIsNotString()
Status: Reviewed & tested by the community » Fixed
+++ b/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataTest.php
@@ -73,7 +73,7 @@ public function testGetAndSet() {
-    $this->assertTrue(is_string($typed_data->getString()), 'Boolean value was converted to string');

@@ -91,7 +91,7 @@ public function testGetAndSet() {
-    $this->assertTrue(is_string($typed_data->getString()), 'String value was converted to string');

@@ -107,7 +107,7 @@ public function testGetAndSet() {
-    $this->assertTrue(is_string($typed_data->getString()), 'Integer value was converted to string');

@@ -124,7 +124,7 @@ public function testGetAndSet() {
-    $this->assertTrue(is_string($typed_data->getString()), 'Float value was converted to string');

@@ -229,7 +229,7 @@ public function testGetAndSet() {
-    $this->assertTrue(is_string($typed_data->getString()), 'DurationIso8601 value was converted to string');

@@ -253,7 +253,7 @@ public function testGetAndSet() {
-    $this->assertTrue(is_string($typed_data->getString()), 'Time span value was converted to string');

These removed assertion messages are adding information about what's going on in the test: That these are conversions of various specific data types to a string. You can still mostly understand this from the surrounding inline comments, but if we do more work removing assertion messages from this file, we're going to need to add some comments.

Since this is a backport and it's mostly OK, I'm going to go ahead and commit the 8.9.x patch. Just remember to be careful about not losing information from the test when we get rid of static assertion messages. Thanks

mondrake’s picture

Status: Fixed » Reviewed & tested by the community

not pushed?

xjm’s picture

Status: Reviewed & tested by the community » Fixed

Good catch. Apparently my push was rejected earlier with a bunch of access denied errors from GitLab... reommitted now. Thanks!

  • xjm committed dcb356d on 8.9.x
    Issue #3131820 by jungle, mero.S, quietone, catch: Replace assertions...
mondrake’s picture

#18 sometimes there is quite a delay between a push and the appearance of the 'committed' comment on the issue itself. I've seen that myself on projects I maintain. But can's find a reason for that.

Status: Fixed » Closed (fixed)

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