diff --git a/packages/core/lib/providers.dart b/packages/core/lib/providers.dart deleted file mode 100644 index 20f5669..0000000 --- a/packages/core/lib/providers.dart +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index 0de8957..0000000 --- a/packages/core/lib/src/provider/platform_with_providers.dart +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 41eb41e..0000000 --- a/packages/core/lib/src/provider/provider_discovery.dart +++ /dev/null @@ -1,54 +0,0 @@ -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 deleted file mode 100644 index de1d884..0000000 --- a/packages/core/lib/src/provider/service_provider.dart +++ /dev/null @@ -1,39 +0,0 @@ -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 deleted file mode 100644 index ebceda6..0000000 --- a/packages/core/lib/src/provider/service_provider_config.dart +++ /dev/null @@ -1,82 +0,0 @@ -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 deleted file mode 100644 index 1fed530..0000000 --- a/packages/core/lib/src/provider/service_provider_manager.dart +++ /dev/null @@ -1,131 +0,0 @@ -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/test/provider/platform_with_providers_test.dart b/packages/core/test/provider/platform_with_providers_test.dart deleted file mode 100644 index 8141270..0000000 --- a/packages/core/test/provider/platform_with_providers_test.dart +++ /dev/null @@ -1,55 +0,0 @@ -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 deleted file mode 100644 index e19c8c8..0000000 --- a/packages/core/test/provider/platform_with_providers_test.mocks.dart +++ /dev/null @@ -1,1526 +0,0 @@ -// 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 deleted file mode 100644 index 29b6458..0000000 --- a/packages/core/test/provider/provider_discovery_test.dart +++ /dev/null @@ -1,33 +0,0 @@ -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 deleted file mode 100644 index 65e090e..0000000 --- a/packages/core/test/provider/service_provider_config_test.dart +++ /dev/null @@ -1,27 +0,0 @@ -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 deleted file mode 100644 index 4798b01..0000000 --- a/packages/core/test/provider/service_provider_integration_test.dart +++ /dev/null @@ -1,87 +0,0 @@ -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 deleted file mode 100644 index 4c6269a..0000000 --- a/packages/core/test/provider/service_provider_manager_test.dart +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 207a292..0000000 --- a/packages/core/test/provider/service_provider_manager_test.mocks.dart +++ /dev/null @@ -1,1462 +0,0 @@ -// 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 deleted file mode 100644 index f1bfc11..0000000 --- a/packages/core/test/provider/service_provider_test.dart +++ /dev/null @@ -1,32 +0,0 @@ -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); - }); - }); -} diff --git a/packages/core/test/provider/test_setup.dart b/packages/core/test/provider/test_setup.dart deleted file mode 100644 index b2d8309..0000000 --- a/packages/core/test/provider/test_setup.dart +++ /dev/null @@ -1,35 +0,0 @@ -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 with MirrorsReflector - _container = Container(MirrorsReflector()); - - // Initialize PlatformWithProviders - platformWithProviders = PlatformWithProviders(app); - - // Configure the app to use our container - app.configure((angel) { - // Instead of registering the container, we'll replace Angel's container - angel.container = _container; - }); - - // Allow some time for initialization - await Future.delayed(Duration(milliseconds: 100)); - } - - Future tearDown() async { - await app.close(); - } -}