From 914949fdac76393eef8eb102b26ad2ea36fe5b3e Mon Sep 17 00:00:00 2001 From: Patrick Stewart Date: Sat, 28 Sep 2024 23:01:12 -0700 Subject: [PATCH] add(laravel): adding support for laravel inspired serviceproviders --- packages/core/README.md | 100 +- packages/core/lib/providers.dart | 3 + .../src/provider/platform_with_providers.dart | 93 + .../lib/src/provider/provider_discovery.dart | 54 + .../lib/src/provider/service_provider.dart | 39 + .../src/provider/service_provider_config.dart | 82 + .../provider/service_provider_manager.dart | 131 ++ .../core/lib/src/provider/test_setup.dart | 37 + packages/core/pubspec.lock | 144 ++ packages/core/pubspec.yaml | 2 + .../platform_with_providers_test.dart | 55 + .../platform_with_providers_test.mocks.dart | 1526 +++++++++++++++++ .../provider/provider_discovery_test.dart | 33 + .../service_provider_config_test.dart | 27 + .../service_provider_integration_test.dart | 87 + .../service_provider_manager_test.dart | 93 + .../service_provider_manager_test.mocks.dart | 1462 ++++++++++++++++ .../test/provider/service_provider_test.dart | 32 + 18 files changed, 3923 insertions(+), 77 deletions(-) create mode 100644 packages/core/lib/providers.dart create mode 100644 packages/core/lib/src/provider/platform_with_providers.dart create mode 100644 packages/core/lib/src/provider/provider_discovery.dart create mode 100644 packages/core/lib/src/provider/service_provider.dart create mode 100644 packages/core/lib/src/provider/service_provider_config.dart create mode 100644 packages/core/lib/src/provider/service_provider_manager.dart create mode 100644 packages/core/lib/src/provider/test_setup.dart create mode 100644 packages/core/test/provider/platform_with_providers_test.dart create mode 100644 packages/core/test/provider/platform_with_providers_test.mocks.dart create mode 100644 packages/core/test/provider/provider_discovery_test.dart create mode 100644 packages/core/test/provider/service_provider_config_test.dart create mode 100644 packages/core/test/provider/service_provider_integration_test.dart create mode 100644 packages/core/test/provider/service_provider_manager_test.dart create mode 100644 packages/core/test/provider/service_provider_manager_test.mocks.dart create mode 100644 packages/core/test/provider/service_provider_test.dart diff --git a/packages/core/README.md b/packages/core/README.md index 9d1ab8b..56ea484 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -1,86 +1,32 @@ -# Protevus Framework +# Protevus Platform Core -[![Protevus Framework](../../angel3_logo.png)](https://github.com/dart-backend/angel) +

Protevus Logo

-![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_framework?include_prereleases) +[![Pub Version (including pre-releases)](https://img.shields.io/pub/v/protevus_core?include_prereleases)](https://pub.dev/packages/protevus_core) [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) -[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) -[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/framework/LICENSE) -[![melos](https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square)](https://github.com/invertase/melos) +[![License](https://img.shields.io/github/license/protevus/platform)](https://github.com/protevus/platform/blob/main/packages/core/LICENSE) -Protevus framework is a high-powered HTTP server with support for dependency injection, sophisticated routing, authentication, ORM, graphql etc. It is designed to keep the core minimal but extensible through a series of plugin packages. It won't dictate which features, databases or web templating engine to use. This flexibility enable Protevus framework to grow with your application as new features can be added to handle the new use cases. +Protevus Platform Core is a high-powered HTTP server framework for Dart, designed to be minimal yet extensible. It provides a robust foundation for building scalable and flexible web applications. -This package is the core package of [Protevus](https://github.com/dart-backend/angel). For more information, visit us at [Protevus Website](https://angel3-framework.web.app). +## Features -## Installation and Setup +- Dependency injection +- Sophisticated routing +- Authentication support +- ORM integration +- GraphQL support +- Extensible plugin architecture +- HTTP/2 support +- WebSocket capabilities +- File handling and MIME type detection +- Environment configuration management +- Performance optimization with caching mechanisms -### (Option 1) Create a new project by cloning from boilerplate templates +## Installation -1. Download and install [Dart](https://dart.dev/get-dart) +Add `protevus_core` to your `pubspec.yaml`: -2. Clone one of the following starter projects: - * [Protevus Basic Template](https://github.com/dukefirehawk/boilerplates/tree/v7/angel3-basic) - * [Protevus ORM Template](https://github.com/dukefirehawk/boilerplates/tree/v7/angel3-orm) - * [Protevus ORM MySQL Template](https://github.com/dukefirehawk/boilerplates/tree/v7/angel3-orm-mysql) - * [Protevus Graphql Template](https://github.com/dukefirehawk/boilerplates/tree/v7/angel3-graphql) - -3. Run the project in development mode (*hot-reloaded* is enabled on file changes). - - ```bash - dart --observe bin/dev.dart - ``` - -4. Run the project in production mode (*hot-reloaded* is disabled). - - ```bash - dart bin/prod.dart - ``` - -5. Run as docker. Edit and build the image with the provided `Dockerfile` file. - -### (Option 2) Create a new project with Protevus CLI - -1. Download and install [Dart](https://dart.dev/get-dart) - -2. Install the [Protevus CLI](https://pub.dev/packages/angel3_cli): - - ```bash - dart pub global activate angel3_cli - ``` - -3. On terminal, create a new project: - - ```bash - angel3 init hello - ``` - -4. Run the project in development mode (*hot-reloaded* is enabled on file changes). - - ```bash - dart --observe bin/dev.dart - ``` - -5. Run the project in production mode (*hot-reloaded* is disabled). - - ```bash - dart bin/prod.dart - ``` - -6. Run as docker. Edit and build the image with the provided `Dockerfile` file. - -## Performance Benchmark - -The performance benchmark can be found at - -[TechEmpower Framework Benchmarks Round 21](https://www.techempower.com/benchmarks/#section=data-r21&test=composite) - -### Migrating from Angel to Protevus - -Check out [Migrating to Protevus](https://angel3-docs.dukefirehawk.com/migration/angel-2.x.x-to-angel3/migration-guide-3) - -## Donation & Support - -If you like this project and interested in supporting its development, you can make a donation using the following services: - -* [![GitHub](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/dukefirehawk) -* [paypal](https://paypal.me/dukefirehawk?country.x=MY&locale.x=en_US) service +```yaml +dependencies: + protevus_core: ^latest_version +``` \ No newline at end of file diff --git a/packages/core/lib/providers.dart b/packages/core/lib/providers.dart new file mode 100644 index 0000000..20f5669 --- /dev/null +++ b/packages/core/lib/providers.dart @@ -0,0 +1,3 @@ +export 'src/provider/platform_with_providers.dart'; +export 'src/provider/service_provider.dart'; +export 'src/provider/service_provider_config.dart'; diff --git a/packages/core/lib/src/provider/platform_with_providers.dart b/packages/core/lib/src/provider/platform_with_providers.dart new file mode 100644 index 0000000..0de8957 --- /dev/null +++ b/packages/core/lib/src/provider/platform_with_providers.dart @@ -0,0 +1,93 @@ +import 'package:platform_core/core.dart'; +import 'package:platform_container/container.dart'; +import 'package:platform_container/mirrors.dart'; +import 'package:logging/logging.dart'; +import 'service_provider.dart'; +import 'service_provider_manager.dart'; +import 'service_provider_config.dart'; +import 'provider_discovery.dart'; + +class PlatformWithProviders { + final Application app; + late ServiceProviderManager _serviceProviderManager; + late ProviderDiscovery _discovery; + late Container container; + + PlatformWithProviders(this.app, + {ServiceProviderManager? serviceProviderManager}) { + container = Container(MirrorsReflector()); + app.configure(configureContainer); + + _serviceProviderManager = + serviceProviderManager ?? ServiceProviderManager(app, _discovery); + } + + Future configureContainer(Application app) async { + // Register the container itself + container.registerSingleton((c) => container); + + // Configure the container here + // For example, you might want to register some services: + // container.registerSingleton((c) => SomeService()); + + // You might need to set up dependency injection for routes here + // app.use((req, res) => container.make().handleRequest(req, res)); + } + + Future registerProvidersFromConfig(ServiceProviderConfig config) async { + for (var providerType in config.providers) { + var provider = _discovery.createInstance(providerType); + if (provider != null) { + if (config.deferredProviders.containsKey(providerType)) { + provider.setDeferred(config.deferredProviders[providerType]!); + } + if (config.providerConfigs.containsKey(providerType)) { + provider.configure(config.providerConfigs[providerType]!); + } + await _serviceProviderManager.register(provider); + } + } + } + + Future registerServiceProvider(ServiceProvider provider) async { + await _serviceProviderManager.register(provider); + } + + void unregisterServiceProvider(Type providerType) { + _serviceProviderManager.unregister(providerType); + } + + T? getServiceProvider() { + return _serviceProviderManager.getProvider(); + } + + Future bootServiceProviders() async { + await _serviceProviderManager.bootAll(); + } + + Future bootDeferredServiceProvider(Type providerType) async { + await _serviceProviderManager.bootDeferredProvider(providerType); + } + + void setServiceProviderLogLevel(Level level) { + _serviceProviderManager.setLogLevel(level); + } + + Future discoverServiceProviders() async { + await _serviceProviderManager.discoverProviders(); + } + + void registerProviderType(Type type, ServiceProvider Function() factory) { + if (_discovery is ManualProviderDiscovery) { + (_discovery as ManualProviderDiscovery) + .registerProviderType(type, factory); + } else { + throw UnsupportedError( + 'Provider type registration is only supported with ManualProviderDiscovery'); + } + } + + T? getService() { + return app.container.make(); + } +} diff --git a/packages/core/lib/src/provider/provider_discovery.dart b/packages/core/lib/src/provider/provider_discovery.dart new file mode 100644 index 0000000..41eb41e --- /dev/null +++ b/packages/core/lib/src/provider/provider_discovery.dart @@ -0,0 +1,54 @@ +import 'dart:mirrors' as mirrors; +import 'service_provider.dart'; + +abstract class ProviderDiscovery { + List discoverProviders(); + ServiceProvider? createInstance(Type type); +} + +class MirrorProviderDiscovery implements ProviderDiscovery { + @override + List discoverProviders() { + var providers = []; + mirrors.currentMirrorSystem().libraries.values.forEach((lib) { + for (var declaration in lib.declarations.values) { + if (declaration is mirrors.ClassMirror && + declaration.isSubclassOf(mirrors.reflectClass(ServiceProvider)) && + !declaration.isAbstract) { + providers.add(declaration.reflectedType); + } + } + }); + return providers; + } + + @override + ServiceProvider? createInstance(Type type) { + var classMirror = mirrors.reflectClass(type); + if (classMirror.declarations.containsKey(const Symbol(''))) { + var ctor = + classMirror.declarations[const Symbol('')] as mirrors.MethodMirror?; + if (ctor != null && ctor.isConstructor && ctor.parameters.isEmpty) { + return classMirror.newInstance(const Symbol(''), []).reflectee + as ServiceProvider; + } + } + return null; + } +} + +class ManualProviderDiscovery implements ProviderDiscovery { + final List _registeredTypes = []; + final Map _factories = {}; + + void registerProviderType(Type type, ServiceProvider Function() factory) { + _registeredTypes.add(type); + _factories[type] = factory; + } + + @override + List discoverProviders() => List.unmodifiable(_registeredTypes); + + @override + ServiceProvider? createInstance(Type type) => _factories[type]?.call(); +} diff --git a/packages/core/lib/src/provider/service_provider.dart b/packages/core/lib/src/provider/service_provider.dart new file mode 100644 index 0000000..de1d884 --- /dev/null +++ b/packages/core/lib/src/provider/service_provider.dart @@ -0,0 +1,39 @@ +import 'package:platform_core/core.dart'; +import 'package:platform_container/container.dart'; + +abstract class ServiceProvider { + late Application app; + late Container container; + late final Map _config; + bool _isEnabled = true; + bool _isDeferred = false; + + ServiceProvider([Map? config]) : _config = config ?? {}; + + Map get config => _config; + bool get isEnabled => _isEnabled; + bool get isDeferred => _isDeferred; + + void configure(Map options) { + _config.addAll(options); + } + + void setEnabled(bool enabled) { + _isEnabled = enabled; + } + + void setDeferred(bool deferred) { + _isDeferred = deferred; + } + + void registerWithContainer(Container container) { + this.container = container; + } + + Future register(); + Future beforeBoot() async {} + Future boot(); + Future afterBoot() async {} + + List get dependencies => []; +} diff --git a/packages/core/lib/src/provider/service_provider_config.dart b/packages/core/lib/src/provider/service_provider_config.dart new file mode 100644 index 0000000..ebceda6 --- /dev/null +++ b/packages/core/lib/src/provider/service_provider_config.dart @@ -0,0 +1,82 @@ +import 'package:platform_core/core.dart'; +import 'package:platform_core/src/provider/service_provider.dart'; + +class ServiceProviderConfig { + final List providers; + final Map deferredProviders; + final Map> providerConfigs; + + ServiceProviderConfig({ + required this.providers, + this.deferredProviders = const {}, + this.providerConfigs = const {}, + }); + + factory ServiceProviderConfig.fromMap(Map map) { + final providersList = + (map['providers'] as List).cast>(); + + final providers = []; + final deferredProviders = {}; + final providerConfigs = >{}; + + for (var providerMap in providersList) { + final type = _getTypeFromString(providerMap['type'] as String); + providers.add(type); + + if (providerMap['deferred'] == true) { + deferredProviders[type] = true; + } + + if (providerMap['config'] != null) { + providerConfigs[type] = (providerMap['config'] as Map); + } + } + + return ServiceProviderConfig( + providers: providers, + deferredProviders: deferredProviders, + providerConfigs: providerConfigs, + ); + } + + static Type _getTypeFromString(String typeName) { + // This is a simple implementation. You might need to expand this + // to cover all your service provider types. + switch (typeName) { + case 'TestServiceProvider': + return TestServiceProvider; + case 'AnotherServiceProvider': + return AnotherServiceProvider; + // Add cases for all your service provider types + default: + throw UnimplementedError( + 'Type $typeName is not implemented in _getTypeFromString'); + } + } +} + +// Example service provider classes (you should replace these with your actual service providers) +class TestServiceProvider extends ServiceProvider { + @override + Future register() async { + // Implementation + } + + @override + Future boot() async { + // Implementation + } +} + +class AnotherServiceProvider extends ServiceProvider { + @override + Future register() async { + // Implementation + } + + @override + Future boot() async { + // Implementation + } +} diff --git a/packages/core/lib/src/provider/service_provider_manager.dart b/packages/core/lib/src/provider/service_provider_manager.dart new file mode 100644 index 0000000..1fed530 --- /dev/null +++ b/packages/core/lib/src/provider/service_provider_manager.dart @@ -0,0 +1,131 @@ +import 'package:platform_core/core.dart'; +import 'package:platform_container/container.dart'; +import 'package:logging/logging.dart'; +import 'service_provider.dart'; +import 'provider_discovery.dart'; + +class ServiceProviderManager { + final Application app; + final Container container; + final Map _providers = {}; + final Set _booted = {}; + final Logger _logger; + final ProviderDiscovery _discovery; + + ServiceProviderManager(this.app, this._discovery) + : container = app.container, + _logger = Logger('ServiceProviderManager'); + + void setLogLevel(Level level) { + _logger.level = level; + } + + Future register(ServiceProvider provider) async { + provider.app = app; + provider.registerWithContainer(container); + _providers[provider.runtimeType] = provider; + try { + _logger.info('Registering ${provider.runtimeType}'); + await provider.register(); + _logger.info('Registered ${provider.runtimeType}'); + } catch (e) { + _logger.severe('Failed to register ${provider.runtimeType}', e); + rethrow; + } + } + + void unregister(Type providerType) { + if (_providers.containsKey(providerType)) { + _logger.info('Unregistering $providerType'); + _providers.remove(providerType); + _booted.remove(providerType); + } else { + _logger.warning( + 'Attempted to unregister non-existent provider: $providerType'); + } + } + + T? getProvider() { + return _providers[T] as T?; + } + + Future bootAll() async { + for (var providerType in _providers.keys) { + await _bootProvider(providerType); + } + } + + Future _bootProvider(Type providerType) async { + if (_booted.contains(providerType)) return; + + var provider = _providers[providerType]; + if (provider == null) { + _logger.severe('Provider not found: $providerType'); + throw ProviderNotFoundException(providerType); + } + + if (!provider.isEnabled) { + _logger.info('Skipping disabled provider: $providerType'); + return; + } + + if (provider.isDeferred) { + _logger.info('Skipping deferred provider: $providerType'); + return; + } + + for (var dependencyType in provider.dependencies) { + await _bootProvider(dependencyType); + } + + try { + _logger.info('Booting ${provider.runtimeType}'); + await provider.beforeBoot(); + await provider.boot(); + await provider.afterBoot(); + _booted.add(providerType); + _logger.info('Booted ${provider.runtimeType}'); + } catch (e) { + _logger.severe('Failed to boot ${provider.runtimeType}', e); + throw ProviderBootException(provider, e); + } + } + + Future bootDeferredProvider(Type providerType) async { + var provider = _providers[providerType]; + if (provider == null || !provider.isDeferred) { + throw ProviderNotFoundException(providerType); + } + await _bootProvider(providerType); + } + + Future discoverProviders() async { + for (var type in _discovery.discoverProviders()) { + if (!_providers.containsKey(type)) { + var instance = _discovery.createInstance(type); + if (instance != null) { + await register(instance); + } + } + } + } +} + +class ProviderNotFoundException implements Exception { + final Type providerType; + + ProviderNotFoundException(this.providerType); + + @override + String toString() => 'Provider not found: $providerType'; +} + +class ProviderBootException implements Exception { + final ServiceProvider provider; + final Object error; + + ProviderBootException(this.provider, this.error); + + @override + String toString() => 'Failed to boot ${provider.runtimeType}: $error'; +} diff --git a/packages/core/lib/src/provider/test_setup.dart b/packages/core/lib/src/provider/test_setup.dart new file mode 100644 index 0000000..292f01b --- /dev/null +++ b/packages/core/lib/src/provider/test_setup.dart @@ -0,0 +1,37 @@ +import 'package:platform_core/core.dart'; +import 'package:platform_container/container.dart'; +import 'package:platform_container/mirrors.dart'; +import 'package:platform_core/src/provider/platform_with_providers.dart'; + +class TestSetup { + late Application app; + late PlatformWithProviders platformWithProviders; + late Container _container; + + Container get container => _container; + + Future initialize() async { + app = Application(); + + // Create a container + _container = Container(); + + // Set up MirrorsReflector + Reflector.global = MirrorsReflector(); + + // Initialize PlatformWithProviders + platformWithProviders = PlatformWithProviders(app); + + // Configure the app to use our container + app.configure((angel) { + angel.container.registerSingleton((c) => _container); + }); + + // Allow some time for initialization + await Future.delayed(Duration(milliseconds: 100)); + } + + Future tearDown() async { + await app.close(); + } +} diff --git a/packages/core/pubspec.lock b/packages/core/pubspec.lock index 88054ad..1c2ff4a 100644 --- a/packages/core/pubspec.lock +++ b/packages/core/pubspec.lock @@ -78,6 +78,70 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" + build: + dependency: transitive + description: + name: build + sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + build_config: + dependency: transitive + description: + name: build_config + sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 + url: "https://pub.dev" + source: hosted + version: "1.1.1" + build_daemon: + dependency: transitive + description: + name: build_daemon + sha256: "79b2aef6ac2ed00046867ed354c88778c9c0f029df8a20fe10b5436826721ef9" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a" + url: "https://pub.dev" + source: hosted + version: "2.4.2" + build_runner: + dependency: "direct dev" + description: + name: build_runner + sha256: "644dc98a0f179b872f612d3eb627924b578897c629788e858157fa5e704ca0c7" + url: "https://pub.dev" + source: hosted + version: "2.4.11" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + sha256: e3c79f69a64bdfcd8a776a3c28db4eb6e3fb5356d013ae5eb2e52007706d5dbe + url: "https://pub.dev" + source: hosted + version: "7.3.1" + built_collection: + dependency: transitive + description: + name: built_collection + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + sha256: c7913a9737ee4007efedaffc968c049fd0f3d0e49109e778edc10de9426005cb + url: "https://pub.dev" + source: hosted + version: "8.9.2" charcode: dependency: "direct main" description: @@ -86,6 +150,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.1" + checked_yaml: + dependency: transitive + description: + name: checked_yaml + sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff + url: "https://pub.dev" + source: hosted + version: "2.0.3" + code_builder: + dependency: transitive + description: + name: code_builder + sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37 + url: "https://pub.dev" + source: hosted + version: "4.10.0" collection: dependency: "direct main" description: @@ -118,6 +198,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.5" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab" + url: "https://pub.dev" + source: hosted + version: "2.3.7" file: dependency: "direct main" description: @@ -150,6 +238,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.2" + graphs: + dependency: transitive + description: + name: graphs + sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0" + url: "https://pub.dev" + source: hosted + version: "2.3.2" http: dependency: "direct dev" description: @@ -198,6 +294,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.1" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.dev" + source: hosted + version: "4.9.0" lints: dependency: "direct dev" description: @@ -246,6 +350,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.6" + mockito: + dependency: "direct dev" + description: + name: mockito + sha256: "6841eed20a7befac0ce07df8116c8b8233ed1f4486a7647c7fc5a02ae6163917" + url: "https://pub.dev" + source: hosted + version: "5.4.4" node_preamble: dependency: transitive description: @@ -321,6 +433,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + sha256: c799b721d79eb6ee6fa56f00c04b472dcd44a30d258fac2174a6ec57302678f8 + url: "https://pub.dev" + source: hosted + version: "1.3.0" quiver: dependency: "direct main" description: @@ -369,6 +489,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" + source_gen: + dependency: transitive + description: + name: source_gen + sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832" + url: "https://pub.dev" + source: hosted + version: "1.5.0" source_map_stack_trace: dependency: transitive description: @@ -417,6 +545,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.2" + stream_transform: + dependency: transitive + description: + name: stream_transform + sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f" + url: "https://pub.dev" + source: hosted + version: "2.1.0" string_scanner: dependency: "direct main" description: @@ -457,6 +593,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.5" + timing: + dependency: transitive + description: + name: timing + sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32" + url: "https://pub.dev" + source: hosted + version: "1.0.1" tuple: dependency: "direct main" description: diff --git a/packages/core/pubspec.yaml b/packages/core/pubspec.yaml index 6b7aafd..f9b79c9 100644 --- a/packages/core/pubspec.yaml +++ b/packages/core/pubspec.yaml @@ -36,6 +36,8 @@ dev_dependencies: io: ^1.0.0 test: ^1.24.0 lints: ^4.0.0 + mockito: ^5.4.4 + build_runner: ^2.0.0 # dependency_overrides: # platform_container: # path: ../container/angel_container diff --git a/packages/core/test/provider/platform_with_providers_test.dart b/packages/core/test/provider/platform_with_providers_test.dart new file mode 100644 index 0000000..8141270 --- /dev/null +++ b/packages/core/test/provider/platform_with_providers_test.dart @@ -0,0 +1,55 @@ +import 'package:test/test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:mockito/annotations.dart'; +import 'package:platform_core/core.dart'; +import 'package:platform_container/container.dart'; +import 'package:platform_core/src/provider/platform_with_providers.dart'; +import 'package:platform_core/src/provider/service_provider.dart'; +import 'package:platform_core/src/provider/service_provider_manager.dart'; +import 'package:platform_core/src/provider/provider_discovery.dart'; + +@GenerateMocks([ServiceProviderManager, ProviderDiscovery]) +import 'platform_with_providers_test.mocks.dart'; + +void main() { + group('PlatformWithProviders', () { + late PlatformWithProviders platformWithProviders; + late Application app; + late MockServiceProviderManager mockManager; + + setUp(() { + app = Application(); + mockManager = MockServiceProviderManager(); + + platformWithProviders = + PlatformWithProviders(app, serviceProviderManager: mockManager); + }); + + test('PlatformWithProviders initializes correctly', () { + expect(platformWithProviders, isNotNull); + expect(platformWithProviders.app, equals(app)); + }); + + test('container is created', () { + expect(platformWithProviders.container, isNotNull); + expect(platformWithProviders.container, isA()); + }); + + test('registerServiceProvider calls manager.register', () async { + final provider = MockServiceProvider(); + await platformWithProviders.registerServiceProvider(provider); + + verify(mockManager.register(provider)).called(1); + }); + + test('bootServiceProviders calls manager.bootAll', () async { + await platformWithProviders.bootServiceProviders(); + + verify(mockManager.bootAll()).called(1); + }); + + // Add more tests for other methods in PlatformWithProviders + }); +} + +class MockServiceProvider extends Mock implements ServiceProvider {} diff --git a/packages/core/test/provider/platform_with_providers_test.mocks.dart b/packages/core/test/provider/platform_with_providers_test.mocks.dart new file mode 100644 index 0000000..e19c8c8 --- /dev/null +++ b/packages/core/test/provider/platform_with_providers_test.mocks.dart @@ -0,0 +1,1526 @@ +// Mocks generated by Mockito 5.4.4 from annotations +// in platform_core/test/provider/platform_with_providers_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i7; +import 'dart:convert' as _i13; + +import 'package:belatuk_combinator/belatuk_combinator.dart' as _i12; +import 'package:logging/logging.dart' as _i5; +import 'package:mime/mime.dart' as _i2; +import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i19; +import 'package:platform_container/container.dart' as _i6; +import 'package:platform_core/core.dart' as _i10; +import 'package:platform_core/src/core/controller.dart' as _i18; +import 'package:platform_core/src/core/env.dart' as _i3; +import 'package:platform_core/src/core/hooked_service.dart' as _i9; +import 'package:platform_core/src/core/request_context.dart' as _i16; +import 'package:platform_core/src/core/response_context.dart' as _i17; +import 'package:platform_core/src/core/routable.dart' as _i14; +import 'package:platform_core/src/core/service.dart' as _i8; +import 'package:platform_core/src/provider/service_provider.dart' as _i20; +import 'package:platform_core/src/provider/service_provider_manager.dart' + as _i21; +import 'package:platform_exceptions/http_exception.dart' as _i15; +import 'package:platform_route/route.dart' as _i4; +import 'package:tuple/tuple.dart' as _i11; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeMimeTypeResolver_0 extends _i1.SmartFake + implements _i2.MimeTypeResolver { + _FakeMimeTypeResolver_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeProtevusEnvironment_1 extends _i1.SmartFake + implements _i3.ProtevusEnvironment { + _FakeProtevusEnvironment_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeRouter_2 extends _i1.SmartFake implements _i4.Router { + _FakeRouter_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeLogger_3 extends _i1.SmartFake implements _i5.Logger { + _FakeLogger_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeContainer_4 extends _i1.SmartFake implements _i6.Container { + _FakeContainer_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeRoute_5 extends _i1.SmartFake implements _i4.Route { + _FakeRoute_5( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeSymlinkRoute_6 extends _i1.SmartFake + implements _i4.SymlinkRoute { + _FakeSymlinkRoute_6( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeFuture_7 extends _i1.SmartFake implements _i7.Future { + _FakeFuture_7( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeHookedService_8> + extends _i1.SmartFake implements _i9.HookedService { + _FakeHookedService_8( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeChainedRouter_9 extends _i1.SmartFake + implements _i4.ChainedRouter { + _FakeChainedRouter_9( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeApplication_10 extends _i1.SmartFake implements _i10.Application { + _FakeApplication_10( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeReflector_11 extends _i1.SmartFake implements _i6.Reflector { + _FakeReflector_11( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [Application]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockApplication extends _i1.Mock implements _i10.Application { + MockApplication() { + _i1.throwOnMissingStub(this); + } + + @override + Map< + String, + _i11.Tuple4< + List, + Map, + _i12.ParseResult<_i4.RouteResult>, + _i4.MiddlewarePipeline>> get handlerCache => + (super.noSuchMethod( + Invocation.getter(#handlerCache), + returnValue: , + Map, + _i12.ParseResult<_i4.RouteResult>, + _i4.MiddlewarePipeline>>{}, + ) as Map< + String, + _i11.Tuple4< + List, + Map, + _i12.ParseResult<_i4.RouteResult>, + _i4.MiddlewarePipeline>>); + + @override + Map, List>> get encoders => + (super.noSuchMethod( + Invocation.getter(#encoders), + returnValue: , List>>{}, + ) as Map, List>>); + + @override + _i2.MimeTypeResolver get mimeTypeResolver => (super.noSuchMethod( + Invocation.getter(#mimeTypeResolver), + returnValue: _FakeMimeTypeResolver_0( + this, + Invocation.getter(#mimeTypeResolver), + ), + ) as _i2.MimeTypeResolver); + + @override + set serializer(_i7.FutureOr Function(dynamic)? _serializer) => + super.noSuchMethod( + Invocation.setter( + #serializer, + _serializer, + ), + returnValueForMissingStub: null, + ); + + @override + bool get allowMethodOverrides => (super.noSuchMethod( + Invocation.getter(#allowMethodOverrides), + returnValue: false, + ) as bool); + + @override + set allowMethodOverrides(bool? _allowMethodOverrides) => super.noSuchMethod( + Invocation.setter( + #allowMethodOverrides, + _allowMethodOverrides, + ), + returnValueForMissingStub: null, + ); + + @override + _i3.ProtevusEnvironment get environment => (super.noSuchMethod( + Invocation.getter(#environment), + returnValue: _FakeProtevusEnvironment_1( + this, + Invocation.getter(#environment), + ), + ) as _i3.ProtevusEnvironment); + + @override + List<_i10.PlatformConfigurer> get startupHooks => (super.noSuchMethod( + Invocation.getter(#startupHooks), + returnValue: <_i10.PlatformConfigurer>[], + ) as List<_i10.PlatformConfigurer>); + + @override + List<_i10.PlatformConfigurer> get shutdownHooks => (super.noSuchMethod( + Invocation.getter(#shutdownHooks), + returnValue: <_i10.PlatformConfigurer>[], + ) as List<_i10.PlatformConfigurer>); + + @override + List<_i14.RequestHandler> get responseFinalizers => (super.noSuchMethod( + Invocation.getter(#responseFinalizers), + returnValue: <_i14.RequestHandler>[], + ) as List<_i14.RequestHandler>); + + @override + set viewGenerator(_i10.ViewGenerator? _viewGenerator) => super.noSuchMethod( + Invocation.setter( + #viewGenerator, + _viewGenerator, + ), + returnValueForMissingStub: null, + ); + + @override + _i10.PlatformErrorHandler get errorHandler => (super.noSuchMethod( + Invocation.getter(#errorHandler), + returnValue: ( + _i15.PlatformHttpException e, + _i16.RequestContext req, + _i17.ResponseContext res, + ) => + null, + ) as _i10.PlatformErrorHandler); + + @override + set errorHandler(_i10.PlatformErrorHandler? _errorHandler) => + super.noSuchMethod( + Invocation.setter( + #errorHandler, + _errorHandler, + ), + returnValueForMissingStub: null, + ); + + @override + Map get preContained => (super.noSuchMethod( + Invocation.getter(#preContained), + returnValue: {}, + ) as Map); + + @override + _i4.Router<_i14.RequestHandler> get optimizedRouter => (super.noSuchMethod( + Invocation.getter(#optimizedRouter), + returnValue: _FakeRouter_2<_i14.RequestHandler>( + this, + Invocation.getter(#optimizedRouter), + ), + ) as _i4.Router<_i14.RequestHandler>); + + @override + List<_i10.Application> get children => (super.noSuchMethod( + Invocation.getter(#children), + returnValue: <_i10.Application>[], + ) as List<_i10.Application>); + + @override + Map get controllers => (super.noSuchMethod( + Invocation.getter(#controllers), + returnValue: {}, + ) as Map); + + @override + _i5.Logger get logger => (super.noSuchMethod( + Invocation.getter(#logger), + returnValue: _FakeLogger_3( + this, + Invocation.getter(#logger), + ), + ) as _i5.Logger); + + @override + set logger(_i5.Logger? log) => super.noSuchMethod( + Invocation.setter( + #logger, + log, + ), + returnValueForMissingStub: null, + ); + + @override + Map get configuration => (super.noSuchMethod( + Invocation.getter(#configuration), + returnValue: {}, + ) as Map); + + @override + _i6.Container get container => (super.noSuchMethod( + Invocation.getter(#container), + returnValue: _FakeContainer_4( + this, + Invocation.getter(#container), + ), + ) as _i6.Container); + + @override + Map> get services => + (super.noSuchMethod( + Invocation.getter(#services), + returnValue: >{}, + ) as Map>); + + @override + _i7.Stream<_i8.Service> get onService => + (super.noSuchMethod( + Invocation.getter(#onService), + returnValue: _i7.Stream<_i8.Service>.empty(), + ) as _i7.Stream<_i8.Service>); + + @override + List<_i14.RequestHandler> get middleware => (super.noSuchMethod( + Invocation.getter(#middleware), + returnValue: <_i14.RequestHandler>[], + ) as List<_i14.RequestHandler>); + + @override + Map> get mounted => + (super.noSuchMethod( + Invocation.getter(#mounted), + returnValue: >{}, + ) as Map>); + + @override + List<_i4.Route<_i14.RequestHandler>> get routes => (super.noSuchMethod( + Invocation.getter(#routes), + returnValue: <_i4.Route<_i14.RequestHandler>>[], + ) as List<_i4.Route<_i14.RequestHandler>>); + + @override + _i4.Route<_i14.RequestHandler> addRoute( + String? method, + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #addRoute, + [ + method, + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #addRoute, + [ + method, + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.SymlinkRoute<_i14.RequestHandler> mount( + String? path, + _i4.Router<_i14.RequestHandler>? router, + ) => + (super.noSuchMethod( + Invocation.method( + #mount, + [ + path, + router, + ], + ), + returnValue: _FakeSymlinkRoute_6<_i14.RequestHandler>( + this, + Invocation.method( + #mount, + [ + path, + router, + ], + ), + ), + ) as _i4.SymlinkRoute<_i14.RequestHandler>); + + @override + void bootstrapContainer() => super.noSuchMethod( + Invocation.method( + #bootstrapContainer, + [], + ), + returnValueForMissingStub: null, + ); + + @override + _i7.Future close() => (super.noSuchMethod( + Invocation.method( + #close, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + void dumpTree({ + dynamic Function(String)? callback, + String? header = r'Dumping route tree:', + String? tab = r' ', + bool? showMatchers = false, + }) => + super.noSuchMethod( + Invocation.method( + #dumpTree, + [], + { + #callback: callback, + #header: header, + #tab: tab, + #showMatchers: showMatchers, + }, + ), + returnValueForMissingStub: null, + ); + + @override + _i7.Future getHandlerResult( + dynamic handler, + _i16.RequestContext? req, + _i17.ResponseContext? res, + ) => + (super.noSuchMethod( + Invocation.method( + #getHandlerResult, + [ + handler, + req, + res, + ], + ), + returnValue: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future executeHandler( + dynamic handler, + _i16.RequestContext? req, + _i17.ResponseContext? res, + ) => + (super.noSuchMethod( + Invocation.method( + #executeHandler, + [ + handler, + req, + res, + ], + ), + returnValue: _i7.Future.value(false), + ) as _i7.Future); + + @override + void optimizeForProduction({bool? force = false}) => super.noSuchMethod( + Invocation.method( + #optimizeForProduction, + [], + {#force: force}, + ), + returnValueForMissingStub: null, + ); + + @override + _i7.Future runContained( + Function? handler, + _i16.RequestContext? req, + _i17.ResponseContext? res, [ + _i6.Container? container, + ]) => + (super.noSuchMethod( + Invocation.method( + #runContained, + [ + handler, + req, + res, + container, + ], + ), + returnValue: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future runReflected( + Function? handler, + _i16.RequestContext? req, + _i17.ResponseContext? res, [ + _i6.Container? container, + ]) => + (super.noSuchMethod( + Invocation.method( + #runReflected, + [ + handler, + req, + res, + container, + ], + ), + returnValue: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future configure(_i10.PlatformConfigurer? configurer) => + (super.noSuchMethod( + Invocation.method( + #configure, + [configurer], + ), + returnValue: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future mountController([Type? type]) => + (super.noSuchMethod( + Invocation.method( + #mountController, + [type], + ), + returnValue: _i19.ifNotNull( + _i19.dummyValueOrNull( + this, + Invocation.method( + #mountController, + [type], + ), + ), + (T v) => _i7.Future.value(v), + ) ?? + _FakeFuture_7( + this, + Invocation.method( + #mountController, + [type], + ), + ), + ) as _i7.Future); + + @override + _i4.Route<_i14.RequestHandler?> fallback(_i14.RequestHandler? handler) => + (super.noSuchMethod( + Invocation.method( + #fallback, + [handler], + ), + returnValue: _FakeRoute_5<_i14.RequestHandler?>( + this, + Invocation.method( + #fallback, + [handler], + ), + ), + ) as _i4.Route<_i14.RequestHandler?>); + + @override + _i9.HookedService use>( + String? path, + T? service, + ) => + (super.noSuchMethod( + Invocation.method( + #use, + [ + path, + service, + ], + ), + returnValue: _FakeHookedService_8( + this, + Invocation.method( + #use, + [ + path, + service, + ], + ), + ), + ) as _i9.HookedService); + + @override + T? findService>(Pattern? path) => + (super.noSuchMethod(Invocation.method( + #findService, + [path], + )) as T?); + + @override + _i8.Service? findServiceOf(Pattern? path) => + (super.noSuchMethod(Invocation.method( + #findServiceOf, + [path], + )) as _i8.Service?); + + @override + _i9.HookedService? + findHookedService>( + Pattern? path) => + (super.noSuchMethod(Invocation.method( + #findHookedService, + [path], + )) as _i9.HookedService?); + + @override + void enableCache() => super.noSuchMethod( + Invocation.method( + #enableCache, + [], + ), + returnValueForMissingStub: null, + ); + + @override + _i4.ChainedRouter<_i14.RequestHandler> chain( + Iterable<_i14.RequestHandler>? middleware) => + (super.noSuchMethod( + Invocation.method( + #chain, + [middleware], + ), + returnValue: _FakeChainedRouter_9<_i14.RequestHandler>( + this, + Invocation.method( + #chain, + [middleware], + ), + ), + ) as _i4.ChainedRouter<_i14.RequestHandler>); + + @override + _i4.Router<_i14.RequestHandler> clone() => (super.noSuchMethod( + Invocation.method( + #clone, + [], + ), + returnValue: _FakeRouter_2<_i14.RequestHandler>( + this, + Invocation.method( + #clone, + [], + ), + ), + ) as _i4.Router<_i14.RequestHandler>); + + @override + _i4.SymlinkRoute<_i14.RequestHandler> group( + String? path, + void Function(_i4.Router<_i14.RequestHandler>)? callback, { + Iterable<_i14.RequestHandler>? middleware = const [], + String? name = r'', + }) => + (super.noSuchMethod( + Invocation.method( + #group, + [ + path, + callback, + ], + { + #middleware: middleware, + #name: name, + }, + ), + returnValue: _FakeSymlinkRoute_6<_i14.RequestHandler>( + this, + Invocation.method( + #group, + [ + path, + callback, + ], + { + #middleware: middleware, + #name: name, + }, + ), + ), + ) as _i4.SymlinkRoute<_i14.RequestHandler>); + + @override + _i7.Future<_i4.SymlinkRoute<_i14.RequestHandler>> groupAsync( + String? path, + _i7.FutureOr Function(_i4.Router<_i14.RequestHandler>)? callback, { + Iterable<_i14.RequestHandler>? middleware = const [], + String? name = r'', + }) => + (super.noSuchMethod( + Invocation.method( + #groupAsync, + [ + path, + callback, + ], + { + #middleware: middleware, + #name: name, + }, + ), + returnValue: _i7.Future<_i4.SymlinkRoute<_i14.RequestHandler>>.value( + _FakeSymlinkRoute_6<_i14.RequestHandler>( + this, + Invocation.method( + #groupAsync, + [ + path, + callback, + ], + { + #middleware: middleware, + #name: name, + }, + ), + )), + ) as _i7.Future<_i4.SymlinkRoute<_i14.RequestHandler>>); + + @override + String navigate( + Iterable? linkParams, { + bool? absolute = true, + }) => + (super.noSuchMethod( + Invocation.method( + #navigate, + [linkParams], + {#absolute: absolute}, + ), + returnValue: _i19.dummyValue( + this, + Invocation.method( + #navigate, + [linkParams], + {#absolute: absolute}, + ), + ), + ) as String); + + @override + bool resolve( + String? absolute, + String? relative, + List<_i4.RoutingResult<_i14.RequestHandler?>>? out, { + String? method = r'GET', + bool? strip = true, + }) => + (super.noSuchMethod( + Invocation.method( + #resolve, + [ + absolute, + relative, + out, + ], + { + #method: method, + #strip: strip, + }, + ), + returnValue: false, + ) as bool); + + @override + Iterable<_i4.RoutingResult<_i14.RequestHandler>> resolveAbsolute( + String? path, { + String? method = r'GET', + bool? strip = true, + }) => + (super.noSuchMethod( + Invocation.method( + #resolveAbsolute, + [path], + { + #method: method, + #strip: strip, + }, + ), + returnValue: <_i4.RoutingResult<_i14.RequestHandler>>[], + ) as Iterable<_i4.RoutingResult<_i14.RequestHandler>>); + + @override + Iterable<_i4.RoutingResult<_i14.RequestHandler>> resolveAll( + String? absolute, + String? relative, { + String? method = r'GET', + bool? strip = true, + }) => + (super.noSuchMethod( + Invocation.method( + #resolveAll, + [ + absolute, + relative, + ], + { + #method: method, + #strip: strip, + }, + ), + returnValue: <_i4.RoutingResult<_i14.RequestHandler>>[], + ) as Iterable<_i4.RoutingResult<_i14.RequestHandler>>); + + @override + _i4.Route<_i14.RequestHandler> all( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #all, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #all, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route<_i14.RequestHandler> delete( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #delete, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #delete, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route<_i14.RequestHandler> get( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #get, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #get, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route<_i14.RequestHandler> head( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #head, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #head, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route<_i14.RequestHandler> options( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const {}, + }) => + (super.noSuchMethod( + Invocation.method( + #options, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #options, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route<_i14.RequestHandler> post( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #post, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #post, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route<_i14.RequestHandler> patch( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #patch, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #patch, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route put( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #put, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5( + this, + Invocation.method( + #put, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route); +} + +/// A class which mocks [ServiceProvider]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockServiceProvider extends _i1.Mock implements _i20.ServiceProvider { + MockServiceProvider() { + _i1.throwOnMissingStub(this); + } + + @override + _i10.Application get app => (super.noSuchMethod( + Invocation.getter(#app), + returnValue: _FakeApplication_10( + this, + Invocation.getter(#app), + ), + ) as _i10.Application); + + @override + set app(_i10.Application? _app) => super.noSuchMethod( + Invocation.setter( + #app, + _app, + ), + returnValueForMissingStub: null, + ); + + @override + _i6.Container get container => (super.noSuchMethod( + Invocation.getter(#container), + returnValue: _FakeContainer_4( + this, + Invocation.getter(#container), + ), + ) as _i6.Container); + + @override + set container(_i6.Container? _container) => super.noSuchMethod( + Invocation.setter( + #container, + _container, + ), + returnValueForMissingStub: null, + ); + + @override + Map get config => (super.noSuchMethod( + Invocation.getter(#config), + returnValue: {}, + ) as Map); + + @override + bool get isEnabled => (super.noSuchMethod( + Invocation.getter(#isEnabled), + returnValue: false, + ) as bool); + + @override + bool get isDeferred => (super.noSuchMethod( + Invocation.getter(#isDeferred), + returnValue: false, + ) as bool); + + @override + List get dependencies => (super.noSuchMethod( + Invocation.getter(#dependencies), + returnValue: [], + ) as List); + + @override + void configure(Map? options) => super.noSuchMethod( + Invocation.method( + #configure, + [options], + ), + returnValueForMissingStub: null, + ); + + @override + void setEnabled(bool? enabled) => super.noSuchMethod( + Invocation.method( + #setEnabled, + [enabled], + ), + returnValueForMissingStub: null, + ); + + @override + void setDeferred(bool? deferred) => super.noSuchMethod( + Invocation.method( + #setDeferred, + [deferred], + ), + returnValueForMissingStub: null, + ); + + @override + void registerWithContainer(_i6.Container? container) => super.noSuchMethod( + Invocation.method( + #registerWithContainer, + [container], + ), + returnValueForMissingStub: null, + ); + + @override + _i7.Future register() => (super.noSuchMethod( + Invocation.method( + #register, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future beforeBoot() => (super.noSuchMethod( + Invocation.method( + #beforeBoot, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future boot() => (super.noSuchMethod( + Invocation.method( + #boot, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future afterBoot() => (super.noSuchMethod( + Invocation.method( + #afterBoot, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); +} + +/// A class which mocks [ServiceProviderManager]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockServiceProviderManager extends _i1.Mock + implements _i21.ServiceProviderManager { + MockServiceProviderManager() { + _i1.throwOnMissingStub(this); + } + + @override + _i10.Application get app => (super.noSuchMethod( + Invocation.getter(#app), + returnValue: _FakeApplication_10( + this, + Invocation.getter(#app), + ), + ) as _i10.Application); + + @override + _i6.Container get container => (super.noSuchMethod( + Invocation.getter(#container), + returnValue: _FakeContainer_4( + this, + Invocation.getter(#container), + ), + ) as _i6.Container); + + @override + void setLogLevel(_i5.Level? level) => super.noSuchMethod( + Invocation.method( + #setLogLevel, + [level], + ), + returnValueForMissingStub: null, + ); + + @override + _i7.Future register(_i20.ServiceProvider? provider) => + (super.noSuchMethod( + Invocation.method( + #register, + [provider], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + void unregister(Type? providerType) => super.noSuchMethod( + Invocation.method( + #unregister, + [providerType], + ), + returnValueForMissingStub: null, + ); + + @override + _i7.Future bootAll() => (super.noSuchMethod( + Invocation.method( + #bootAll, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future bootDeferredProvider(Type? providerType) => + (super.noSuchMethod( + Invocation.method( + #bootDeferredProvider, + [providerType], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future discoverProviders() => (super.noSuchMethod( + Invocation.method( + #discoverProviders, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); +} + +/// A class which mocks [Container]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockContainer extends _i1.Mock implements _i6.Container { + MockContainer() { + _i1.throwOnMissingStub(this); + } + + @override + _i6.Reflector get reflector => (super.noSuchMethod( + Invocation.getter(#reflector), + returnValue: _FakeReflector_11( + this, + Invocation.getter(#reflector), + ), + ) as _i6.Reflector); + + @override + bool get isRoot => (super.noSuchMethod( + Invocation.getter(#isRoot), + returnValue: false, + ) as bool); + + @override + _i6.Container createChild() => (super.noSuchMethod( + Invocation.method( + #createChild, + [], + ), + returnValue: _FakeContainer_4( + this, + Invocation.method( + #createChild, + [], + ), + ), + ) as _i6.Container); + + @override + bool has([Type? t]) => (super.noSuchMethod( + Invocation.method( + #has, + [t], + ), + returnValue: false, + ) as bool); + + @override + bool hasNamed(String? name) => (super.noSuchMethod( + Invocation.method( + #hasNamed, + [name], + ), + returnValue: false, + ) as bool); + + @override + _i7.Future makeAsync([Type? type]) => (super.noSuchMethod( + Invocation.method( + #makeAsync, + [type], + ), + returnValue: _i19.ifNotNull( + _i19.dummyValueOrNull( + this, + Invocation.method( + #makeAsync, + [type], + ), + ), + (T v) => _i7.Future.value(v), + ) ?? + _FakeFuture_7( + this, + Invocation.method( + #makeAsync, + [type], + ), + ), + ) as _i7.Future); + + @override + T make([Type? type]) => (super.noSuchMethod( + Invocation.method( + #make, + [type], + ), + returnValue: _i19.dummyValue( + this, + Invocation.method( + #make, + [type], + ), + ), + ) as T); + + @override + T Function(_i6.Container) registerLazySingleton( + T Function(_i6.Container)? f, { + Type? as, + }) => + (super.noSuchMethod( + Invocation.method( + #registerLazySingleton, + [f], + {#as: as}, + ), + returnValue: (_i6.Container __p0) => _i19.dummyValue( + this, + Invocation.method( + #registerLazySingleton, + [f], + {#as: as}, + ), + ), + ) as T Function(_i6.Container)); + + @override + T Function(_i6.Container) registerFactory( + T Function(_i6.Container)? f, { + Type? as, + }) => + (super.noSuchMethod( + Invocation.method( + #registerFactory, + [f], + {#as: as}, + ), + returnValue: (_i6.Container __p0) => _i19.dummyValue( + this, + Invocation.method( + #registerFactory, + [f], + {#as: as}, + ), + ), + ) as T Function(_i6.Container)); + + @override + T registerSingleton( + T? object, { + Type? as, + }) => + (super.noSuchMethod( + Invocation.method( + #registerSingleton, + [object], + {#as: as}, + ), + returnValue: _i19.dummyValue( + this, + Invocation.method( + #registerSingleton, + [object], + {#as: as}, + ), + ), + ) as T); + + @override + T findByName(String? name) => (super.noSuchMethod( + Invocation.method( + #findByName, + [name], + ), + returnValue: _i19.dummyValue( + this, + Invocation.method( + #findByName, + [name], + ), + ), + ) as T); + + @override + T registerNamedSingleton( + String? name, + T? object, + ) => + (super.noSuchMethod( + Invocation.method( + #registerNamedSingleton, + [ + name, + object, + ], + ), + returnValue: _i19.dummyValue( + this, + Invocation.method( + #registerNamedSingleton, + [ + name, + object, + ], + ), + ), + ) as T); +} diff --git a/packages/core/test/provider/provider_discovery_test.dart b/packages/core/test/provider/provider_discovery_test.dart new file mode 100644 index 0000000..29b6458 --- /dev/null +++ b/packages/core/test/provider/provider_discovery_test.dart @@ -0,0 +1,33 @@ +import 'package:test/test.dart'; +import 'package:platform_core/src/provider/provider_discovery.dart'; +import 'package:platform_core/src/provider/service_provider.dart'; + +class TestServiceProvider extends ServiceProvider { + @override + Future register() async {} + + @override + Future boot() async {} +} + +void main() { + group('ManualProviderDiscovery', () { + late ManualProviderDiscovery discovery; + + setUp(() { + discovery = ManualProviderDiscovery(); + }); + + test('registerProviderType adds type and factory', () { + discovery.registerProviderType( + TestServiceProvider, () => TestServiceProvider()); + + expect(discovery.discoverProviders(), contains(TestServiceProvider)); + expect(discovery.createInstance(TestServiceProvider), + isA()); + }); + }); + + // Note: Testing MirrorProviderDiscovery is challenging in a unit test environment + // due to its reliance on runtime reflection. Consider integration tests for this. +} diff --git a/packages/core/test/provider/service_provider_config_test.dart b/packages/core/test/provider/service_provider_config_test.dart new file mode 100644 index 0000000..65e090e --- /dev/null +++ b/packages/core/test/provider/service_provider_config_test.dart @@ -0,0 +1,27 @@ +import 'package:test/test.dart'; +import 'package:platform_core/src/provider/service_provider_config.dart'; + +void main() { + group('ServiceProviderConfig', () { + test('fromMap creates correct config', () { + final map = { + 'providers': [ + { + 'type': 'TestServiceProvider', + 'deferred': true, + 'config': {'key': 'value'} + }, + {'type': 'AnotherServiceProvider', 'deferred': false}, + ] + }; + + final config = ServiceProviderConfig.fromMap(map); + + expect(config.providers.length, equals(2)); + expect(config.deferredProviders.length, equals(1)); + expect(config.providerConfigs.length, equals(1)); + // Note: This test assumes you've implemented _getTypeFromString to handle these provider types + // You might need to adjust this part of the test based on your actual implementation + }); + }); +} diff --git a/packages/core/test/provider/service_provider_integration_test.dart b/packages/core/test/provider/service_provider_integration_test.dart new file mode 100644 index 0000000..4798b01 --- /dev/null +++ b/packages/core/test/provider/service_provider_integration_test.dart @@ -0,0 +1,87 @@ +import 'package:test/test.dart'; +import 'package:platform_core/core.dart'; +import 'package:platform_core/src/provider/platform_with_providers.dart'; +import 'package:platform_core/src/provider/service_provider.dart'; +import 'package:platform_core/src/provider/service_provider_config.dart'; + +class TestService { + String getData() => 'Test Data'; +} + +class TestServiceProvider extends ServiceProvider { + @override + Future register() async { + container.registerSingleton((container) => TestService()); + } + + @override + Future boot() async { + await Future.delayed(Duration(milliseconds: 100)); + } +} + +class DeferredServiceProvider extends ServiceProvider { + @override + Future register() async { + container.registerSingleton((container) => 'Deferred Service'); + } + + @override + Future boot() async { + await Future.delayed(Duration(milliseconds: 100)); + } +} + +void main() { + late Application app; + late PlatformWithProviders platformWithProviders; + + setUp(() async { + app = Application(); + platformWithProviders = PlatformWithProviders(app); + // Allow some time for the platform to initialize + await Future.delayed(Duration(milliseconds: 100)); + }); + + tearDown(() async { + await app.close(); + }); + + group('Service Provider Integration Tests', () { + test('Manual provider registration works', () async { + await platformWithProviders + .registerServiceProvider(TestServiceProvider()); + await platformWithProviders.bootServiceProviders(); + + var testService = platformWithProviders.container.make(); + expect(testService, isNotNull); + expect(testService.getData(), equals('Test Data')); + }); + + test('Deferred provider is not booted initially', () async { + var config = ServiceProviderConfig( + providers: [DeferredServiceProvider], + deferredProviders: {DeferredServiceProvider: true}, + ); + await platformWithProviders.registerProvidersFromConfig(config); + await platformWithProviders.bootServiceProviders(); + + expect(() => platformWithProviders.container.make(), + throwsException); + }); + + test('Deferred provider can be booted on demand', () async { + var config = ServiceProviderConfig( + providers: [DeferredServiceProvider], + deferredProviders: {DeferredServiceProvider: true}, + ); + await platformWithProviders.registerProvidersFromConfig(config); + await platformWithProviders.bootServiceProviders(); + await platformWithProviders + .bootDeferredServiceProvider(DeferredServiceProvider); + + var deferredService = platformWithProviders.container.make(); + expect(deferredService, equals('Deferred Service')); + }); + }); +} diff --git a/packages/core/test/provider/service_provider_manager_test.dart b/packages/core/test/provider/service_provider_manager_test.dart new file mode 100644 index 0000000..4c6269a --- /dev/null +++ b/packages/core/test/provider/service_provider_manager_test.dart @@ -0,0 +1,93 @@ +import 'package:test/test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:mockito/annotations.dart'; +import 'package:platform_core/core.dart'; +import 'package:platform_core/src/provider/service_provider_manager.dart'; +import 'package:platform_core/src/provider/service_provider.dart'; +import 'package:platform_core/src/provider/provider_discovery.dart'; +import 'package:platform_container/container.dart' as container; +import 'service_provider_manager_test.mocks.dart'; + +//class MockAngel extends Mock implements Application {} + +//class MockServiceProvider extends Mock implements ServiceProvider {} + +//class MockProviderDiscovery extends Mock implements ProviderDiscovery {} + +// Generate mocks +@GenerateMocks( + [Application, ServiceProvider, ProviderDiscovery, container.Container]) +void main() { + group('ServiceProviderManager', () { + late ServiceProviderManager manager; + late Application mockAngel; + late MockProviderDiscovery mockDiscovery; + late MockContainer mockContainer; + + setUp(() { + mockAngel = Application(); + mockDiscovery = MockProviderDiscovery(); + mockContainer = MockContainer(); + when(mockAngel.container).thenReturn(mockContainer); + manager = ServiceProviderManager(mockAngel, mockDiscovery); + }); + + test('register adds provider and calls register method', () async { + final provider = MockServiceProvider(); + await manager.register(provider); + + verify(provider.registerWithContainer(any)).called(1); + verify(provider.register()).called(1); + }); + + test('bootAll calls boot for all providers', () async { + final provider1 = MockServiceProvider(); + final provider2 = MockServiceProvider(); + + when(provider1.isEnabled).thenReturn(true); + when(provider2.isEnabled).thenReturn(true); + when(provider1.isDeferred).thenReturn(false); + when(provider2.isDeferred).thenReturn(false); + + await manager.register(provider1); + await manager.register(provider2); + + await manager.bootAll(); + + verify(provider1.beforeBoot()).called(1); + verify(provider1.boot()).called(1); + verify(provider1.afterBoot()).called(1); + verify(provider2.beforeBoot()).called(1); + verify(provider2.boot()).called(1); + verify(provider2.afterBoot()).called(1); + }); + + test('bootDeferredProvider boots only the specified provider', () async { + final provider1 = MockServiceProvider(); + final provider2 = MockServiceProvider(); + + when(provider1.isDeferred).thenReturn(true); + when(provider2.isDeferred).thenReturn(true); + + await manager.register(provider1); + await manager.register(provider2); + + await manager.bootDeferredProvider(provider1.runtimeType); + + verify(provider1.beforeBoot()).called(1); + verify(provider1.boot()).called(1); + verify(provider1.afterBoot()).called(1); + verifyNever(provider2.beforeBoot()); + verifyNever(provider2.boot()); + verifyNever(provider2.afterBoot()); + }); + + test('unregister removes the provider', () async { + final provider = MockServiceProvider(); + await manager.register(provider); + manager.unregister(provider.runtimeType); + + expect(manager.getProvider(), isNull); + }); + }); +} diff --git a/packages/core/test/provider/service_provider_manager_test.mocks.dart b/packages/core/test/provider/service_provider_manager_test.mocks.dart new file mode 100644 index 0000000..207a292 --- /dev/null +++ b/packages/core/test/provider/service_provider_manager_test.mocks.dart @@ -0,0 +1,1462 @@ +// Mocks generated by Mockito 5.4.4 from annotations +// in platform_core/test/provider/service_provider_manager_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i7; +import 'dart:convert' as _i13; + +import 'package:belatuk_combinator/belatuk_combinator.dart' as _i12; +import 'package:logging/logging.dart' as _i5; +import 'package:mime/mime.dart' as _i2; +import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i19; +import 'package:platform_container/container.dart' as _i6; +import 'package:platform_core/core.dart' as _i10; +import 'package:platform_core/src/core/controller.dart' as _i18; +import 'package:platform_core/src/core/env.dart' as _i3; +import 'package:platform_core/src/core/hooked_service.dart' as _i9; +import 'package:platform_core/src/core/request_context.dart' as _i16; +import 'package:platform_core/src/core/response_context.dart' as _i17; +import 'package:platform_core/src/core/routable.dart' as _i14; +import 'package:platform_core/src/core/service.dart' as _i8; +import 'package:platform_core/src/provider/provider_discovery.dart' as _i21; +import 'package:platform_core/src/provider/service_provider.dart' as _i20; +import 'package:platform_exceptions/http_exception.dart' as _i15; +import 'package:platform_route/route.dart' as _i4; +import 'package:tuple/tuple.dart' as _i11; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeMimeTypeResolver_0 extends _i1.SmartFake + implements _i2.MimeTypeResolver { + _FakeMimeTypeResolver_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeProtevusEnvironment_1 extends _i1.SmartFake + implements _i3.ProtevusEnvironment { + _FakeProtevusEnvironment_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeRouter_2 extends _i1.SmartFake implements _i4.Router { + _FakeRouter_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeLogger_3 extends _i1.SmartFake implements _i5.Logger { + _FakeLogger_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeContainer_4 extends _i1.SmartFake implements _i6.Container { + _FakeContainer_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeRoute_5 extends _i1.SmartFake implements _i4.Route { + _FakeRoute_5( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeSymlinkRoute_6 extends _i1.SmartFake + implements _i4.SymlinkRoute { + _FakeSymlinkRoute_6( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeFuture_7 extends _i1.SmartFake implements _i7.Future { + _FakeFuture_7( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeHookedService_8> + extends _i1.SmartFake implements _i9.HookedService { + _FakeHookedService_8( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeChainedRouter_9 extends _i1.SmartFake + implements _i4.ChainedRouter { + _FakeChainedRouter_9( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeApplication_10 extends _i1.SmartFake implements _i10.Application { + _FakeApplication_10( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeReflector_11 extends _i1.SmartFake implements _i6.Reflector { + _FakeReflector_11( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [Application]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockApplication extends _i1.Mock implements _i10.Application { + MockApplication() { + _i1.throwOnMissingStub(this); + } + + @override + Map< + String, + _i11.Tuple4< + List, + Map, + _i12.ParseResult<_i4.RouteResult>, + _i4.MiddlewarePipeline>> get handlerCache => + (super.noSuchMethod( + Invocation.getter(#handlerCache), + returnValue: , + Map, + _i12.ParseResult<_i4.RouteResult>, + _i4.MiddlewarePipeline>>{}, + ) as Map< + String, + _i11.Tuple4< + List, + Map, + _i12.ParseResult<_i4.RouteResult>, + _i4.MiddlewarePipeline>>); + + @override + Map, List>> get encoders => + (super.noSuchMethod( + Invocation.getter(#encoders), + returnValue: , List>>{}, + ) as Map, List>>); + + @override + _i2.MimeTypeResolver get mimeTypeResolver => (super.noSuchMethod( + Invocation.getter(#mimeTypeResolver), + returnValue: _FakeMimeTypeResolver_0( + this, + Invocation.getter(#mimeTypeResolver), + ), + ) as _i2.MimeTypeResolver); + + @override + set serializer(_i7.FutureOr Function(dynamic)? _serializer) => + super.noSuchMethod( + Invocation.setter( + #serializer, + _serializer, + ), + returnValueForMissingStub: null, + ); + + @override + bool get allowMethodOverrides => (super.noSuchMethod( + Invocation.getter(#allowMethodOverrides), + returnValue: false, + ) as bool); + + @override + set allowMethodOverrides(bool? _allowMethodOverrides) => super.noSuchMethod( + Invocation.setter( + #allowMethodOverrides, + _allowMethodOverrides, + ), + returnValueForMissingStub: null, + ); + + @override + _i3.ProtevusEnvironment get environment => (super.noSuchMethod( + Invocation.getter(#environment), + returnValue: _FakeProtevusEnvironment_1( + this, + Invocation.getter(#environment), + ), + ) as _i3.ProtevusEnvironment); + + @override + List<_i10.PlatformConfigurer> get startupHooks => (super.noSuchMethod( + Invocation.getter(#startupHooks), + returnValue: <_i10.PlatformConfigurer>[], + ) as List<_i10.PlatformConfigurer>); + + @override + List<_i10.PlatformConfigurer> get shutdownHooks => (super.noSuchMethod( + Invocation.getter(#shutdownHooks), + returnValue: <_i10.PlatformConfigurer>[], + ) as List<_i10.PlatformConfigurer>); + + @override + List<_i14.RequestHandler> get responseFinalizers => (super.noSuchMethod( + Invocation.getter(#responseFinalizers), + returnValue: <_i14.RequestHandler>[], + ) as List<_i14.RequestHandler>); + + @override + set viewGenerator(_i10.ViewGenerator? _viewGenerator) => super.noSuchMethod( + Invocation.setter( + #viewGenerator, + _viewGenerator, + ), + returnValueForMissingStub: null, + ); + + @override + _i10.PlatformErrorHandler get errorHandler => (super.noSuchMethod( + Invocation.getter(#errorHandler), + returnValue: ( + _i15.PlatformHttpException e, + _i16.RequestContext req, + _i17.ResponseContext res, + ) => + null, + ) as _i10.PlatformErrorHandler); + + @override + set errorHandler(_i10.PlatformErrorHandler? _errorHandler) => + super.noSuchMethod( + Invocation.setter( + #errorHandler, + _errorHandler, + ), + returnValueForMissingStub: null, + ); + + @override + Map get preContained => (super.noSuchMethod( + Invocation.getter(#preContained), + returnValue: {}, + ) as Map); + + @override + _i4.Router<_i14.RequestHandler> get optimizedRouter => (super.noSuchMethod( + Invocation.getter(#optimizedRouter), + returnValue: _FakeRouter_2<_i14.RequestHandler>( + this, + Invocation.getter(#optimizedRouter), + ), + ) as _i4.Router<_i14.RequestHandler>); + + @override + List<_i10.Application> get children => (super.noSuchMethod( + Invocation.getter(#children), + returnValue: <_i10.Application>[], + ) as List<_i10.Application>); + + @override + Map get controllers => (super.noSuchMethod( + Invocation.getter(#controllers), + returnValue: {}, + ) as Map); + + @override + _i5.Logger get logger => (super.noSuchMethod( + Invocation.getter(#logger), + returnValue: _FakeLogger_3( + this, + Invocation.getter(#logger), + ), + ) as _i5.Logger); + + @override + set logger(_i5.Logger? log) => super.noSuchMethod( + Invocation.setter( + #logger, + log, + ), + returnValueForMissingStub: null, + ); + + @override + Map get configuration => (super.noSuchMethod( + Invocation.getter(#configuration), + returnValue: {}, + ) as Map); + + @override + _i6.Container get container => (super.noSuchMethod( + Invocation.getter(#container), + returnValue: _FakeContainer_4( + this, + Invocation.getter(#container), + ), + ) as _i6.Container); + + @override + Map> get services => + (super.noSuchMethod( + Invocation.getter(#services), + returnValue: >{}, + ) as Map>); + + @override + _i7.Stream<_i8.Service> get onService => + (super.noSuchMethod( + Invocation.getter(#onService), + returnValue: _i7.Stream<_i8.Service>.empty(), + ) as _i7.Stream<_i8.Service>); + + @override + List<_i14.RequestHandler> get middleware => (super.noSuchMethod( + Invocation.getter(#middleware), + returnValue: <_i14.RequestHandler>[], + ) as List<_i14.RequestHandler>); + + @override + Map> get mounted => + (super.noSuchMethod( + Invocation.getter(#mounted), + returnValue: >{}, + ) as Map>); + + @override + List<_i4.Route<_i14.RequestHandler>> get routes => (super.noSuchMethod( + Invocation.getter(#routes), + returnValue: <_i4.Route<_i14.RequestHandler>>[], + ) as List<_i4.Route<_i14.RequestHandler>>); + + @override + _i4.Route<_i14.RequestHandler> addRoute( + String? method, + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #addRoute, + [ + method, + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #addRoute, + [ + method, + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.SymlinkRoute<_i14.RequestHandler> mount( + String? path, + _i4.Router<_i14.RequestHandler>? router, + ) => + (super.noSuchMethod( + Invocation.method( + #mount, + [ + path, + router, + ], + ), + returnValue: _FakeSymlinkRoute_6<_i14.RequestHandler>( + this, + Invocation.method( + #mount, + [ + path, + router, + ], + ), + ), + ) as _i4.SymlinkRoute<_i14.RequestHandler>); + + @override + void bootstrapContainer() => super.noSuchMethod( + Invocation.method( + #bootstrapContainer, + [], + ), + returnValueForMissingStub: null, + ); + + @override + _i7.Future close() => (super.noSuchMethod( + Invocation.method( + #close, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + void dumpTree({ + dynamic Function(String)? callback, + String? header = r'Dumping route tree:', + String? tab = r' ', + bool? showMatchers = false, + }) => + super.noSuchMethod( + Invocation.method( + #dumpTree, + [], + { + #callback: callback, + #header: header, + #tab: tab, + #showMatchers: showMatchers, + }, + ), + returnValueForMissingStub: null, + ); + + @override + _i7.Future getHandlerResult( + dynamic handler, + _i16.RequestContext? req, + _i17.ResponseContext? res, + ) => + (super.noSuchMethod( + Invocation.method( + #getHandlerResult, + [ + handler, + req, + res, + ], + ), + returnValue: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future executeHandler( + dynamic handler, + _i16.RequestContext? req, + _i17.ResponseContext? res, + ) => + (super.noSuchMethod( + Invocation.method( + #executeHandler, + [ + handler, + req, + res, + ], + ), + returnValue: _i7.Future.value(false), + ) as _i7.Future); + + @override + void optimizeForProduction({bool? force = false}) => super.noSuchMethod( + Invocation.method( + #optimizeForProduction, + [], + {#force: force}, + ), + returnValueForMissingStub: null, + ); + + @override + _i7.Future runContained( + Function? handler, + _i16.RequestContext? req, + _i17.ResponseContext? res, [ + _i6.Container? container, + ]) => + (super.noSuchMethod( + Invocation.method( + #runContained, + [ + handler, + req, + res, + container, + ], + ), + returnValue: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future runReflected( + Function? handler, + _i16.RequestContext? req, + _i17.ResponseContext? res, [ + _i6.Container? container, + ]) => + (super.noSuchMethod( + Invocation.method( + #runReflected, + [ + handler, + req, + res, + container, + ], + ), + returnValue: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future configure(_i10.PlatformConfigurer? configurer) => + (super.noSuchMethod( + Invocation.method( + #configure, + [configurer], + ), + returnValue: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future mountController([Type? type]) => + (super.noSuchMethod( + Invocation.method( + #mountController, + [type], + ), + returnValue: _i19.ifNotNull( + _i19.dummyValueOrNull( + this, + Invocation.method( + #mountController, + [type], + ), + ), + (T v) => _i7.Future.value(v), + ) ?? + _FakeFuture_7( + this, + Invocation.method( + #mountController, + [type], + ), + ), + ) as _i7.Future); + + @override + _i4.Route<_i14.RequestHandler?> fallback(_i14.RequestHandler? handler) => + (super.noSuchMethod( + Invocation.method( + #fallback, + [handler], + ), + returnValue: _FakeRoute_5<_i14.RequestHandler?>( + this, + Invocation.method( + #fallback, + [handler], + ), + ), + ) as _i4.Route<_i14.RequestHandler?>); + + @override + _i9.HookedService use>( + String? path, + T? service, + ) => + (super.noSuchMethod( + Invocation.method( + #use, + [ + path, + service, + ], + ), + returnValue: _FakeHookedService_8( + this, + Invocation.method( + #use, + [ + path, + service, + ], + ), + ), + ) as _i9.HookedService); + + @override + T? findService>(Pattern? path) => + (super.noSuchMethod(Invocation.method( + #findService, + [path], + )) as T?); + + @override + _i8.Service? findServiceOf(Pattern? path) => + (super.noSuchMethod(Invocation.method( + #findServiceOf, + [path], + )) as _i8.Service?); + + @override + _i9.HookedService? + findHookedService>( + Pattern? path) => + (super.noSuchMethod(Invocation.method( + #findHookedService, + [path], + )) as _i9.HookedService?); + + @override + void enableCache() => super.noSuchMethod( + Invocation.method( + #enableCache, + [], + ), + returnValueForMissingStub: null, + ); + + @override + _i4.ChainedRouter<_i14.RequestHandler> chain( + Iterable<_i14.RequestHandler>? middleware) => + (super.noSuchMethod( + Invocation.method( + #chain, + [middleware], + ), + returnValue: _FakeChainedRouter_9<_i14.RequestHandler>( + this, + Invocation.method( + #chain, + [middleware], + ), + ), + ) as _i4.ChainedRouter<_i14.RequestHandler>); + + @override + _i4.Router<_i14.RequestHandler> clone() => (super.noSuchMethod( + Invocation.method( + #clone, + [], + ), + returnValue: _FakeRouter_2<_i14.RequestHandler>( + this, + Invocation.method( + #clone, + [], + ), + ), + ) as _i4.Router<_i14.RequestHandler>); + + @override + _i4.SymlinkRoute<_i14.RequestHandler> group( + String? path, + void Function(_i4.Router<_i14.RequestHandler>)? callback, { + Iterable<_i14.RequestHandler>? middleware = const [], + String? name = r'', + }) => + (super.noSuchMethod( + Invocation.method( + #group, + [ + path, + callback, + ], + { + #middleware: middleware, + #name: name, + }, + ), + returnValue: _FakeSymlinkRoute_6<_i14.RequestHandler>( + this, + Invocation.method( + #group, + [ + path, + callback, + ], + { + #middleware: middleware, + #name: name, + }, + ), + ), + ) as _i4.SymlinkRoute<_i14.RequestHandler>); + + @override + _i7.Future<_i4.SymlinkRoute<_i14.RequestHandler>> groupAsync( + String? path, + _i7.FutureOr Function(_i4.Router<_i14.RequestHandler>)? callback, { + Iterable<_i14.RequestHandler>? middleware = const [], + String? name = r'', + }) => + (super.noSuchMethod( + Invocation.method( + #groupAsync, + [ + path, + callback, + ], + { + #middleware: middleware, + #name: name, + }, + ), + returnValue: _i7.Future<_i4.SymlinkRoute<_i14.RequestHandler>>.value( + _FakeSymlinkRoute_6<_i14.RequestHandler>( + this, + Invocation.method( + #groupAsync, + [ + path, + callback, + ], + { + #middleware: middleware, + #name: name, + }, + ), + )), + ) as _i7.Future<_i4.SymlinkRoute<_i14.RequestHandler>>); + + @override + String navigate( + Iterable? linkParams, { + bool? absolute = true, + }) => + (super.noSuchMethod( + Invocation.method( + #navigate, + [linkParams], + {#absolute: absolute}, + ), + returnValue: _i19.dummyValue( + this, + Invocation.method( + #navigate, + [linkParams], + {#absolute: absolute}, + ), + ), + ) as String); + + @override + bool resolve( + String? absolute, + String? relative, + List<_i4.RoutingResult<_i14.RequestHandler?>>? out, { + String? method = r'GET', + bool? strip = true, + }) => + (super.noSuchMethod( + Invocation.method( + #resolve, + [ + absolute, + relative, + out, + ], + { + #method: method, + #strip: strip, + }, + ), + returnValue: false, + ) as bool); + + @override + Iterable<_i4.RoutingResult<_i14.RequestHandler>> resolveAbsolute( + String? path, { + String? method = r'GET', + bool? strip = true, + }) => + (super.noSuchMethod( + Invocation.method( + #resolveAbsolute, + [path], + { + #method: method, + #strip: strip, + }, + ), + returnValue: <_i4.RoutingResult<_i14.RequestHandler>>[], + ) as Iterable<_i4.RoutingResult<_i14.RequestHandler>>); + + @override + Iterable<_i4.RoutingResult<_i14.RequestHandler>> resolveAll( + String? absolute, + String? relative, { + String? method = r'GET', + bool? strip = true, + }) => + (super.noSuchMethod( + Invocation.method( + #resolveAll, + [ + absolute, + relative, + ], + { + #method: method, + #strip: strip, + }, + ), + returnValue: <_i4.RoutingResult<_i14.RequestHandler>>[], + ) as Iterable<_i4.RoutingResult<_i14.RequestHandler>>); + + @override + _i4.Route<_i14.RequestHandler> all( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #all, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #all, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route<_i14.RequestHandler> delete( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #delete, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #delete, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route<_i14.RequestHandler> get( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #get, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #get, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route<_i14.RequestHandler> head( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #head, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #head, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route<_i14.RequestHandler> options( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const {}, + }) => + (super.noSuchMethod( + Invocation.method( + #options, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #options, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route<_i14.RequestHandler> post( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #post, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #post, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route<_i14.RequestHandler> patch( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #patch, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5<_i14.RequestHandler>( + this, + Invocation.method( + #patch, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route<_i14.RequestHandler>); + + @override + _i4.Route put( + String? path, + _i14.RequestHandler? handler, { + Iterable<_i14.RequestHandler>? middleware = const [], + }) => + (super.noSuchMethod( + Invocation.method( + #put, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + returnValue: _FakeRoute_5( + this, + Invocation.method( + #put, + [ + path, + handler, + ], + {#middleware: middleware}, + ), + ), + ) as _i4.Route); +} + +/// A class which mocks [ServiceProvider]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockServiceProvider extends _i1.Mock implements _i20.ServiceProvider { + MockServiceProvider() { + _i1.throwOnMissingStub(this); + } + + @override + _i10.Application get app => (super.noSuchMethod( + Invocation.getter(#app), + returnValue: _FakeApplication_10( + this, + Invocation.getter(#app), + ), + ) as _i10.Application); + + @override + set app(_i10.Application? _app) => super.noSuchMethod( + Invocation.setter( + #app, + _app, + ), + returnValueForMissingStub: null, + ); + + @override + _i6.Container get container => (super.noSuchMethod( + Invocation.getter(#container), + returnValue: _FakeContainer_4( + this, + Invocation.getter(#container), + ), + ) as _i6.Container); + + @override + set container(_i6.Container? _container) => super.noSuchMethod( + Invocation.setter( + #container, + _container, + ), + returnValueForMissingStub: null, + ); + + @override + Map get config => (super.noSuchMethod( + Invocation.getter(#config), + returnValue: {}, + ) as Map); + + @override + bool get isEnabled => (super.noSuchMethod( + Invocation.getter(#isEnabled), + returnValue: false, + ) as bool); + + @override + bool get isDeferred => (super.noSuchMethod( + Invocation.getter(#isDeferred), + returnValue: false, + ) as bool); + + @override + List get dependencies => (super.noSuchMethod( + Invocation.getter(#dependencies), + returnValue: [], + ) as List); + + @override + void configure(Map? options) => super.noSuchMethod( + Invocation.method( + #configure, + [options], + ), + returnValueForMissingStub: null, + ); + + @override + void setEnabled(bool? enabled) => super.noSuchMethod( + Invocation.method( + #setEnabled, + [enabled], + ), + returnValueForMissingStub: null, + ); + + @override + void setDeferred(bool? deferred) => super.noSuchMethod( + Invocation.method( + #setDeferred, + [deferred], + ), + returnValueForMissingStub: null, + ); + + @override + void registerWithContainer(_i6.Container? container) => super.noSuchMethod( + Invocation.method( + #registerWithContainer, + [container], + ), + returnValueForMissingStub: null, + ); + + @override + _i7.Future register() => (super.noSuchMethod( + Invocation.method( + #register, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future beforeBoot() => (super.noSuchMethod( + Invocation.method( + #beforeBoot, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future boot() => (super.noSuchMethod( + Invocation.method( + #boot, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future afterBoot() => (super.noSuchMethod( + Invocation.method( + #afterBoot, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); +} + +/// A class which mocks [ProviderDiscovery]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockProviderDiscovery extends _i1.Mock implements _i21.ProviderDiscovery { + MockProviderDiscovery() { + _i1.throwOnMissingStub(this); + } + + @override + List discoverProviders() => (super.noSuchMethod( + Invocation.method( + #discoverProviders, + [], + ), + returnValue: [], + ) as List); + + @override + _i20.ServiceProvider? createInstance(Type? type) => + (super.noSuchMethod(Invocation.method( + #createInstance, + [type], + )) as _i20.ServiceProvider?); +} + +/// A class which mocks [Container]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockContainer extends _i1.Mock implements _i6.Container { + MockContainer() { + _i1.throwOnMissingStub(this); + } + + @override + _i6.Reflector get reflector => (super.noSuchMethod( + Invocation.getter(#reflector), + returnValue: _FakeReflector_11( + this, + Invocation.getter(#reflector), + ), + ) as _i6.Reflector); + + @override + bool get isRoot => (super.noSuchMethod( + Invocation.getter(#isRoot), + returnValue: false, + ) as bool); + + @override + _i6.Container createChild() => (super.noSuchMethod( + Invocation.method( + #createChild, + [], + ), + returnValue: _FakeContainer_4( + this, + Invocation.method( + #createChild, + [], + ), + ), + ) as _i6.Container); + + @override + bool has([Type? t]) => (super.noSuchMethod( + Invocation.method( + #has, + [t], + ), + returnValue: false, + ) as bool); + + @override + bool hasNamed(String? name) => (super.noSuchMethod( + Invocation.method( + #hasNamed, + [name], + ), + returnValue: false, + ) as bool); + + @override + _i7.Future makeAsync([Type? type]) => (super.noSuchMethod( + Invocation.method( + #makeAsync, + [type], + ), + returnValue: _i19.ifNotNull( + _i19.dummyValueOrNull( + this, + Invocation.method( + #makeAsync, + [type], + ), + ), + (T v) => _i7.Future.value(v), + ) ?? + _FakeFuture_7( + this, + Invocation.method( + #makeAsync, + [type], + ), + ), + ) as _i7.Future); + + @override + T make([Type? type]) => (super.noSuchMethod( + Invocation.method( + #make, + [type], + ), + returnValue: _i19.dummyValue( + this, + Invocation.method( + #make, + [type], + ), + ), + ) as T); + + @override + T Function(_i6.Container) registerLazySingleton( + T Function(_i6.Container)? f, { + Type? as, + }) => + (super.noSuchMethod( + Invocation.method( + #registerLazySingleton, + [f], + {#as: as}, + ), + returnValue: (_i6.Container __p0) => _i19.dummyValue( + this, + Invocation.method( + #registerLazySingleton, + [f], + {#as: as}, + ), + ), + ) as T Function(_i6.Container)); + + @override + T Function(_i6.Container) registerFactory( + T Function(_i6.Container)? f, { + Type? as, + }) => + (super.noSuchMethod( + Invocation.method( + #registerFactory, + [f], + {#as: as}, + ), + returnValue: (_i6.Container __p0) => _i19.dummyValue( + this, + Invocation.method( + #registerFactory, + [f], + {#as: as}, + ), + ), + ) as T Function(_i6.Container)); + + @override + T registerSingleton( + T? object, { + Type? as, + }) => + (super.noSuchMethod( + Invocation.method( + #registerSingleton, + [object], + {#as: as}, + ), + returnValue: _i19.dummyValue( + this, + Invocation.method( + #registerSingleton, + [object], + {#as: as}, + ), + ), + ) as T); + + @override + T findByName(String? name) => (super.noSuchMethod( + Invocation.method( + #findByName, + [name], + ), + returnValue: _i19.dummyValue( + this, + Invocation.method( + #findByName, + [name], + ), + ), + ) as T); + + @override + T registerNamedSingleton( + String? name, + T? object, + ) => + (super.noSuchMethod( + Invocation.method( + #registerNamedSingleton, + [ + name, + object, + ], + ), + returnValue: _i19.dummyValue( + this, + Invocation.method( + #registerNamedSingleton, + [ + name, + object, + ], + ), + ), + ) as T); +} diff --git a/packages/core/test/provider/service_provider_test.dart b/packages/core/test/provider/service_provider_test.dart new file mode 100644 index 0000000..f1bfc11 --- /dev/null +++ b/packages/core/test/provider/service_provider_test.dart @@ -0,0 +1,32 @@ +import 'package:test/test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:platform_core/src/provider/service_provider.dart'; + +class MockServiceProvider extends Mock implements ServiceProvider {} + +void main() { + group('ServiceProvider', () { + late ServiceProvider provider; + + setUp(() { + provider = MockServiceProvider(); + }); + + test('setEnabled changes isEnabled', () { + when(provider.isEnabled).thenAnswer((_) => true); + provider.setEnabled(false); + verify(provider.setEnabled(false)).called(1); + }); + + test('setDeferred changes isDeferred', () { + when(provider.isDeferred).thenAnswer((_) => false); + provider.setDeferred(true); + verify(provider.setDeferred(true)).called(1); + }); + + test('configure adds to config', () { + provider.configure({'key': 'value'}); + verify(provider.configure({'key': 'value'})).called(1); + }); + }); +}