This is a follow-on from #3109923: Deprecation: add $defaultTheme - create FormWidgetBrowserTestBase class where the scope of the original problem expanded. When that issue is complete then this can be worked on. See comments #6 to #10 for the background.

Issue fork typed_data-3110650

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jonathan1055 created an issue. See original summary.

jonathan1055’s picture

jonathan1055’s picture

Status: Postponed » Active

and I forgot the vital change

jonathan1055’s picture

Checking back with the problems we found on #3109923: Deprecation: add $defaultTheme - create FormWidgetBrowserTestBase class, in summary

  1. If our WidgetBrowserTestBase has protected function setUp($widgetId): void { we get the error that it does not match with BrowserTestBase: Declaration of Drupal\Tests\typed_data\Functional\TypedDataFormWidget\FormWidgetBrowserTestBase::setUp($widgetId) should be compatible with Drupal\Tests\BrowserTestBase::setUp() which means we have to have a default value for $widgetId
  2. Therefore we need it be protected function setUp($widgetId = ''): void {, which causes the error that the individual test's setup() do not match our WidgetBrowserTestBase: Declaration of Drupal\Tests\typed_data\Functional\TypedDataFormWidget\DatetimeWidgetTest::setUp(): void should be compatible with Drupal\Tests\typed_data\Functional\TypedDataFormWidget\FormWidgetBrowserTestBase::setUp($widgetId = ''): void
  3. One solution to this is for the separate test classes to have
    protected function setUp($widgetId = 'datetime'): void {
        parent::setUp($widgetId);
      }
    

    This actually runs fine, but we get a coding standard failure for each one, stating:

    Possible useless method overriding detected (Generic.CodeAnalysis.UselessOverridingMethod.Found)
    
  4. Therefore I propose that instead of trying to create the widget directly in the base class setUp() we simply have a new function defined in the base class protected function createWidget($widgetId): void { and this can be called from the setUp() of each test class. This runs fine, has no coding standards faults and keeps the definition of the $widgetID and $widget properties and the creation of the widget all within the base class.

I moved the createUser and login into this function too, just for convenience, as we do not now have a setUp() in FormWidgetBrowserTestBase. But if you would prefer, I can create that setUp and move the single line login into it.

tr’s picture

StatusFileSize
new7.76 KB

This moves the createUser() into the Base setUp() and eliminates the widgetId property which isn't really needed.

jonathan1055’s picture

Just a question, if we are working on this together then we need to agree how. I created a MR but you have provided a patch without interdiff. If you want to work with patches that ok, I just need to know.

jonathan1055’s picture

StatusFileSize
new7.45 KB

Your changes look good. For the record, I have uploaded that interdiff. Yes that widgetId property is not needed. It was a remnant from my previous work on the preceding issue #3109923: Deprecation: add $defaultTheme - create FormWidgetBrowserTestBase class. Also moving the createUser() into a new base setUp() is much better than having it in the createWidget(). I had wondered about doing that myself.

I spotted one unnecessary 'drupalLogin(...createUser()' which I will remove in the next patch.

jonathan1055’s picture

StatusFileSize
new8.12 KB
new679 bytes

Patch to remove the unnecessary login & createUser. When this passes I am happy for this to be RTBC if you are.

tr’s picture

StatusFileSize
new8.12 KB
new709 bytes

The MR needs to be rebased and the UI gives me an error message when I try, so back to the patch ...

I made a spelling change to what you have in #10, but otherwise this is the same. I just want to re-test to be sure before I commit.

  • TR committed 8e68a884 on 8.x-1.x authored by jonathan1055
    Issue #3110650 by jonathan1055, TR: Move creation of $widget into...
tr’s picture

Status: Needs review » Fixed

Committed.

jonathan1055’s picture

The message above was automatically duplicated from the MR.
Thanks for the commit. I have unpostponed #3110036: Create assertIsApplicable() and assertIsNotApplicable() in widget base class

Status: Fixed » Closed (fixed)

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