mock_creator_generator 1.0.8

  • Readme
  • Changelog
  • Example
  • Installing
  • 48

You want a generator to create a mock from a call method? Append @MockCreator() to your class name.

@MockCreator()
class SalutationAppender {
  String call(String name) {
    if (["Bob", "Rob", "Todd"].contains(name)) {
      return "Mr " + name;
    }

    return "Mrs " + name;
  }
}

class SalutationAppender_Mock extends SalutationAppender {
  final String Function(
    String name,
  ) fn;

  SalutationAppender_Mock(this.fn);

  String call(
    String a,
  ) =>
      fn(a);
}

1.0.8 #

  • Update dependencies (dartx)

1.0.7 #

  • Possible fix to the analysis exception errors by removing getResolvedLibraryByElement

1.0.6 #

  • Creates a well named fndef for the call method

1.0.5 #

  • Supports mixed positional and named params

1.0.4 #

  • Supports zero length parameters

1.0.3 #

  • Update dependencies

1.0.2 #

  • Update dependencies

1.0.1 #

  • Supports named params in the call method

1.0.0 #

  • First publish

example/example.dart

import 'package:meta/meta.dart';
import 'package:mock_creator_annotation/mock_creator_annotation.dart';

//see example project in github

part 'example.g.dart';

@MockCreator()
class SalutationAppender {
  String call(String name, int someInt, List<int> someGeneric) {
    if (["Bob", "Rob", "Todd"].contains(name)) {
      return "Mr " + name;
    }

    return "Mrs " + name;
  }
}

class PersonFormatter {
  SalutationAppender $salutationAppender = SalutationAppender();

  String call(Person person) {
    var result = $salutationAppender(person.firstName, null, null).toString() + //
        " " +
        person.lastName +
        ". Age:" +
        person.age.toString();

    return result;
  }
}

class Person {
  final String firstName;
  final String lastName;
  final int age;

  Person({
    @required this.firstName,
    @required this.lastName,
    @required this.age,
  });
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  mock_creator_generator: ^1.0.8

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:mock_creator_generator/mock_creator_generator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
2
Health:
Code health derived from static analysis. [more]
96
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because:

  • package:mock_creator_generator/mock_creator_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on ios

Because:

  • package:mock_creator_generator/mock_creator_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on linux

Because:

  • package:mock_creator_generator/mock_creator_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on macos

Because:

  • package:mock_creator_generator/mock_creator_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on windows

Because:

  • package:mock_creator_generator/mock_creator_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-web on web

Because:

  • package:mock_creator_generator/mock_creator_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/utils.dart that imports:
  • package:build/build.dart that imports:
  • package:build/src/generate/run_post_process_builder.dart that imports:
  • package:build/src/builder/post_process_builder.dart that imports:
  • package:build/src/builder/builder.dart that imports:
  • package:build/src/builder/build_step.dart that imports:
  • package:build/src/asset/reader.dart that imports:
  • package:glob/glob.dart that imports:
  • package:glob/src/list_tree.dart that imports:
  • package:glob/src/io.dart that imports:
  • package:glob/src/io_export.dart that imports:
  • dart:io

Package not compatible with runtime js

Because:

  • package:mock_creator_generator/mock_creator_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/utils.dart that imports:
  • package:build/build.dart that imports:
  • package:build/src/generate/run_post_process_builder.dart that imports:
  • package:build/src/builder/post_process_builder.dart that imports:
  • package:build/src/builder/builder.dart that imports:
  • package:build/src/builder/build_step.dart that imports:
  • package:build/src/asset/reader.dart that imports:
  • package:glob/glob.dart that imports:
  • package:glob/src/list_tree.dart that imports:
  • package:glob/src/io.dart that imports:
  • package:glob/src/io_export.dart that imports:
  • dart:io

Package not compatible with runtime native-aot

Because:

  • package:mock_creator_generator/mock_creator_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Health issues and suggestions

Document public APIs. (-1 points)

2 out of 2 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/helpers.dart. (-2.96 points)

Analysis of lib/src/helpers.dart reported 6 hints, including:

line 18 col 7: Use isEmpty instead of length

line 18 col 39: Use isEmpty instead of length

line 49 col 7: Use isEmpty instead of length

line 49 col 39: Use isEmpty instead of length

line 91 col 7: Use isEmpty instead of length

Format lib/src/MockCreatorGenerator.dart.

Run dartfmt to format lib/src/MockCreatorGenerator.dart.

Format lib/src/createMockCreator.dart.

Run dartfmt to format lib/src/createMockCreator.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (dartz).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.1 <3.0.0
analyzer >=0.39.5 <0.40.0 0.39.12
basic_utils ^2.4.8 2.5.5
build ^1.2.2 1.3.0
dartx >=0.3.0 <0.7.0 0.4.2
dartz ^0.8.3 0.8.9 0.9.1
meta ^1.1.8 1.2.2 1.3.0-nullsafety
mock_creator_annotation ^1.0.1 1.0.1
quiver ^2.0.1 2.1.3
source_gen ^0.9.4+7 0.9.5
typedef_for_fn_generator ^1.0.0 1.0.0
Transitive dependencies
_fe_analyzer_shared 5.0.0
args 1.6.0
asn1lib 0.6.5
async 2.4.2
characters 1.0.0 1.1.0-nullsafety
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
dart_style 1.3.6
glob 1.2.0
html 0.14.0+3
http 0.12.1
http_parser 3.1.4
intl 0.16.1
js 0.6.2
json_annotation 3.0.1
logging 0.11.4
matcher 0.12.8
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
path 1.7.0
pedantic 1.9.2
pointycastle 1.0.2
pub_semver 1.4.4
source_span 1.7.0
stack_trace 1.9.5
string_scanner 1.0.5
term_glyph 1.1.0
time 1.3.0
typed_data 1.2.0 1.3.0-nullsafety
typedef_for_fn 1.0.0
watcher 0.9.7+15
yaml 2.2.1
Dev dependencies
build_runner ^1.7.3
test ^1.11.1