From fce85c74a538ea19d0f96e4e827ac11ebfaf1da9 Mon Sep 17 00:00:00 2001 From: mateikki Date: Thu, 15 Feb 2024 18:28:28 +0100 Subject: [PATCH] Plugin class namespaces changed, added autoload function to load all plugin dependencies --- .../ewplugin/admin/class-plugin-admin.php | 10 +- wp-content/plugins/ewplugin/constants.php | 3 + .../controllers/class-aplugin-controller.php | 6 +- .../class-user-applications-controller.php | 20 ++- .../exceptions/class-validation-exception.php | 2 +- .../helpers/class-random-values-helper.php | 2 +- .../ewplugin/includes/class-plugin-loader.php | 121 ----------------- wp-content/plugins/ewplugin/load-plugin.php | 17 +++ .../class-plugin-activator.php | 2 +- .../class-plugin-deactivator.php | 2 +- .../{includes => main}/class-plugin-i18n.php | 13 +- .../ewplugin/main/class-plugin-loader.php | 128 ++++++++++++++++++ .../{includes => main}/class-plugin.php | 116 ++++------------ .../ewplugin/{classes => main}/index.php | 0 .../class-user-application.php | 30 ++-- .../ewplugin/{includes => models}/index.php | 0 .../ewplugin/plugin-autoload-register.php | 35 +++++ wp-content/plugins/ewplugin/plugin.php | 51 ++----- .../ewplugin/public/class-plugin-public.php | 21 +-- .../class-user-applications-repository.php | 7 +- .../ewplugin/services/class-files-service.php | 4 +- .../class-user-applications-service.php | 11 +- .../plugins/ewplugin/tests/bootstrap.php | 7 - .../tests/helpers/class-plugin-test-case.php | 20 +-- .../test-user-applications-repository.php | 14 +- .../test-user-applications-service.php | 23 ++-- .../tests/unit/test-random-values-helper.php | 4 +- 27 files changed, 325 insertions(+), 344 deletions(-) delete mode 100755 wp-content/plugins/ewplugin/includes/class-plugin-loader.php create mode 100755 wp-content/plugins/ewplugin/load-plugin.php rename wp-content/plugins/ewplugin/{includes => main}/class-plugin-activator.php (98%) rename wp-content/plugins/ewplugin/{includes => main}/class-plugin-deactivator.php (94%) rename wp-content/plugins/ewplugin/{includes => main}/class-plugin-i18n.php (71%) create mode 100755 wp-content/plugins/ewplugin/main/class-plugin-loader.php rename wp-content/plugins/ewplugin/{includes => main}/class-plugin.php (58%) rename wp-content/plugins/ewplugin/{classes => main}/index.php (100%) rename wp-content/plugins/ewplugin/{classes => models}/class-user-application.php (75%) rename wp-content/plugins/ewplugin/{includes => models}/index.php (100%) create mode 100755 wp-content/plugins/ewplugin/plugin-autoload-register.php diff --git a/wp-content/plugins/ewplugin/admin/class-plugin-admin.php b/wp-content/plugins/ewplugin/admin/class-plugin-admin.php index 5f902c397..c9fb5b104 100755 --- a/wp-content/plugins/ewplugin/admin/class-plugin-admin.php +++ b/wp-content/plugins/ewplugin/admin/class-plugin-admin.php @@ -1,6 +1,6 @@ user_applications_service->create_user_application( $request->get_params() ); @@ -61,7 +67,7 @@ public function create_user_application( \WP_REST_Request $request ): \WP_REST_R return $this->ok( $user_application ); } catch ( Validation_Exception $e ) { return $this->bad_request( $e->getMessage() ); - } catch ( \Exception $e ) { + } catch ( Exception $e ) { return $this->exception_response( $e ); } } diff --git a/wp-content/plugins/ewplugin/exceptions/class-validation-exception.php b/wp-content/plugins/ewplugin/exceptions/class-validation-exception.php index cc05f8749..95f161f5b 100755 --- a/wp-content/plugins/ewplugin/exceptions/class-validation-exception.php +++ b/wp-content/plugins/ewplugin/exceptions/class-validation-exception.php @@ -6,7 +6,7 @@ * Time: 12:12 */ -namespace EwStarter; +namespace EwStarter\Exceptions; /** * Base template class for validation exception. diff --git a/wp-content/plugins/ewplugin/helpers/class-random-values-helper.php b/wp-content/plugins/ewplugin/helpers/class-random-values-helper.php index 6adef23f3..393842331 100755 --- a/wp-content/plugins/ewplugin/helpers/class-random-values-helper.php +++ b/wp-content/plugins/ewplugin/helpers/class-random-values-helper.php @@ -6,7 +6,7 @@ * Time: 14:55 */ -namespace EwStarter; +namespace EwStarter\Helpers; /** * Class Random_Values_Helper diff --git a/wp-content/plugins/ewplugin/includes/class-plugin-loader.php b/wp-content/plugins/ewplugin/includes/class-plugin-loader.php deleted file mode 100755 index 9b5f43703..000000000 --- a/wp-content/plugins/ewplugin/includes/class-plugin-loader.php +++ /dev/null @@ -1,121 +0,0 @@ - - */ -class Plugin_Loader { - - /** - * The array of actions registered with WordPress. - * - * @since 1.0.0 - * @access protected - * @var array $actions The actions registered with WordPress to fire when the plugin loads. - */ - protected $actions; - - /** - * The array of filters registered with WordPress. - * - * @since 1.0.0 - * @access protected - * @var array $filters The filters registered with WordPress to fire when the plugin loads. - */ - protected $filters; - - /** - * Initialize the collections used to maintain the actions and filters. - * - * @since 1.0.0 - */ - public function __construct() { - - $this->actions = array(); - $this->filters = array(); - - } - - /** - * Add a new action to the collection to be registered with WordPress. - * - * @since 1.0.0 - * @param string $hook The name of the WordPress action that is being registered. - * @param object|string $component A reference to the instance of the object on which the action is defined. - * @param string $callback The name of the function definition on the $component. - * @param int $priority Optional. he priority at which the function should be fired. Default is 10. - * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. - */ - public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { - $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); - } - - /** - * Add a new filter to the collection to be registered with WordPress. - * - * @since 1.0.0 - * @param string $hook The name of the WordPress filter that is being registered. - * @param object|string $component A reference to the instance of the object on which the filter is defined. - * @param string $callback The name of the function definition on the $component. - * @param int $priority Optional. he priority at which the function should be fired. Default is 10. - * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 - */ - public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { - $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); - } - - /** - * A utility function that is used to register the actions and hooks into a single - * collection. - * - * @since 1.0.0 - * @access private - * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). - * @param string $hook The name of the WordPress filter that is being registered. - * @param object|string $component A reference to the instance of the object on which the filter is defined. - * @param string $callback The name of the function definition on the $component. - * @param int $priority The priority at which the function should be fired. - * @param int $accepted_args The number of arguments that should be passed to the $callback. - * @return array The collection of actions and filters registered with WordPress. - */ - private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { - - $hooks[] = array( - 'hook' => $hook, - 'component' => $component, - 'callback' => $callback, - 'priority' => $priority, - 'accepted_args' => $accepted_args - ); - - return $hooks; - - } - - /** - * Register the filters and actions with WordPress. - * - * @since 1.0.0 - */ - public function run() { - - foreach ( $this->filters as $hook ) { - add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); - } - - foreach ( $this->actions as $hook ) { - add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); - } - - } - -} diff --git a/wp-content/plugins/ewplugin/load-plugin.php b/wp-content/plugins/ewplugin/load-plugin.php new file mode 100755 index 000000000..a73906c77 --- /dev/null +++ b/wp-content/plugins/ewplugin/load-plugin.php @@ -0,0 +1,17 @@ +run(); diff --git a/wp-content/plugins/ewplugin/includes/class-plugin-activator.php b/wp-content/plugins/ewplugin/main/class-plugin-activator.php similarity index 98% rename from wp-content/plugins/ewplugin/includes/class-plugin-activator.php rename to wp-content/plugins/ewplugin/main/class-plugin-activator.php index 408f0b354..75560233a 100755 --- a/wp-content/plugins/ewplugin/includes/class-plugin-activator.php +++ b/wp-content/plugins/ewplugin/main/class-plugin-activator.php @@ -1,6 +1,6 @@ domain, @@ -42,10 +42,11 @@ public function load_plugin_textdomain() { /** * Set the domain equal to that of the specified domain. * + * @param string $domain The domain that represents the locale of this plugin. + * * @since 1.0.0 - * @param string $domain The domain that represents the locale of this plugin. */ - public function set_domain( $domain ) { + public function set_domain( string $domain ): void { $this->domain = $domain; } diff --git a/wp-content/plugins/ewplugin/main/class-plugin-loader.php b/wp-content/plugins/ewplugin/main/class-plugin-loader.php new file mode 100755 index 000000000..90420db6c --- /dev/null +++ b/wp-content/plugins/ewplugin/main/class-plugin-loader.php @@ -0,0 +1,128 @@ + + */ +class Plugin_Loader { + + /** + * The array of actions registered with WordPress. + * + * @since 1.0.0 + * @access protected + * @var array $actions The actions registered with WordPress to fire when the plugin loads. + */ + protected array $actions; + + /** + * The array of filters registered with WordPress. + * + * @since 1.0.0 + * @access protected + * @var array $filters The filters registered with WordPress to fire when the plugin loads. + */ + protected array $filters; + + /** + * Initialize the collections used to maintain the actions and filters. + * + * @since 1.0.0 + */ + public function __construct() { + $this->actions = array(); + $this->filters = array(); + } + + /** + * Add a new action to the collection to be registered with WordPress. + * + * @param string $hook The name of the WordPress action that is being registered. + * @param object|string $component A reference to the instance of the object on which the action is defined. + * @param string $callback The name of the function definition on the $component. + * @param int $priority Optional. The priority at which the function should be fired. Default is 10. + * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. + * + * @since 1.0.0 + */ + public function add_action( string $hook, object|string $component, string $callback, int $priority = 10, int $accepted_args = 1 ): void { + $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); + } + + /** + * Add a new filter to the collection to be registered with WordPress. + * + * @param string $hook The name of the WordPress filter that is being registered. + * @param object|string $component A reference to the instance of the object on which the filter is defined. + * @param string $callback The name of the function definition on the $component. + * @param int $priority Optional. The priority at which the function should be fired. Default is 10. + * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 + * + * @since 1.0.0 + */ + public function add_filter( string $hook, object|string $component, string $callback, int $priority = 10, int $accepted_args = 1 ): void { + $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); + } + + /** + * A utility function that is used to register the actions and hooks into a single + * collection. + * + * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). + * @param string $hook The name of the WordPress filter that is being registered. + * @param object|string $component A reference to the instance of the object on which the filter is defined. + * @param string $callback The name of the function definition on the $component. + * @param int $priority The priority at which the function should be fired. + * @param int $accepted_args The number of arguments that should be passed to the $callback. + * + * @return array The collection of actions and filters registered with WordPress. + * @since 1.0.0 + * @access private + */ + private function add( array $hooks, string $hook, object|string $component, string $callback, int $priority, int $accepted_args ): array { + + $hooks[] = array( + 'hook' => $hook, + 'component' => $component, + 'callback' => $callback, + 'priority' => $priority, + 'accepted_args' => $accepted_args + ); + + return $hooks; + + } + + /** + * Register the filters and actions with WordPress. + * + * @since 1.0.0 + */ + public function run(): void { + + foreach ( $this->filters as $hook ) { + add_filter( $hook['hook'], array( + $hook['component'], + $hook['callback'] + ), $hook['priority'], $hook['accepted_args'] ); + } + + foreach ( $this->actions as $hook ) { + add_action( $hook['hook'], array( + $hook['component'], + $hook['callback'] + ), $hook['priority'], $hook['accepted_args'] ); + } + + } + +} diff --git a/wp-content/plugins/ewplugin/includes/class-plugin.php b/wp-content/plugins/ewplugin/main/class-plugin.php similarity index 58% rename from wp-content/plugins/ewplugin/includes/class-plugin.php rename to wp-content/plugins/ewplugin/main/class-plugin.php index de8f5086c..38b1ed562 100755 --- a/wp-content/plugins/ewplugin/includes/class-plugin.php +++ b/wp-content/plugins/ewplugin/main/class-plugin.php @@ -1,6 +1,11 @@ */ class Plugin { - /** * The loader that's responsible for maintaining and registering all hooks that power * the plugin. @@ -26,7 +30,7 @@ class Plugin { * @access protected * @var Plugin_Loader $loader Maintains and registers all hooks for the plugin. */ - protected $loader; + protected Plugin_Loader $loader; /** * The unique identifier of this plugin. @@ -35,7 +39,7 @@ class Plugin { * @access protected * @var string $plugin_name The string used to uniquely identify this plugin. */ - protected $plugin_name; + protected string $plugin_name; /** * The current version of the plugin. @@ -44,7 +48,7 @@ class Plugin { * @access protected * @var string $version The current version of the plugin. */ - protected $version; + protected string $version; /** * Define the core functionality of the plugin. @@ -60,7 +64,8 @@ public function __construct() { $this->plugin_name = 'ew-plugin'; $this->version = '1.0.0'; - $this->load_dependencies(); + $this->loader = new Plugin_Loader(); + $this->set_locale(); $this->define_admin_hooks(); $this->define_public_hooks(); @@ -68,79 +73,6 @@ public function __construct() { $this->init_controllers(); } - /** - * Load the required dependencies for this plugin. - * - * Include the following files that make up the plugin: - * - * - Plugin_Name_Loader. Orchestrates the hooks of the plugin. - * - Plugin_Name_i18n. Defines internationalization functionality. - * - Plugin_Name_Admin. Defines all hooks for the admin area. - * - Plugin_Name_Public. Defines all hooks for the public side of the site. - * - * Create an instance of the loader which will be used to register the hooks - * with WordPress. - * - * @since 1.0.0 - */ - private function load_dependencies() { - /** - * Include constants required for plugin to work. - */ - require_once plugin_dir_path( dirname( __FILE__ ) ) . '/constants.php'; - - /** - * The class responsible for orchestrating the actions and filters of the - * core plugin. - */ - require_once PLUGIN_DIR . '/includes/class-plugin-loader.php'; - - /** - * The class responsible for defining internationalization functionality - * of the plugin. - */ - require_once PLUGIN_DIR . '/includes/class-plugin-i18n.php'; - - /** - * The class responsible for defining all actions that occur in the admin area. - */ - require_once PLUGIN_DIR . '/admin/class-plugin-admin.php'; - - /** - * The class responsible for defining all actions that occur in the public-facing - * side of the site. - */ - require_once PLUGIN_DIR . '/public/class-plugin-public.php'; - - /** - * Include autoload for all packages. - */ - require_once PLUGIN_DIR . '/vendor/autoload.php'; - - // Load exceptions - require_once PLUGIN_DIR . 'exceptions/class-validation-exception.php'; - - // Load helpers - require_once PLUGIN_DIR . 'helpers/class-random-values-helper.php'; - - // Load classes - require_once PLUGIN_DIR . 'classes/class-user-application.php'; - - // Load repositories - require_once PLUGIN_DIR . 'repositories/class-user-applications-repository.php'; - - // Load services - require_once PLUGIN_DIR . 'services/class-files-service.php'; - require_once PLUGIN_DIR . 'services/class-user-applications-service.php'; - - // Load controllers - require_once PLUGIN_DIR . 'controllers/class-aplugin-controller.php'; - require_once PLUGIN_DIR . 'controllers/class-user-applications-controller.php'; - - $this->loader = new Plugin_Loader(); - - } - /** * Define the locale for this plugin for internationalization. * @@ -149,7 +81,7 @@ private function load_dependencies() { * * @since 1.0.0 */ - private function set_locale() { + private function set_locale(): void { $plugin_i18n = new Plugin_i18n(); $plugin_i18n->set_domain( $this->get_plugin_name() ); @@ -157,12 +89,12 @@ private function set_locale() { } /** - * Register all of the hooks related to the admin area functionality + * Register all the hooks related to the admin area functionality * of the plugin. * * @since 1.0.0 */ - private function define_admin_hooks() { + private function define_admin_hooks(): void { $plugin_admin = new Plugin_Admin( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); @@ -170,12 +102,12 @@ private function define_admin_hooks() { } /** - * Register all of the hooks related to the public-facing functionality + * Register all the hooks related to the public-facing functionality * of the plugin. * * @since 1.0.0 */ - private function define_public_hooks() { + private function define_public_hooks(): void { $plugin_public = new Plugin_Public( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); @@ -187,17 +119,17 @@ private function define_public_hooks() { * * @since 1.0.0 */ - private function initialize_post_types() { + private function initialize_post_types(): void { // Init all custom post types. } /** * Initializes all custom REST API controllers. * + * @throws Exception * @since 1.0.0 - * @throws \Exception */ - private function init_controllers() { + private function init_controllers(): void { $controllers = [ new User_Applications_Controller() ]; @@ -208,11 +140,11 @@ private function init_controllers() { } /** - * Run the loader to execute all of the hooks with WordPress. + * Run the loader to execute all the hooks with WordPress. * * @since 1.0.0 */ - public function run() { + public function run(): void { $this->loader->run(); } @@ -220,8 +152,8 @@ public function run() { * The name of the plugin used to uniquely identify it within the context of * WordPress and to define internationalization functionality. * - * @since 1.0.0 * @return string The name of the plugin. + * @since 1.0.0 */ public function get_plugin_name(): string { return $this->plugin_name; @@ -230,8 +162,8 @@ public function get_plugin_name(): string { /** * The reference to the class that orchestrates the hooks with the plugin. * - * @since 1.0.0 * @return Plugin_Loader Orchestrates the hooks of the plugin. + * @since 1.0.0 */ public function get_loader(): Plugin_Loader { return $this->loader; @@ -240,8 +172,8 @@ public function get_loader(): Plugin_Loader { /** * Retrieve the version number of the plugin. * - * @since 1.0.0 * @return string The version number of the plugin. + * @since 1.0.0 */ public function get_version(): string { return $this->version; diff --git a/wp-content/plugins/ewplugin/classes/index.php b/wp-content/plugins/ewplugin/main/index.php similarity index 100% rename from wp-content/plugins/ewplugin/classes/index.php rename to wp-content/plugins/ewplugin/main/index.php diff --git a/wp-content/plugins/ewplugin/classes/class-user-application.php b/wp-content/plugins/ewplugin/models/class-user-application.php similarity index 75% rename from wp-content/plugins/ewplugin/classes/class-user-application.php rename to wp-content/plugins/ewplugin/models/class-user-application.php index f6bfc74c3..727d70dc8 100755 --- a/wp-content/plugins/ewplugin/classes/class-user-application.php +++ b/wp-content/plugins/ewplugin/models/class-user-application.php @@ -1,6 +1,8 @@ date_created = new \DateTime(); + $this->date_created = new DateTime(); // We construct empty object if ( empty( $row ) ) { @@ -99,6 +101,6 @@ public function __construct( array $row = [] ) { $this->city = $row['city']; $this->postal_code = $row['postal_code']; $this->invoice_file = $row['invoice_file']; - $this->date_created = \DateTime::createFromFormat( DATE_ATOM, $row['date_created'] ); + $this->date_created = DateTime::createFromFormat( DATE_ATOM, $row['date_created'] ); } } diff --git a/wp-content/plugins/ewplugin/includes/index.php b/wp-content/plugins/ewplugin/models/index.php similarity index 100% rename from wp-content/plugins/ewplugin/includes/index.php rename to wp-content/plugins/ewplugin/models/index.php diff --git a/wp-content/plugins/ewplugin/plugin-autoload-register.php b/wp-content/plugins/ewplugin/plugin-autoload-register.php new file mode 100755 index 000000000..0a190f086 --- /dev/null +++ b/wp-content/plugins/ewplugin/plugin-autoload-register.php @@ -0,0 +1,35 @@ +run(); +$autoload_file_path = plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; +if ( ! file_exists( $autoload_file_path ) ) { + throw new Exception( 'Run composer install' ); +} else { + // Load composer and dependencies + require_once $autoload_file_path; + require_once plugin_dir_path( __FILE__ ) . 'load-plugin.php'; } - -run_ew_plugin(); diff --git a/wp-content/plugins/ewplugin/public/class-plugin-public.php b/wp-content/plugins/ewplugin/public/class-plugin-public.php index 003ebc7bc..ca97bedac 100755 --- a/wp-content/plugins/ewplugin/public/class-plugin-public.php +++ b/wp-content/plugins/ewplugin/public/class-plugin-public.php @@ -1,6 +1,6 @@ plugin_name = $plugin_name; - $this->version = $version; + $this->version = $version; } /** @@ -47,7 +48,7 @@ public function __construct( string $plugin_name, string $version ) { * * @since 1.0.0 */ - public function enqueue_styles() { + public function enqueue_styles(): void { // TODO: Add stlyes } @@ -56,7 +57,7 @@ public function enqueue_styles() { * * @since 1.0.0 */ - public function enqueue_scripts() { + public function enqueue_scripts(): void { // TODO: Add scripts } diff --git a/wp-content/plugins/ewplugin/repositories/class-user-applications-repository.php b/wp-content/plugins/ewplugin/repositories/class-user-applications-repository.php index d9e20f972..ee1319736 100755 --- a/wp-content/plugins/ewplugin/repositories/class-user-applications-repository.php +++ b/wp-content/plugins/ewplugin/repositories/class-user-applications-repository.php @@ -6,10 +6,11 @@ * Time: 13:33 */ -namespace EwStarter; +namespace EwStarter\Repositories; use Ew\WpHelpers\Classes\Db_Data; use Ew\WpHelpers\Repositories\ARepository; +use EwStarter\Models\User_Application; /** * Class User_Applications_Repository @@ -95,7 +96,7 @@ public function get( int $id ): User_Application { * * @return mixed */ - protected function _construct_object( $table_row, $object_data = null ) { + protected function _construct_object( $table_row, $object_data = null ): User_Application { return new User_Application( $table_row ); } @@ -106,7 +107,7 @@ protected function _construct_object( $table_row, $object_data = null ) { * * @throws \Exception */ - private function validate( User_Application $user_application ) { + private function validate( User_Application $user_application ): void { $errors = []; $required_vars = [ 'first_name', diff --git a/wp-content/plugins/ewplugin/services/class-files-service.php b/wp-content/plugins/ewplugin/services/class-files-service.php index 77ccad06b..c029d70e6 100755 --- a/wp-content/plugins/ewplugin/services/class-files-service.php +++ b/wp-content/plugins/ewplugin/services/class-files-service.php @@ -6,7 +6,9 @@ * Time: 12:23 */ -namespace EwStarter; +namespace EwStarter\Services; + +use EwStarter\Helpers\Random_Values_Helper; /** * Class Files_Service diff --git a/wp-content/plugins/ewplugin/services/class-user-applications-service.php b/wp-content/plugins/ewplugin/services/class-user-applications-service.php index 445612da9..76ba451db 100755 --- a/wp-content/plugins/ewplugin/services/class-user-applications-service.php +++ b/wp-content/plugins/ewplugin/services/class-user-applications-service.php @@ -1,9 +1,12 @@ user_applications_repository = new \EwStarter\User_Applications_Repository(); + $this->user_applications_repository = new User_Applications_Repository(); } /** * Returns user application for testing. - * @return \EwStarter\User_Application + * @return User_Application */ private function get_test_user_application() { - $user_application = new \EwStarter\User_Application(); + $user_application = new User_Application(); $user_application->first_name = 'John'; $user_application->last_name = 'Doe'; $user_application->email = 'john@doe.com'; diff --git a/wp-content/plugins/ewplugin/tests/integration/test-user-applications-service.php b/wp-content/plugins/ewplugin/tests/integration/test-user-applications-service.php index 193419512..059aaa166 100755 --- a/wp-content/plugins/ewplugin/tests/integration/test-user-applications-service.php +++ b/wp-content/plugins/ewplugin/tests/integration/test-user-applications-service.php @@ -1,5 +1,8 @@ user_applications_service = new \EwStarter\User_Applications_Service(); + $this->user_applications_service = new User_Applications_Service(); } /** @@ -40,7 +43,7 @@ private function get_test_user_application_request_data() { /** * Tests user application create. - * @throws \EwStarter\Validation_Exception + * @throws Validation_Exception */ public function test_user_application_create() { $request_data = $this->get_test_user_application_request_data(); @@ -58,7 +61,7 @@ public function test_user_application_create() { /** * Tests user application that has invalid image file extension. - * @throws \EwStarter\Validation_Exception + * @throws Validation_Exception */ public function test_user_application_create_invalid_image_extension() { $request_data = $this->get_test_user_application_request_data(); @@ -87,11 +90,11 @@ public function test_user_application_create_invalid_image_extension() { /** * Tests user application create with validation fields. - * @throws \EwStarter\Validation_Exception + * @throws Validation_Exception */ public function test_user_application_create_validation_fields() { // We expect validation exception - $this->expectException( \EwStarter\Validation_Exception::class ); + $this->expectException( Validation_Exception::class ); $request_data = $this->get_test_user_application_request_data(); unset( $request_data['firstName'] ); @@ -102,11 +105,11 @@ public function test_user_application_create_validation_fields() { /** * Tests user application create with validation - image base64 is not valid. - * @throws \EwStarter\Validation_Exception + * @throws Validation_Exception */ public function test_user_application_create_validation_image_invalid_base64() { // We expect validation exception - $this->expectException( \EwStarter\Validation_Exception::class ); + $this->expectException( Validation_Exception::class ); $request_data = $this->get_test_user_application_request_data(); $request_data['invoiceFile'] = 'invalid-base-64'; @@ -116,7 +119,7 @@ public function test_user_application_create_validation_image_invalid_base64() { /** * Tests user application create with validation - base64 file is not an image. - * @throws \EwStarter\Validation_Exception + * @throws Validation_Exception */ public function test_user_application_create_validation_not_image_base64() { // We expect validation exception diff --git a/wp-content/plugins/ewplugin/tests/unit/test-random-values-helper.php b/wp-content/plugins/ewplugin/tests/unit/test-random-values-helper.php index c50ba143b..c9c218892 100755 --- a/wp-content/plugins/ewplugin/tests/unit/test-random-values-helper.php +++ b/wp-content/plugins/ewplugin/tests/unit/test-random-values-helper.php @@ -5,6 +5,8 @@ * @package Ewplugin */ +use EwStarter\Helpers\Random_Values_Helper; + /** * Random values helper test case. */ @@ -17,7 +19,7 @@ public function test_random_values_helper_length() { $expected_length = 10; // Get random string - $random_string = \EwStarter\Random_Values_Helper::get_random_string($expected_length); + $random_string = Random_Values_Helper::get_random_string($expected_length); // Actual length $actual_length = strlen($random_string);