diff --git a/.flutter-plugins b/.flutter-plugins new file mode 100644 index 0000000..585a4fd --- /dev/null +++ b/.flutter-plugins @@ -0,0 +1,5 @@ +# This is a generated file; do not edit or check into version control. +firebase_core=C:\\Users\\ciriousjoker\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dartlang.org\\firebase_core-1.11.0\\ +firebase_core_web=C:\\Users\\ciriousjoker\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dartlang.org\\firebase_core_web-1.5.3\\ +firebase_performance=C:\\Users\\ciriousjoker\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dartlang.org\\firebase_performance-0.8.0\\ +firebase_performance_web=C:\\Users\\ciriousjoker\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dartlang.org\\firebase_performance_web-0.1.0+4\\ diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies new file mode 100644 index 0000000..a4dfa11 --- /dev/null +++ b/.flutter-plugins-dependencies @@ -0,0 +1 @@ +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"firebase_core","path":"C:\\\\Users\\\\ciriousjoker\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-1.11.0\\\\","dependencies":[]},{"name":"firebase_performance","path":"C:\\\\Users\\\\ciriousjoker\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_performance-0.8.0\\\\","dependencies":["firebase_core"]}],"android":[{"name":"firebase_core","path":"C:\\\\Users\\\\ciriousjoker\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-1.11.0\\\\","dependencies":[]},{"name":"firebase_performance","path":"C:\\\\Users\\\\ciriousjoker\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_performance-0.8.0\\\\","dependencies":["firebase_core"]}],"macos":[{"name":"firebase_core","path":"C:\\\\Users\\\\ciriousjoker\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-1.11.0\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"firebase_core_web","path":"C:\\\\Users\\\\ciriousjoker\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core_web-1.5.3\\\\","dependencies":[]},{"name":"firebase_performance_web","path":"C:\\\\Users\\\\ciriousjoker\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_performance_web-0.1.0+4\\\\","dependencies":["firebase_core_web"]}]},"dependencyGraph":[{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]},{"name":"firebase_performance","dependencies":["firebase_core","firebase_performance_web"]},{"name":"firebase_performance_web","dependencies":["firebase_core","firebase_core_web"]}],"date_created":"2022-01-08 09:36:15.643430","version":"2.8.1"} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9be145f --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/.metadata b/.metadata new file mode 100644 index 0000000..af84dae --- /dev/null +++ b/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: 77d935af4db863f6abd0b9c31c7e6df2a13de57b + channel: stable + +project_type: package diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..275d71f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial release diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fbd044b --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +BSD 2-Clause License + +Copyright (c) 2022, Philipp Bauer All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f808ea3 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# Fake Firebase Performance + +[![pub package](https://img.shields.io/pub/v/fake_firebase_performance.svg)](https://pub.dartlang.org/packages/fake_firebase_performance) + +Fakes to write unit tests for apps using Firebase Performance monitoring. Instantiate a `FakeFirebasePerformance`, then pass it around your project to replace `FirebasePerformance.instance`. This fake acts like `FirebasePerformance` except it will load mocked data instead. + +## Usage + +### A simple usage example + +```dart +import 'package:fake_firebase_performance/fake_firebase_performance.dart'; + +void main() async { + final perf = FakeFirebasePerformance(); + + perf.isPerformanceCollectionEnabled(); // will return false + + perf.newTrace('test'); // will do nothing + perf.newHttpMetric("https://example.com/", HttpMethod.Get); // will do nothing +} +``` + +This `perf` object needs to replace the real `FirebasePerformance.instance` during testing. You can do this for example with [Riverpod](https://pub.dev/packages/riverpod) or by doing something like this: + +```dart +await tester.pumpWidget( + MaterialApp( + title: 'FirebasePerformance Example', + home: MyApp(overrideFirebasePerformance: perf), + ), +); +``` + +## Missing functionality + +- `perf.app` will throw +- `perf.pluginConstants` is empty +- `perf.newTrace()` does nothing +- `perf.newHttpMetric()` does nothing + +## Compatibility table + +| firebase_performance | fake_firebase_performance | +| -------------------- | ------------------------- | +| >=0.8.0 | 1.0.0 | + +## Features and bugs + +Please file feature requests and bugs at the [issue tracker](https://github.com/CiriousJoker/fake_firebase_performance/issues). diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..083fcb2 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:lint/analysis_options.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/lib/fake_firebase_performance.dart b/lib/fake_firebase_performance.dart new file mode 100644 index 0000000..c6ae272 --- /dev/null +++ b/lib/fake_firebase_performance.dart @@ -0,0 +1,3 @@ +library fake_firebase_performance; + +export 'src/fake_firebase_performance_instance.dart'; diff --git a/lib/src/fake_firebase_performance_instance.dart b/lib/src/fake_firebase_performance_instance.dart new file mode 100644 index 0000000..218eac2 --- /dev/null +++ b/lib/src/fake_firebase_performance_instance.dart @@ -0,0 +1,117 @@ +library fake_firebase_performance; + +import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_performance/firebase_performance.dart'; +import 'package:flutter/foundation.dart'; + +/// Fake implementation of [FirebasePerformance] for testing. +class FakeFirebasePerformance + with ChangeNotifier + implements FirebasePerformance { + @override + late FirebaseApp app; + + @override + Future isPerformanceCollectionEnabled() { + return Future.value(false); + } + + @override + HttpMetric newHttpMetric(String url, HttpMethod httpMethod) { + return FakeHttpMetric(); + } + + @override + Trace newTrace(String name) { + return FakeTrace(); + } + + @override + Map get pluginConstants => {}; + + @override + Future setPerformanceCollectionEnabled(bool enabled) { + return Future.value(); + } +} + +class FakeHttpMetric implements HttpMetric { + @override + int? httpResponseCode; + + @override + int? requestPayloadSize; + + @override + String? responseContentType; + + @override + int? responsePayloadSize; + + @override + String? getAttribute(String name) => null; + + @override + Map getAttributes() => {}; + + @override + void putAttribute(String name, String value) { + // noop + } + + @override + void removeAttribute(String name) { + // noop + } + + @override + Future start() { + return Future.value(); + } + + @override + Future stop() { + return Future.value(); + } +} + +class FakeTrace implements Trace { + @override + String? getAttribute(String name) => null; + + @override + Map getAttributes() => {}; + + @override + int getMetric(String name) => 0; + + @override + void incrementMetric(String name, int value) { + // noop + } + + @override + void putAttribute(String name, String value) { + // noop + } + + @override + void removeAttribute(String name) { + // noop + } + + @override + void setMetric(String name, int value) { + // noop + } + + @override + Future start() { + return Future.value(); + } + + @override + Future stop() { + return Future.value(); + } +} diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..a89dbb6 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,22 @@ +name: fake_firebase_performance +description: Fake Firebase Performance for use during Flutter unit & widget tests. +version: 1.0.0 +homepage: https://philippbauer.me/ +repository: https://github.com/CiriousJoker/fake_firebase_performance + +environment: + sdk: ">=2.12.0 <3.0.0" + flutter: ">=1.17.0" + +dependencies: + firebase_core: any + firebase_performance: ">=0.8.0 <1.0.0" + flutter: + sdk: flutter + +dev_dependencies: + flutter_test: + sdk: flutter + lint: ^1.8.1 + +flutter: