Problem/Motivation

Every time we need a lowercase machine name in tests we have to type Unicode::strtolower($this->randomMachineName())

Proposed resolution

Add a new parameter to RandomGeneratorTrait::randomMachineName():

  protected function randomMachineName($length = 8, $lowercase = FALSE) {
    ...
  }

OR

Add a new method to RandomGeneratorTrait:

  protected function randomLowercaseMachineName($length = 8) {
    ...
  }

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Feature because adds some DX shorthand when writing tests.
Issue priority Not critical because without this tests are not affected. Unicode::strtolower($this->randomMachineName()) can be used instead.
Disruption No disruption.
CommentFileSizeAuthor
#40 interdiff-38-40.txt1.78 KBAnonymous (not verified)
#40 2556711-40.patch3.07 KBAnonymous (not verified)
#38 2556711-38.patch3.05 KBAnonymous (not verified)
#7 2556711-7.patch11.99 KBclaudiu.cristea
#7 interdiff.txt9.22 KBclaudiu.cristea
#6 interdiff.txt1.03 KBclaudiu.cristea
#6 2556711-6.patch2.77 KBclaudiu.cristea
#3 2556711-3.patch1.75 KBclaudiu.cristea

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

claudiu.cristea’s picture

Status: Postponed » Needs review
StatusFileSize
new1.75 KB

I implemented both.

claudiu.cristea’s picture

Priority: Normal » Minor
Issue summary: View changes
Issue tags: +DX (Developer Experience)

This is minor but adds a DX improvement. Added beta evaluation.

dawehner’s picture

Do you mind converting over at least some of the usecases?

claudiu.cristea’s picture

StatusFileSize
new2.77 KB
new1.03 KB

Yes, of course.

claudiu.cristea’s picture

StatusFileSize
new9.22 KB
new11.99 KB

Added more cases (but not all).

claudiu.cristea’s picture

I can change all occurrences. Should I?

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

I think its enough for now

claudiu.cristea’s picture

jibran’s picture

It is a test only change and a non disruptive one why not make it a normal task?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: 2556711-7.patch, failed testing.

claudiu.cristea’s picture

That was a random failure.

Status: Needs work » Needs review

claudiu.cristea queued 7: 2556711-7.patch for re-testing.

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

Setting back to RTBC as per #9.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: 2556711-7.patch, failed testing.

Status: Needs work » Needs review

claudiu.cristea queued 7: 2556711-7.patch for re-testing.

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

It was a random bot failure. Back to RTBC as per #9.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: 2556711-7.patch, failed testing.

Status: Needs work » Needs review

claudiu.cristea queued 7: 2556711-7.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 7: 2556711-7.patch, failed testing.

klausi’s picture

Nope, we should not add yet another random() method. Instead, we should deprecate all random values in tests and convert to hard coded strings, see #2571183: Deprecate random() usage in tests to avoid random test failures.

Status: Needs work » Needs review

claudiu.cristea queued 7: 2556711-7.patch for re-testing.

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

Moving this back to RTBC based on #9 till #22 will get an approval.

klausi’s picture

We have agreement in the other issue and I talked to alexpott at Drupalcon who agrees to not use random functions where we can.

Adding another method means we need to deprecate another method later, so I would not do that.

Also, since you should not use random*() methods in tests nobody is supposed to use this new method.

Leaving status unchanged for other opinions, if you agree with me let's close this as "won't fix".

dawehner’s picture

I agree with the idea to not longer use random strings, given the problems, especially in the debugging way of things. Given that this particular issue would be certainly won't fix.

claudiu.cristea’s picture

IMO, we need random, arbitrary strings. I'm against deprecating this the use of random*(). As I see in #2571183: Deprecate random() usage in tests to avoid random test failures there's no a final agreement on removing random* stuff. @dawehner expresses his agreement partially but he's arguing also to maintain the random strings. If you look at the random name generator you can find that is safe enough, there's no risk of overlapping in the way it's designed.

This patch adds only a DX short-hand. If we gonna drop TOTALLY the random stiff it would be easy to drop this too. If not, we keep also this short-hand to help developers write tests more easy.

claudiu.cristea’s picture

Ouch! Cross posting.

pwolanin’s picture

Status: Reviewed & tested by the community » Needs work

Can we just fix the original method to return lower case instead of adding another one?

claudiu.cristea’s picture

Of course we can but what if a test needs case variation? I don't know a use-case right now.

pwolanin’s picture

If they need case variation they can use one of the other random methods

claudiu.cristea’s picture

@pwolanin, but what if there are tests in place? How do we know which of them need case variation?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anonymous’s picture

Status: Needs work » Needs review
Related issues: +#2972573: randomMachineName() should conform to processMachineName() pattern
StatusFileSize
new3.05 KB

I closed #2972573: randomMachineName() should conform to processMachineName() pattern, because its purpose is to solve the same problem. The issue describes few cases when randomMachineName() should contains only lower case, instead of use new randomLowercaseMachineName(). Otherwise we potentially have many places with random fails + inconvenient testing expected/actual asserts.

But we also cann't use strtolower inside of randomMachineName(). Because randomMachineName() use Random::name(..., unique = TRUE). But name() check unique value with case-sensitive.

So, what about next variant: implement id(), and use it inside of randomMachineName()?

Status: Needs review » Needs work

The last submitted patch, 38: 2556711-38.patch, failed testing. View results

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new3.07 KB
new1.78 KB
dawehner’s picture

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jonathanshaw’s picture

Adding a parameter to the existing method, rather than a new method, seems harmless, even if #2571183: Deprecate random() usage in tests to avoid random test failures ever went ahead which is highly uncertain.

krzysztof domański’s picture

Status: Needs review » Closed (won't fix)

1. Unicode::strtolower is deprecated. Use mb_* functions instead of Unicode::* methods

Current:
strtolower($this->randomMachineName())
Clear message "it returns lowercase". Helpful when viewing the patch in the browser. When you see it, you know what's going on.

Proposed:
$this->randomMachineName(8, TRUE)
Less understandable code. You need to know the parameters of the method to know what this method returns.
In this case, the first argument must be set.

jonathanshaw’s picture