From f59405c7f96795a5079a2b198d566bb261c4323b Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 24 Oct 2024 10:46:45 +0300 Subject: [PATCH] more OOP tweaks --- classes/class-base.php | 50 +++++++++++++++++++++++++++---- tests/phpunit/test-class-todo.php | 18 +---------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/classes/class-base.php b/classes/class-base.php index c7dcea9ac..056822edf 100644 --- a/classes/class-base.php +++ b/classes/class-base.php @@ -116,6 +116,20 @@ class Base { */ private $onboard; + /** + * An object containing actions classes. + * + * @var \stdClass|null + */ + private $actions; + + /** + * An instance of the \Progress_Planner\Rest_API class. + * + * @var \Progress_Planner\Rest_API|null + */ + private $rest_api; + /** * Constructor. */ @@ -148,18 +162,20 @@ public function init() { $this->get_admin()->dashboard_widgets->score = new \Progress_Planner\Admin\Dashboard_Widget_Score(); $this->get_admin()->dashboard_widgets->todo = new \Progress_Planner\Admin\Dashboard_Widget_Todo(); } - new \Progress_Planner\Actions\Content(); - new \Progress_Planner\Actions\Content_Scan(); - new \Progress_Planner\Actions\Maintenance(); + + $this->actions = new \stdClass(); + $this->actions->content = new \Progress_Planner\Actions\Content(); + $this->actions->content_scan = new \Progress_Planner\Actions\Content_Scan(); + $this->actions->maintenance = new \Progress_Planner\Actions\Maintenance(); // REST API. - new Rest_API(); + $this->rest_api = new Rest_API(); // Onboarding. $this->onboard = new Onboard(); // To-do. - new Todo(); + $this->todo = new Todo(); \add_filter( 'plugin_action_links_' . plugin_basename( PROGRESS_PLANNER_FILE ), [ $this, 'add_action_links' ] ); \add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_editor_script' ] ); @@ -342,6 +358,30 @@ public function get_onboard() { return $this->onboard; } + /** + * Get the actions instance. + * + * @return \stdClass + */ + public function get_actions() { + if ( ! $this->actions ) { + $this->actions = new \stdClass(); + } + return $this->actions; + } + + /** + * Get the rest api instance. + * + * @return \Progress_Planner\Rest_API + */ + public function get_rest_api() { + if ( ! $this->rest_api ) { + $this->rest_api = new Rest_API(); + } + return $this->rest_api; + } + /** * Get the activation date. * diff --git a/tests/phpunit/test-class-todo.php b/tests/phpunit/test-class-todo.php index bd7822a37..9d2c46b0d 100644 --- a/tests/phpunit/test-class-todo.php +++ b/tests/phpunit/test-class-todo.php @@ -14,29 +14,13 @@ */ class Todo_Test extends \WP_UnitTestCase { - /** - * Todo object. - * - * @var Todo - */ - protected $todo; - - /** - * Setup the test case. - * - * @return void - */ - public function set_up() { - $this->todo = new Todo(); - } - /** * Test get_items method. * * @return void */ public function test_get_items() { - $items = $this->todo->get_items(); + $items = \progress_planner()->get_todo()->get_items(); $this->assertIsArray( $items ); $this->assertEmpty( $items ); }