-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Forbid ... implements UrlLauncherPlatform
#2230
Conversation
ac24fc4 to
6c1906a
Compare
| }, throwsA(isInstanceOf<AssertionError>())); | ||
| }); | ||
|
|
||
| test('Can be mocked with `implements', () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a backtick here
There was a problem hiding this comment.
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', () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
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;
}
```
…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) { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
|
@goderbauer suggested that instead of having the mock implement isMock, it could implement |
@Hixie If the underlying concern here is developers ignoring the |
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;
}
```
…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
Description
Fail setting
UrlLauncherPlatform.instanceto something thatimplements(rather thanextends)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
extendit.We leave a backdoor for mockito mocks which can do:
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.///).flutter analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?