Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@amirh
Copy link
Contributor

@amirh amirh commented Oct 23, 2019

Description

Fail setting UrlLauncherPlatform.instance to something that implements (rather than extends) UrlLauncherPlatform.

I'm not bumping the major version as the breaking change policy for platform interface is that we're only guaranteeing to not break classes that extend it.

We leave a backdoor for mockito mocks which can do:

class MockUrlLauncherPlatform extends Mock
    implements UrlLauncherPlatform {}

test('', () {
  MockUrlLauncherPlatform mock = MockUrlLauncherPlatform();
  when(mock.isMock).thenReturn(true);
  UrlLauncherPlatform.instance = mock;
}

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See [Contributor Guide]).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the [Flutter Style Guide].
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy].
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the [CLA].
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@amirh amirh force-pushed the forbid_implements branch from ac24fc4 to 6c1906a Compare October 23, 2019 18:34
}, throwsA(isInstanceOf<AssertionError>()));
});

test('Can be mocked with `implements', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a backtick here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

UrlLauncherPlatform.instance = mock;
});

test('Can be exteneded', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/// other than mocks (see class docs). This property provides a backdoor for mockito mocks to
/// skip the verification that the class isn't implemented with `implements`.
@visibleForTesting
bool get isMock => false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of this functionality will be shared across many plugins. Should it be a mixin or base class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed flutter/flutter#43368 and added a TODO (we will have to wait for a stable release before we can use common framework code for this)

@amirh amirh merged commit a68932e into flutter:master Oct 23, 2019
@amirh amirh deleted the forbid_implements branch October 23, 2019 21:06
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2019
…2228)

* [url_launcher] Use `url_launcher_platform_interface` to handle calls

* Exclude platform interface from all-plugins-app

* Update now that #2230 has landed
mormih pushed a commit to mormih/plugins that referenced this pull request Nov 17, 2019
Fail setting `UrlLauncherPlatform.instance` to something that `implements` (rather than `extends`) `UrlLauncherPlatform`.

I'm not bumping the major version as the breaking change policy for platform interface is that we're only guaranteeing to not break classes that `extend` it.

We leave a backdoor for mockito mocks which can do:
```dart
class MockUrlLauncherPlatform extends Mock
    implements UrlLauncherPlatform {}

test('', () {
  MockUrlLauncherPlatform mock = MockUrlLauncherPlatform();
  when(mock.isMock).thenReturn(true);
  UrlLauncherPlatform.instance = mock;
}
```
mormih pushed a commit to mormih/plugins that referenced this pull request Nov 17, 2019
…lutter#2228)

* [url_launcher] Use `url_launcher_platform_interface` to handle calls

* Exclude platform interface from all-plugins-app

* Update now that flutter#2230 has landed

// TODO(amirh): Extract common platform interface logic.
// https://github.com/flutter/flutter/issues/43368
static set instance(UrlLauncherPlatform instance) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: style guide gives the order for getters/setters as "getter/field/setter" with no whitespace between them

static set instance(UrlLauncherPlatform instance) {
if (!instance.isMock) {
try {
instance._verifyProvidesDefaultImplementations();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be in an assert so it doesn't run in release builds

@Hixie
Copy link
Contributor

Hixie commented Nov 26, 2019

@goderbauer suggested that instead of having the mock implement isMock, it could implement _verifyProvidesDefaultImplementations using noSuchMethod.

@collinjackson
Copy link
Contributor

@goderbauer suggested that instead of having the mock implement isMock, it could implement _verifyProvidesDefaultImplementations using noSuchMethod.

@Hixie If the underlying concern here is developers ignoring the @visibleForTesting annotation I've proposed a fix for that in #2326

sungmin-park pushed a commit to sungmin-park/flutter-plugins that referenced this pull request Dec 17, 2019
Fail setting `UrlLauncherPlatform.instance` to something that `implements` (rather than `extends`) `UrlLauncherPlatform`.

I'm not bumping the major version as the breaking change policy for platform interface is that we're only guaranteeing to not break classes that `extend` it.

We leave a backdoor for mockito mocks which can do:
```dart
class MockUrlLauncherPlatform extends Mock
    implements UrlLauncherPlatform {}

test('', () {
  MockUrlLauncherPlatform mock = MockUrlLauncherPlatform();
  when(mock.isMock).thenReturn(true);
  UrlLauncherPlatform.instance = mock;
}
```
sungmin-park pushed a commit to sungmin-park/flutter-plugins that referenced this pull request Dec 17, 2019
…lutter#2228)

* [url_launcher] Use `url_launcher_platform_interface` to handle calls

* Exclude platform interface from all-plugins-app

* Update now that flutter#2230 has landed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants