[plugin_platform_interface] Update README and add a test (#4652)
diff --git a/packages/plugin_platform_interface/CHANGELOG.md b/packages/plugin_platform_interface/CHANGELOG.md
index ac6f247..4f49842 100644
--- a/packages/plugin_platform_interface/CHANGELOG.md
+++ b/packages/plugin_platform_interface/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 2.1.2
+
+* Updates README to demonstrate `verify` rather than `verifyToken`, and to note
+ that the test mixin applies to fakes as well as mocks.
+* Adds an additional test for `verifyToken`.
+
## 2.1.1
* Fixes `verify` to work with fake objects, not just mocks.
diff --git a/packages/plugin_platform_interface/README.md b/packages/plugin_platform_interface/README.md
index 2fe4432..1b1f804 100644
--- a/packages/plugin_platform_interface/README.md
+++ b/packages/plugin_platform_interface/README.md
@@ -25,7 +25,7 @@
/// Platform-specific plugins should set this with their own platform-specific
/// class that extends [UrlLauncherPlatform] when they register themselves.
static set instance(UrlLauncherPlatform instance) {
- PlatformInterface.verifyToken(instance, _token);
+ PlatformInterface.verify(instance, _token);
_instance = instance;
}
@@ -35,14 +35,15 @@
This guarantees that UrlLauncherPlatform.instance cannot be set to an object that `implements`
UrlLauncherPlatform (it can only be set to an object that `extends` UrlLauncherPlatform).
-## Mocking platform interfaces with Mockito
+## Mocking or faking platform interfaces
-Mockito mocks of platform interfaces will fail the verification done by `verifyToken`.
-This package provides a `MockPlatformInterfaceMixin` which can be used in test code only to disable
-the `extends` enforcement.
+Test implementations of platform interfaces, such as those using `mockito`'s
+`Mock` or `test`'s `Fake`, will fail the verification done by `verify`.
+This package provides a `MockPlatformInterfaceMixin` which can be used in test
+code only to disable the `extends` enforcement.
-A Mockito mock of a platform interface can be created with:
+For example, a Mockito mock of a platform interface can be created with:
```dart
class UrlLauncherPlatformMock extends Mock
diff --git a/packages/plugin_platform_interface/pubspec.yaml b/packages/plugin_platform_interface/pubspec.yaml
index fdb1e4c..e73d520 100644
--- a/packages/plugin_platform_interface/pubspec.yaml
+++ b/packages/plugin_platform_interface/pubspec.yaml
@@ -15,7 +15,7 @@
# be done when absolutely necessary and after the ecosystem has already migrated to 2.X.Y version
# that is forward compatible with 3.0.0 (ideally the ecosystem have migrated to depend on:
# `plugin_platform_interface: >=2.X.Y <4.0.0`).
-version: 2.1.1
+version: 2.1.2
environment:
sdk: ">=2.12.0 <3.0.0"
diff --git a/packages/plugin_platform_interface/test/plugin_platform_interface_test.dart b/packages/plugin_platform_interface/test/plugin_platform_interface_test.dart
index 8775873..d36f21c 100644
--- a/packages/plugin_platform_interface/test/plugin_platform_interface_test.dart
+++ b/packages/plugin_platform_interface/test/plugin_platform_interface_test.dart
@@ -63,6 +63,21 @@
class ExtendsVerifyTokenPluginPlatform extends VerifyTokenPluginPlatform {}
+class ConstVerifyTokenPluginPlatform extends PlatformInterface {
+ ConstVerifyTokenPluginPlatform() : super(token: _token);
+
+ static const Object _token = Object(); // invalid
+
+ static set instance(ConstVerifyTokenPluginPlatform instance) {
+ PlatformInterface.verifyToken(instance, _token);
+ }
+}
+
+class ImplementsConstVerifyTokenPluginPlatform extends PlatformInterface
+ implements ConstVerifyTokenPluginPlatform {
+ ImplementsConstVerifyTokenPluginPlatform() : super(token: const Object());
+}
+
void main() {
group('`verify`', () {
test('prevents implementation with `implements`', () {
@@ -112,5 +127,10 @@
test('allows extending', () {
VerifyTokenPluginPlatform.instance = ExtendsVerifyTokenPluginPlatform();
});
+
+ test('does not prevent `const Object()` token', () {
+ ConstVerifyTokenPluginPlatform.instance =
+ ImplementsConstVerifyTokenPluginPlatform();
+ });
});
}