From 8c3773f040c36b25f6cf1870058ed447218b2c25 Mon Sep 17 00:00:00 2001 From: Keith Solomon Date: Tue, 28 Apr 2026 13:04:39 -0500 Subject: [PATCH] feat: wire rest transport services --- src/Plugin.php | 22 ++++++++++++++ tests/Unit/PluginTest.php | 30 +++++++++++++++++++ tests/Unit/Rest/RestPackageControllerTest.php | 6 ++++ 3 files changed, 58 insertions(+) diff --git a/src/Plugin.php b/src/Plugin.php index 3d1f504..7681ad3 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -12,9 +12,11 @@ use WPContentSync\Admin\FileImportController; use WPContentSync\Logging\LoggerInterface; use WPContentSync\Logging\OptionLogger; use WPContentSync\Package\PackageValidator; +use WPContentSync\Rest\RestPackageController; use WPContentSync\Settings\SettingsRepository; use WPContentSync\Transport\FileTransportInterface; use WPContentSync\Transport\JsonFileTransport; +use WPContentSync\Transport\RestTransportClient; use WPContentSync\Url\MetadataUrlTransformer; use WPContentSync\Url\UrlTransformer; @@ -84,6 +86,22 @@ final class Plugin { } ); + $container->factory( + RestTransportClient::class, + static function (): RestTransportClient { + return new RestTransportClient(); + } + ); + + $container->factory( + RestPackageController::class, + static function () use ( $container ): RestPackageController { + return new RestPackageController( + $container->get( PackageValidator::class ) + ); + } + ); + $container->factory( AdminPage::class, static function () use ( $container ): AdminPage { @@ -104,7 +122,11 @@ final class Plugin { /** @var FileImportController $file_import_controller */ $file_import_controller = $this->container->get( FileImportController::class ); + /** @var RestPackageController $rest_package_controller */ + $rest_package_controller = $this->container->get( RestPackageController::class ); + $admin_page->register(); $file_import_controller->register(); + $rest_package_controller->register(); } } diff --git a/tests/Unit/PluginTest.php b/tests/Unit/PluginTest.php index f7dec7b..a597111 100644 --- a/tests/Unit/PluginTest.php +++ b/tests/Unit/PluginTest.php @@ -6,11 +6,19 @@ use PHPUnit\Framework\TestCase; use WPContentSync\Admin\FileImportController; use WPContentSync\Container; use WPContentSync\Plugin; +use WPContentSync\Rest\RestPackageController; use WPContentSync\Transport\FileTransportInterface; +use WPContentSync\Transport\RestTransportClient; use WPContentSync\Url\MetadataUrlTransformer; use WPContentSync\Url\UrlTransformer; class PluginTest extends TestCase { + protected function tearDown(): void { + unset( $GLOBALS['wpcs_test_actions'] ); + + parent::tearDown(); + } + public function test_it_registers_url_transformation_services(): void { $container = $this->getPluginContainer( Plugin::create() ); @@ -36,6 +44,28 @@ class PluginTest extends TestCase { ); } + public function test_it_registers_rest_transport_services(): void { + $container = $this->getPluginContainer( Plugin::create() ); + + self::assertInstanceOf( + RestTransportClient::class, + $container->get( RestTransportClient::class ) + ); + self::assertInstanceOf( + RestPackageController::class, + $container->get( RestPackageController::class ) + ); + } + + public function test_it_hooks_rest_package_controller_on_register(): void { + unset( $GLOBALS['wpcs_test_actions'] ); + + $plugin = Plugin::create(); + $plugin->register(); + + self::assertArrayHasKey( 'rest_api_init', $GLOBALS['wpcs_test_actions'] ); + } + private function getPluginContainer( Plugin $plugin ): Container { $reflection = new \ReflectionClass( $plugin ); $property = $reflection->getProperty( 'container' ); diff --git a/tests/Unit/Rest/RestPackageControllerTest.php b/tests/Unit/Rest/RestPackageControllerTest.php index 646b6aa..d7683c7 100644 --- a/tests/Unit/Rest/RestPackageControllerTest.php +++ b/tests/Unit/Rest/RestPackageControllerTest.php @@ -13,6 +13,12 @@ use WPContentSync\Package\PackageValidator; use WPContentSync\Rest\RestPackageController; class RestPackageControllerTest extends TestCase { + protected function setUp(): void { + parent::setUp(); + + unset( $GLOBALS['wpcs_rest_routes'], $GLOBALS['wpcs_current_user_can'], $GLOBALS['wpcs_test_actions'] ); + } + protected function tearDown(): void { unset( $GLOBALS['wpcs_rest_routes'], $GLOBALS['wpcs_current_user_can'], $GLOBALS['wpcs_test_actions'] );