[wp-trac] [WordPress Trac] #46836: Site Health: Allow any callable for a direct site health test.

WordPress Trac noreply at wordpress.org
Tue Apr 9 00:33:44 UTC 2019


#46836: Site Health: Allow any callable for a direct site health test.
----------------------------+---------------------
 Reporter:  kraftbj         |       Owner:  (none)
     Type:  defect (bug)    |      Status:  new
 Priority:  normal          |   Milestone:  5.2
Component:  Administration  |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  has-patch       |     Focuses:
----------------------------+---------------------

Comment (by kraftbj):

 Real-life example: https://github.com/Automattic/jetpack/pull/11976

 In this case, we already have an existing testing suite that we want to
 add results of to the Site Health check. Each individual test is a
 separate protected method of a class and our process for adding new tests
 is simply add a new `test__` prefixed-function in a file.

 The current implementation makes it difficult since we would need a
 globally-scoped function for each test (unless I'm missing something a bit
 creative).

 If we allow any callable, we could either pass an class/method array in
 the individual test was public or, within the filtering function,
 dynamically run each test.

 e.g.
 {{{
 function jetpack_add_tests( $core_tests ) {
         $suite = new Jetpack_Cxn_Tests();
         $tests = $suite->list_tests(); // array
         foreach ( $tests as $test ) {
                 $core_tests[] = array(
                         'label' => $test['label'],
                         ...
                         'test' => function( $test ) {
                                 $suite  = new Jetpack_Cxn_Tests();
                                 $result = $suite->run_test( $test['name']
 );
                                 return array(... ); // dynamic mapping of
 our result format to Core's
                         },
                 );
         }
         return $core_tests;
 }

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46836#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list