singleton( FakerGenerator::class, function () { return FakerFactory::create(); } ); } /** * @inheritDoc */ public function boot() { // Add CLI commands if ( defined( 'WP_CLI' ) && WP_CLI ) { $this->addCommands(); try { $this->loadAddonsServiceProviders(); } catch ( InvalidArgumentException $e ) { exit( $e->getMessage() ); } } } /** * Load addons service providers for TestData */ private function loadAddonsServiceProviders() { $providers = []; // Load Test Data add-ons Service Providers as they are not handled by Give foreach ( Addons::getActiveAddons() as $addon ) { if ( ! is_subclass_of( $addon['serviceProvider'], GiveServiceProvider::class ) ) { throw new InvalidArgumentException( "{$addon['serviceProvider']} class must implement the ServiceProvider interface" ); } $addonServiceProvider = new $addon['serviceProvider'](); $addonServiceProvider->register(); $providers[] = $addonServiceProvider; } foreach ( $providers as $addonServiceProvider ) { $addonServiceProvider->boot(); } } /** * Add CLI comands */ private function addCommands() { WP_CLI::add_command( 'give test-donors', give()->make( DonorSeedCommand::class ) ); WP_CLI::add_command( 'give test-donations', give()->make( DonationSeedCommand::class ) ); WP_CLI::add_command( 'give test-donation-statuses', give()->make( DonationStatusCommand::class ) ); WP_CLI::add_command( 'give test-demonstration-page', give()->make( PageSeedCommand::class ) ); WP_CLI::add_command( 'give test-donation-form', give()->make( FormSeedCommand::class ) ); WP_CLI::add_command( 'give test-logs', give()->make( LogsSeedCommand::class ) ); } }