feat: wire rest transport services
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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' );
|
||||
|
||||
@@ -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'] );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user