mirror of
https://github.com/Iconica-Development/flutter_data_interface.git
synced 2025-05-18 18:33:45 +02:00
Merge branch 'fix/add_ci_linter'
This commit is contained in:
commit
f31d873c1b
6 changed files with 86 additions and 38 deletions
14
.github/workflows/compponent-ci.yml
vendored
Normal file
14
.github/workflows/compponent-ci.yml
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
name: Iconica Standard Component CI Workflow
|
||||
# Workflow Caller version: 2.0.0
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
call-global-iconica-workflow:
|
||||
uses: Iconica-Development/.github/.github/workflows/component-ci.yml@master
|
||||
secrets: inherit
|
||||
permissions: write-all
|
||||
with:
|
||||
subfolder: "." # add optional subfolder to run workflow in
|
|
@ -1,3 +1,7 @@
|
|||
## 1.0.1
|
||||
|
||||
- Added CI and linter
|
||||
|
||||
## 1.0.0
|
||||
|
||||
- Initial release
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
include: package:flutter_lints/flutter.yaml
|
||||
include: package:flutter_iconica_analysis/analysis_options.yaml
|
||||
|
||||
# Additional information about this file can be found at
|
||||
# https://dart.dev/guides/language/analysis-options
|
||||
# Possible to overwrite the rules from the package
|
||||
|
||||
analyzer:
|
||||
exclude:
|
||||
|
||||
linter:
|
||||
rules:
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
// SPDX-FileCopyrightText: 2022 Iconica
|
||||
//
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
///
|
||||
library plugin_platform_interface;
|
||||
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// Base class for data interfaces.
|
||||
|
@ -11,20 +12,25 @@ import 'package:meta/meta.dart';
|
|||
/// Provides a static helper method for ensuring that data interfaces are
|
||||
/// implemented using `extends` instead of `implements`.
|
||||
///
|
||||
/// Data interface classes are expected to have a private static token object which will be
|
||||
/// Data interface classes are expected to have a private static token object
|
||||
/// which will be
|
||||
/// be passed to [verify] along with a data interface object for verification.
|
||||
///
|
||||
/// Sample usage:
|
||||
///
|
||||
///
|
||||
/// Mockito mocks of data interfaces will fail the verification, in test code only it is possible
|
||||
/// to include the [MockDataInterfaceMixin] for the verification to be temporarily disabled. See
|
||||
/// [MockDataInterfaceMixin] for a sample of using Mockito to mock a data interface.
|
||||
/// Mockito mocks of data interfaces will fail the verification, in test code
|
||||
/// only it is possible
|
||||
/// to include the [MockDataInterfaceMixin] for the verification to be
|
||||
/// temporarily disabled. See
|
||||
/// [MockDataInterfaceMixin] for a sample of using Mockito to mock a data
|
||||
/// interface.
|
||||
abstract class DataInterface {
|
||||
/// Constructs a DataInterface, for use only in constructors of abstract
|
||||
/// derived classes.
|
||||
///
|
||||
/// @param token The same, non-`const` `Object` that will be passed to `verify`.
|
||||
/// @param token The same, non-`const` `Object` that will be passed
|
||||
/// to `verify`.
|
||||
DataInterface({required Object token}) {
|
||||
_instanceTokens[this] = token;
|
||||
}
|
||||
|
@ -69,14 +75,18 @@ abstract class DataInterface {
|
|||
required bool preventConstObject,
|
||||
}) {
|
||||
if (instance is MockDataInterfaceMixin) {
|
||||
bool assertionsEnabled = false;
|
||||
assert(() {
|
||||
assertionsEnabled = true;
|
||||
return true;
|
||||
}());
|
||||
var assertionsEnabled = false;
|
||||
assert(
|
||||
() {
|
||||
assertionsEnabled = true;
|
||||
return true;
|
||||
}(),
|
||||
'',
|
||||
);
|
||||
if (!assertionsEnabled) {
|
||||
throw AssertionError(
|
||||
'`MockDataInterfaceMixin` is not intended for use in release builds.');
|
||||
'`MockDataInterfaceMixin` is not intended for use in release builds.',
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -86,7 +96,8 @@ abstract class DataInterface {
|
|||
}
|
||||
if (!identical(token, _instanceTokens[instance])) {
|
||||
throw AssertionError(
|
||||
'Data interfaces must not be implemented with `implements`');
|
||||
'Data interfaces must not be implemented with `implements`',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
pubspec.yaml
12
pubspec.yaml
|
@ -1,11 +1,10 @@
|
|||
name: flutter_data_interface
|
||||
description: Generic data interface package
|
||||
version: 1.0.0
|
||||
description: Generic data interface package
|
||||
version: 1.0.1
|
||||
repository: https://github.com/Iconica-Development/flutter_data_interface
|
||||
|
||||
|
||||
environment:
|
||||
sdk: '>=2.18.0 <3.0.0'
|
||||
sdk: ">=2.18.0 <3.0.0"
|
||||
flutter: ">=1.17.0"
|
||||
|
||||
dependencies:
|
||||
|
@ -16,6 +15,9 @@ dependencies:
|
|||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_lints: ^2.0.0
|
||||
flutter_iconica_analysis:
|
||||
git:
|
||||
url: https://github.com/Iconica-Development/flutter_iconica_analysis
|
||||
ref: 6.0.0
|
||||
|
||||
flutter:
|
||||
|
|
|
@ -99,26 +99,32 @@ class StaticMethodsOnlyMockPlatformInterfaceMixinTest
|
|||
void main() {
|
||||
group('`verify`', () {
|
||||
test('prevents implementation with `implements`', () {
|
||||
expect(() {
|
||||
SamplePluginPlatform.instance = ImplementsSamplePluginPlatform();
|
||||
}, throwsA(isA<AssertionError>()));
|
||||
expect(
|
||||
() {
|
||||
SamplePluginPlatform.instance = ImplementsSamplePluginPlatform();
|
||||
},
|
||||
throwsA(isA<AssertionError>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('prevents implmentation with `implements` and `noSuchMethod`', () {
|
||||
expect(() {
|
||||
SamplePluginPlatform.instance =
|
||||
ImplementsSamplePluginPlatformUsingNoSuchMethod();
|
||||
}, throwsA(isA<AssertionError>()));
|
||||
expect(
|
||||
() {
|
||||
SamplePluginPlatform.instance =
|
||||
ImplementsSamplePluginPlatformUsingNoSuchMethod();
|
||||
},
|
||||
throwsA(isA<AssertionError>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('allows mocking with `implements`', () {
|
||||
final SamplePluginPlatform mock =
|
||||
SamplePluginPlatform mock =
|
||||
ImplementsSamplePluginPlatformUsingMockPlatformInterfaceMixin();
|
||||
SamplePluginPlatform.instance = mock;
|
||||
});
|
||||
|
||||
test('allows faking with `implements`', () {
|
||||
final SamplePluginPlatform fake =
|
||||
SamplePluginPlatform fake =
|
||||
ImplementsSamplePluginPlatformUsingFakePlatformInterfaceMixin();
|
||||
SamplePluginPlatform.instance = fake;
|
||||
});
|
||||
|
@ -128,23 +134,29 @@ void main() {
|
|||
});
|
||||
|
||||
test('prevents `const Object()` token', () {
|
||||
expect(() {
|
||||
ConstTokenPluginPlatform.instance = ExtendsConstTokenPluginPlatform();
|
||||
}, throwsA(isA<AssertionError>()));
|
||||
expect(
|
||||
() {
|
||||
ConstTokenPluginPlatform.instance = ExtendsConstTokenPluginPlatform();
|
||||
},
|
||||
throwsA(isA<AssertionError>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// Tests of the earlier, to-be-deprecated `verifyToken` method
|
||||
group('`verifyToken`', () {
|
||||
test('prevents implementation with `implements`', () {
|
||||
expect(() {
|
||||
VerifyTokenPluginPlatform.instance =
|
||||
ImplementsVerifyTokenPluginPlatform();
|
||||
}, throwsA(isA<AssertionError>()));
|
||||
expect(
|
||||
() {
|
||||
VerifyTokenPluginPlatform.instance =
|
||||
ImplementsVerifyTokenPluginPlatform();
|
||||
},
|
||||
throwsA(isA<AssertionError>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('allows mocking with `implements`', () {
|
||||
final VerifyTokenPluginPlatform mock =
|
||||
VerifyTokenPluginPlatform mock =
|
||||
ImplementsVerifyTokenPluginPlatformUsingMockPlatformInterfaceMixin();
|
||||
VerifyTokenPluginPlatform.instance = mock;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue