diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8ae262..9f1fd48 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,7 @@ jobs: - wp-launchpad/core - wp-launchpad/dispatcher - wp-launchpad/uninstaller + - wp-launchpad/uninstaller-take-off - wp-launchpad/updater - wp-launchpad/cli - wp-launchpad/bud-assets diff --git a/packages/core/tests/Integration/inc/boot/deactivate.php b/packages/core/tests/Integration/inc/boot/deactivate.php index b045c12..06fc9fc 100644 --- a/packages/core/tests/Integration/inc/boot/deactivate.php +++ b/packages/core/tests/Integration/inc/boot/deactivate.php @@ -34,5 +34,6 @@ public function testShouldDoAsExpected($config, $expected) do_action("deactivate_{$activate_plugin_path}"); $this->assertFalse(get_option('demo_option', false), "demo_option should be unregistered"); - $this->assertFalse(get_option('demo_option_2', false), "demo_option_2 should be unregistered"); } + $this->assertFalse(get_option('demo_option_2', false), "demo_option_2 should be unregistered"); + } } \ No newline at end of file diff --git a/packages/uninstaller-take-off/composer.json b/packages/uninstaller-take-off/composer.json index 14710a4..62ac367 100644 --- a/packages/uninstaller-take-off/composer.json +++ b/packages/uninstaller-take-off/composer.json @@ -36,7 +36,7 @@ "install": true, "clean": true, "libraries": { - "wp-launchpad/uninstaller": "^0.0" + "wp-launchpad/uninstaller": "^3.1" } } }, diff --git a/packages/uninstaller-take-off/templates/uninstall.php.tpl b/packages/uninstaller-take-off/templates/uninstall.php.tpl index c1ba658..78c2600 100644 --- a/packages/uninstaller-take-off/templates/uninstall.php.tpl +++ b/packages/uninstaller-take-off/templates/uninstall.php.tpl @@ -2,6 +2,7 @@ defined( 'WP_UNINSTALL_PLUGIN' ) || exit; +use {{ base_namespace }}Dependencies\LaunchpadDispatcher\Dispatcher; use {{ base_namespace }}Dependencies\LaunchpadUninstaller\Uninstall\Uninstall; use {{ base_namespace }}Dependencies\League\Container\Container; @@ -13,7 +14,14 @@ require_once $plugin_root_dir . '/vendor/autoload.php'; $params = require_once $plugin_root_dir . '/configs/parameters.php'; $providers = require_once $plugin_root_dir . '/configs/providers.php'; -Uninstall::set_container(new Container()); +$container = new Container(); +if( key_exists('autowiring', $params) && $params['autowiring']) { + $reflection_container = new \LaunchpadCore\Container\Autowiring\Container(); + $container->delegate( $reflection_container ); +} + +Uninstall::set_container($container); +Uninstall::set_dispatcher(new Dispatcher()); Uninstall::set_params($params); Uninstall::set_providers($providers); diff --git a/packages/uninstaller-take-off/tests/Fixtures/inc/Commands/InstallCommand/execute.php b/packages/uninstaller-take-off/tests/Fixtures/inc/Commands/InstallCommand/execute.php index 34b417e..b238da9 100644 --- a/packages/uninstaller-take-off/tests/Fixtures/inc/Commands/InstallCommand/execute.php +++ b/packages/uninstaller-take-off/tests/Fixtures/inc/Commands/InstallCommand/execute.php @@ -47,14 +47,6 @@ 'exists' => true, 'content' => file_get_contents(__DIR__ . '/files/configs/providers.php') ], - 'composer.json' => [ - 'exists' => true, - 'content' => file_get_contents(__DIR__ . '/files/composer.json') - ], - 'bin/generator' => [ - 'exists' => true, - 'content' => file_get_contents(__DIR__ . '/files/bin/generator') - ], 'uninstall.php' => [ 'exists' => true, 'content' => file_get_contents(__DIR__ . '/files/uninstall.php') diff --git a/packages/uninstaller-take-off/tests/Fixtures/inc/Commands/InstallCommand/files/uninstall.php b/packages/uninstaller-take-off/tests/Fixtures/inc/Commands/InstallCommand/files/uninstall.php index fb627c6..eabd680 100644 --- a/packages/uninstaller-take-off/tests/Fixtures/inc/Commands/InstallCommand/files/uninstall.php +++ b/packages/uninstaller-take-off/tests/Fixtures/inc/Commands/InstallCommand/files/uninstall.php @@ -2,7 +2,8 @@ defined( 'WP_UNINSTALL_PLUGIN' ) || exit; -use RocketLauncher\Dependencies\RocketLauncherUninstaller\Uninstall\Uninstall; +use RocketLauncher\Dependencies\LaunchpadDispatcher\Dispatcher; +use RocketLauncher\Dependencies\LaunchpadUninstaller\Uninstall\Uninstall; use RocketLauncher\Dependencies\League\Container\Container; $plugin_root_dir = dirname( __FILE__ ); @@ -13,7 +14,14 @@ $params = require_once $plugin_root_dir . '/configs/parameters.php'; $providers = require_once $plugin_root_dir . '/configs/providers.php'; -Uninstall::set_container(new Container()); +$container = new Container(); +if( key_exists('autowiring', $params) && $params['autowiring']) { + $reflection_container = new \LaunchpadCore\Container\Autowiring\Container(); + $container->delegate( $reflection_container ); +} + +Uninstall::set_container($container); +Uninstall::set_dispatcher(new Dispatcher()); Uninstall::set_params($params); Uninstall::set_providers($providers); diff --git a/packages/uninstaller/composer.json b/packages/uninstaller/composer.json index fdcfeeb..e3d1385 100644 --- a/packages/uninstaller/composer.json +++ b/packages/uninstaller/composer.json @@ -27,9 +27,9 @@ "wp-media/phpunit": "^3.0" }, "scripts": { - "test-unit": "\"vendor/bin/phpunit\" --testsuite unit --colors=always --configuration tests/Unit/phpunit.xml.dist", + "test-integration": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --exclude-group AdminOnly", "run-tests": [ - "@test-unit" + "@test-integration" ] } } diff --git a/packages/uninstaller/inc/Uninstall/HasUninstallerServiceProviderTrait.php b/packages/uninstaller/inc/Uninstall/HasUninstallerServiceProviderTrait.php new file mode 100644 index 0000000..ab96698 --- /dev/null +++ b/packages/uninstaller/inc/Uninstall/HasUninstallerServiceProviderTrait.php @@ -0,0 +1,65 @@ +load(); + + $uninstallers = []; + + foreach ( $this->get_services_to_load() as $registration ) { + if ( ! $registration instanceof UninstallerRegistration ) { + continue; + } + + $uninstallers [] = $registration->get_id(); + } + + return $uninstallers; + } + + /** + * Register uninstaller. + * + * @param string $classname Classname from the uninstaller. + * @return UninstallerRegistration + */ + public function register_uninstaller( string $classname ): UninstallerRegistration { + $registration = new UninstallerRegistration( $classname ); + + $this->add_service_to_load( $registration ); + + return $registration; + } + + /** + * Loads definitions. + * + * @return void + */ + abstract protected function load(); + + /** + * Get the service to load. + * + * @return Registration[] + */ + abstract protected function get_services_to_load(): array; + + /** + * Add to the list of service to load. + * + * @param Registration $registration Registration from the service to add. + * @return void + */ + abstract protected function add_service_to_load( Registration $registration ): void; +} \ No newline at end of file diff --git a/packages/uninstaller/inc/Uninstall/Uninstall.php b/packages/uninstaller/inc/Uninstall/Uninstall.php index 74969dd..3b37986 100644 --- a/packages/uninstaller/inc/Uninstall/Uninstall.php +++ b/packages/uninstaller/inc/Uninstall/Uninstall.php @@ -2,6 +2,11 @@ namespace LaunchpadUninstaller\Uninstall; use LaunchpadCore\Container\HasInflectorInterface; +use LaunchpadCore\Container\PrefixAwareInterface; +use LaunchpadCore\Dispatcher\DispatcherAwareInterface; +use LaunchpadDispatcher\Dispatcher; +use LaunchpadUninstaller\Uninstall\Wrapper\UninstallerWrapper; +use League\Container\Argument\Literal\StringArgument; use Psr\Container\ContainerInterface; class Uninstall @@ -12,6 +17,13 @@ class Uninstall protected static $container; + /** + * Hook dispatcher. + * + * @var Dispatcher + */ + protected static $dispatcher; + public static function set_providers(array $providers) { self::$providers = $providers; } @@ -24,14 +36,53 @@ public static function set_container(ContainerInterface $container) { self::$container = $container; } + /** + * Set hook dispatcher. + * + * @param Dispatcher $dispatcher Hook dispatcher. + * @return void + */ + public static function set_dispatcher( Dispatcher $dispatcher ): void { + self::$dispatcher = $dispatcher; + } + public static function uninstall_plugin() { - foreach (self::$params as $key => $value) { - self::$container->add( $key, $value); - } - $providers = array_filter(self::$providers, function ($provider) { - if(is_string($provider)) { - $provider = new $provider(); - } + foreach ( self::$params as $key => $value ) { + if ( is_string( $value ) && ! class_exists( $value ) ) { + $value = new StringArgument( $value ); + } + + self::$container->addShared( $key, $value ); + } + + + self::$container->addShared( 'dispatcher', self::$dispatcher ); + + self::$container->inflector( PrefixAwareInterface::class )->invokeMethod( 'set_prefix', [ key_exists( 'prefix', self::$params ) ? self::$params['prefix'] : '' ] ); + self::$container->inflector( DispatcherAwareInterface::class )->invokeMethod( 'set_dispatcher', [ self::$container->get( 'dispatcher' ) ] ); + + $providers = array_map( + function ( $provider ) { + if ( is_string( $provider ) ) { + return new $provider(); + } + return $provider; + }, + self::$providers + ); + + foreach ( $providers as $provider ) { + self::$container->addServiceProvider( $provider ); + } + + foreach ( $providers as $service_provider ) { + if ( ! $service_provider instanceof HasInflectorInterface ) { + continue; + } + $service_provider->register_inflectors(); + } + + $providers = array_filter($providers, function ($provider) { if(! $provider instanceof UninstallServiceProviderInterface) { return false; @@ -51,6 +102,8 @@ public static function uninstall_plugin() { self::$container->addServiceProvider($provider); } + $wrapper = new UninstallerWrapper(); + foreach ( $providers as $service_provider ) { if( ! $service_provider instanceof HasInflectorInterface ) { continue; @@ -65,9 +118,8 @@ public static function uninstall_plugin() { foreach ( $provider->get_uninstallers() as $uninstaller ) { $uninstaller_instance = self::$container->get( $uninstaller ); - if(! $uninstaller_instance instanceof UninstallerInterface) { - continue; - } + $uninstaller_instance = $wrapper->wrap($uninstaller_instance); + $uninstaller_instance->uninstall(); } } diff --git a/packages/uninstaller/inc/Uninstall/UninstallerRegistration.php b/packages/uninstaller/inc/Uninstall/UninstallerRegistration.php new file mode 100644 index 0000000..b17c904 --- /dev/null +++ b/packages/uninstaller/inc/Uninstall/UninstallerRegistration.php @@ -0,0 +1,11 @@ +instance = $instance; + $this->uninstall_methods = $uninstall_methods; + } + + /** + * @inheritDoc + */ + public function uninstall() { + foreach ( $this->uninstall_methods as $method ) { + $this->instance->{$method}(); + } + } +} \ No newline at end of file diff --git a/packages/uninstaller/inc/Uninstall/Wrapper/UninstallerWrapper.php b/packages/uninstaller/inc/Uninstall/Wrapper/UninstallerWrapper.php new file mode 100644 index 0000000..fec2e59 --- /dev/null +++ b/packages/uninstaller/inc/Uninstall/Wrapper/UninstallerWrapper.php @@ -0,0 +1,44 @@ +getMethod( $method ); + $doc_comment = $method_reflection->getDocComment(); + if ( ! $doc_comment ) { + continue; + } + $pattern = '#@uninstall#'; + + $matched = preg_match_all( $pattern, $doc_comment, $matches, PREG_PATTERN_ORDER ); + + if ( ! $matched ) { + continue; + } + + $uninstall_methods[] = $method; + } + + return new UninstallerProxy( $instance, $uninstall_methods ); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/configs/parameters.php b/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/configs/parameters.php new file mode 100644 index 0000000..1a838bd --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/configs/parameters.php @@ -0,0 +1,10 @@ + 'demo_', + 'translation_key' => 'demo', + 'is_mu_plugin' => false, + 'key_param' => 'key_param', + 'cache' => \LaunchpadUninstaller\Tests\Fixtures\inc\boot\autowiring\inc\Cache::class, + 'autowiring' => true +]; \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/configs/providers.php b/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/configs/providers.php new file mode 100644 index 0000000..7ac238e --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/configs/providers.php @@ -0,0 +1,6 @@ +register_common_subscriber(Subscriber::class)->autowire(); + + $this->register_common_subscriber(RegularSubscriber::class); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/inc/Subscriber.php b/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/inc/Subscriber.php new file mode 100644 index 0000000..d46f2e0 --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/inc/Subscriber.php @@ -0,0 +1,43 @@ +dependency = $dependency; + $this->translation_key = $translation_key; + $this->cache = $cache; + $this->key_param = $key_param; + } + + /** + * @hook hook + */ + public function hook_callback() + { + $this->cache->clean(); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/inc/Uninstall.php b/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/inc/Uninstall.php new file mode 100644 index 0000000..496e62b --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/inc/Uninstall.php @@ -0,0 +1,41 @@ +uninstallDependency = $uninstallDependency; + $this->cache = $cache; + $this->key_param = $key_param; + } + + /** + * @inheritDoc + */ + public function uninstall() + { + delete_option('demo_option'); + $this->dispatcher->do_action("{$this->prefix}test"); + $this->cache->clean(); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/inc/UninstallDependency.php b/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/inc/UninstallDependency.php new file mode 100644 index 0000000..ef31c6d --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/inc/UninstallDependency.php @@ -0,0 +1,8 @@ +register_uninstaller(Uninstall::class)->autowire(); + $this->register_uninstaller(Uninstaller::class)->autowire(); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/inc/Uninstaller.php b/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/inc/Uninstaller.php new file mode 100644 index 0000000..034ecdc --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/autowiring/inc/Uninstaller.php @@ -0,0 +1,40 @@ +uninstallDependency = $uninstallDependency; + $this->cache = $cache; + $this->key_param = $key_param; + } + + + /** + * @uninstall + */ + public function method() + { + delete_option('demo_option_2'); + $this->dispatcher->do_action("{$this->prefix}test"); + $this->cache->clean(); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/files/configs/parameters.php b/packages/uninstaller/tests/Fixtures/inc/boot/files/configs/parameters.php new file mode 100644 index 0000000..40aff56 --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/files/configs/parameters.php @@ -0,0 +1,9 @@ + 'demo_', + 'translation_key' => 'demo', + 'key_param' => 'key_param', + 'cache' => \LaunchpadUninstaller\Tests\Fixtures\inc\boot\files\inc\Cache::class, + 'is_mu_plugin' => false, +]; \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/files/configs/providers.php b/packages/uninstaller/tests/Fixtures/inc/boot/files/configs/providers.php new file mode 100644 index 0000000..15c2650 --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/files/configs/providers.php @@ -0,0 +1,8 @@ +register_uninstaller(AnnotationUninstaller::class); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/Cache.php b/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/Cache.php new file mode 100644 index 0000000..db638fc --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/Cache.php @@ -0,0 +1,11 @@ +register_service(Subscriber::class) + ->set_definition(function (Definition $definition) { + $definition->addArgument($definition->addArguments(['key_param', 'cache'])); + }); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/Subscriber.php b/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/Subscriber.php new file mode 100644 index 0000000..796695c --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/Subscriber.php @@ -0,0 +1,30 @@ +key = $key; + $this->cache = $cache; + } + + /** + * @hook hook + */ + public function hook_callback() + { + $this->cache->clean(); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/UninstallDependency.php b/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/UninstallDependency.php new file mode 100644 index 0000000..1a53e29 --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/UninstallDependency.php @@ -0,0 +1,8 @@ +register_service(UninstallDependency::class); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/UninstallServiceProvider.php b/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/UninstallServiceProvider.php new file mode 100644 index 0000000..7add24b --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/UninstallServiceProvider.php @@ -0,0 +1,34 @@ +register_service(Uninstaller::class, function (Definition $definition) { + $definition->addArgument(UninstallDependency::class); + $definition->addArgument('key_param'); + $definition->addArgument('cache'); + }); + } + + /** + * @inheritDoc + */ + public function get_uninstallers(): array + { + return [ + Uninstaller::class + ]; + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/Uninstaller.php b/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/Uninstaller.php new file mode 100644 index 0000000..7fafadb --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/files/inc/Uninstaller.php @@ -0,0 +1,40 @@ +deactivateDependency = $deactivateDependency; + $this->key = $key; + $this->cache = $cache; + } + + /** + * @inheritDoc + */ + public function uninstall() + { + delete_option('demo_option'); + $this->dispatcher->do_action("{$this->prefix}test"); + $this->cache->clean(); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/inflector/configs/parameters.php b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/configs/parameters.php new file mode 100644 index 0000000..502b4d1 --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/configs/parameters.php @@ -0,0 +1,7 @@ + 'demo_', + 'translation_key' => 'demo', + 'is_mu_plugin' => false, +]; \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/inflector/configs/providers.php b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/configs/providers.php new file mode 100644 index 0000000..2af2c2e --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/configs/providers.php @@ -0,0 +1,8 @@ +register_uninstaller(AnnotationUninstaller::class); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/Inflector/Inflected.php b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/Inflector/Inflected.php new file mode 100644 index 0000000..f0756dd --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/Inflector/Inflected.php @@ -0,0 +1,11 @@ +register_service(Inflected::class); + $this->register_service(Subscriber::class); + $this->register_inflector(InflectorInterface::class) + ->add_method('inflector_method', [ + Inflected::class + ]); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/Subscriber.php b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/Subscriber.php new file mode 100644 index 0000000..8b8c08b --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/Subscriber.php @@ -0,0 +1,27 @@ +inflected->method(); + } + + public function inflector_method(Inflected $inflected) + { + $this->inflected = $inflected; + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/UninstallDependency.php b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/UninstallDependency.php new file mode 100644 index 0000000..d3417b6 --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/UninstallDependency.php @@ -0,0 +1,8 @@ +register_service(UninstallDependency::class); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/UninstallServiceProvider.php b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/UninstallServiceProvider.php new file mode 100644 index 0000000..fcd9c01 --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/UninstallServiceProvider.php @@ -0,0 +1,32 @@ +register_service(Uninstaller::class, function (Definition $definition) { + $definition->addArgument(UninstallDependency::class); + }); + } + + /** + * @inheritDoc + */ + public function get_uninstallers(): array + { + return [ + Uninstaller::class + ]; + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/Uninstaller.php b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/Uninstaller.php new file mode 100644 index 0000000..f7fc736 --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/inflector/inc/Uninstaller.php @@ -0,0 +1,43 @@ +uninstallDependency = $uninstallDependency; + } + + /** + * @inheritDoc + */ + public function uninstall() + { + delete_option('demo_option'); + $this->dispatcher->do_action("{$this->prefix}test"); + $this->inflected->method(); + } + + public function inflector_method(Inflected $inflected) + { + $this->inflected = $inflected; + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Fixtures/inc/boot/uninstall.php b/packages/uninstaller/tests/Fixtures/inc/boot/uninstall.php new file mode 100644 index 0000000..1a440ff --- /dev/null +++ b/packages/uninstaller/tests/Fixtures/inc/boot/uninstall.php @@ -0,0 +1,28 @@ + [ + 'config' => [ + 'plugin' => __DIR__ . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR, + ], + 'expected' => [ + + ] + ], + 'autowiring' => [ + 'config' => [ + 'plugin' => __DIR__ . DIRECTORY_SEPARATOR . 'autowiring' . DIRECTORY_SEPARATOR, + ], + 'expected' => [ + + ] + ], + 'inflector' => [ + 'config' => [ + 'plugin' => __DIR__ . DIRECTORY_SEPARATOR . 'inflector' . DIRECTORY_SEPARATOR, + ], + 'expected' => [ + + ] + ] +]; \ No newline at end of file diff --git a/packages/uninstaller/tests/Integration/TestCase.php b/packages/uninstaller/tests/Integration/TestCase.php new file mode 100644 index 0000000..b7e9671 --- /dev/null +++ b/packages/uninstaller/tests/Integration/TestCase.php @@ -0,0 +1,86 @@ + $value) { + if (!empty($transient)) { + set_transient($transient, $value); + } else { + delete_transient($transient); + } + } + } + + public function set_up() + { + parent::set_up(); + + if (empty($this->config)) { + $this->loadTestDataConfig(); + } + $this->mockHooks(); + } + + public function tear_down() + { + $this->resetHooks(); + parent::tear_down(); + } + + public function configTestData() + { + if (empty($this->config)) { + $this->loadTestDataConfig(); + } + + return isset($this->config['test_data']) + ? $this->config['test_data'] + : $this->config; + } + + protected function loadTestDataConfig() + { + $obj = new ReflectionObject($this); + $filename = $obj->getFileName(); + + $this->config = $this->getTestData(dirname($filename), basename($filename, '.php')); + } + + public function getPrefix(): string + { + return $this->prefix; + } + + public function getCurrentTest(): string + { + return $this->getName(); + } +} diff --git a/packages/uninstaller/tests/Integration/UseContainer.php b/packages/uninstaller/tests/Integration/UseContainer.php new file mode 100644 index 0000000..3684b01 --- /dev/null +++ b/packages/uninstaller/tests/Integration/UseContainer.php @@ -0,0 +1,27 @@ + 'test', + 'version' => '3.16' + ]; + return apply_filters("{$parameters['prefix']}container", null); + } + + public function get_league_container(): Container + { + $parameters = [ + 'prefix' => 'test', + 'version' => '3.16' + ]; + return apply_filters("{$parameters['prefix']}container", null); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Integration/bootstrap.php b/packages/uninstaller/tests/Integration/bootstrap.php new file mode 100644 index 0000000..306a32f --- /dev/null +++ b/packages/uninstaller/tests/Integration/bootstrap.php @@ -0,0 +1,27 @@ +delegate( $reflection_container ); + } + + Uninstall::set_container($container); + Uninstall::set_dispatcher(new Dispatcher()); + Uninstall::set_params($params); + Uninstall::set_providers($providers); + + Uninstall::uninstall_plugin(); + + $this->assertFalse(get_option('demo_option', false), "demo_option should be unregistered"); + $this->assertFalse(get_option('demo_option_2', false), "demo_option_2 should be unregistered"); + } +} \ No newline at end of file diff --git a/packages/uninstaller/tests/Integration/init-tests.php b/packages/uninstaller/tests/Integration/init-tests.php new file mode 100644 index 0000000..41f38ac --- /dev/null +++ b/packages/uninstaller/tests/Integration/init-tests.php @@ -0,0 +1,11 @@ + + + + + ../../inc + + + + + inc + + + \ No newline at end of file