Skip to content

Create Checks class #12

@mehulkaklotar

Description

@mehulkaklotar

Description

The Checks class will be the main class for running checks against a plugin. This class contains all the logic to collect the Plugin and Check contexts, run Preparations ahead of checks, loop over and run all Checks and collect and return the results.

Containing this logic within a single class decoupled from I/O allows this class to be used in the different contexts in which checks can run, such as WP-CLI or in the WordPress admin, without duplicating efforts and logic which is described more in detail in the Check Orchestration and Execution Approach.

The class will contain a method to return all available checks that can be run against the plugin, which is filterable so developers can extend/modify which checks should run.

Additionally, a method to run a set of checks (by default all checks) should be provided, so the entire suite of checks can be used or a plugin can be tested against one check alone as checks are provided as a list. The method can iterate through the list of checks and execute them. For example, it allows running a single check when a CLI command is executed with one check to test for a plugin and it also allows running a single check as part of running all checks for a plugin when a CLI command or even AJAX requests is initiated to test a plugin for all checks.

The Checks class is also responsible for preparation work ahead of running tests and cleanup after tests have run.

Acceptance Criteria

  • Checks class is created and exists at includes/Checker
  • Protected property $check_context should be there which is an instance of Check_Context
  • Constructor receives the $plugin_main_file as an argument
  • Method get_checks should be created as public and returns the list of checks
  • Method run_check_with_result should be created as protected and receives Check $check and Check_Result $check_result as an arguments.
  • Method run_checks should be created as public and accepts a single parameter array $checks which is an array of the check class names to run. The method will loop over the $checks array and run each check by calling run_check_with_result.

Tests Coverage

  • get_checks method returns the list of expected checks
  • run_check_with_result runs expected check and result is stored as expected
  • run_checks runs the expected checks based on the parameter passed

Metadata

Metadata

Assignees

Labels

InfrastructureIssues for the overall plugin infrastructure[Type] EnhancementA suggestion for improvement of an existing feature

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions