Skip to content

Commit 7fd952f

Browse files
committed
Improve test isolation and update CI workflows
Removed all existing adapter hooks in test setup methods to ensure tests run in isolation. Updated PHPCS workflow to generate a report file and improved PHPUnit matrix to explicitly test PHP 7.4 with WP 6.5 while running other PHP versions with the latest WP. Enhanced get_channels implementation to append channels to the input array if provided.
1 parent 8327032 commit 7fd952f

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

.github/workflows/phpcs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ jobs:
2424
run: composer install --prefer-dist --no-progress
2525

2626
- name: Run PHPCS
27-
run: composer lint -- -q --report-checkstyle | cs2pr
27+
run: |
28+
composer lint -- --report-checkstyle --report-file=phpcs-report.xml || true
29+
cs2pr phpcs-report.xml

.github/workflows/phpunit.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
strategy:
14+
fail-fast: false
1415
matrix:
1516
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
16-
wp-version: ['6.5', 'latest']
17+
wp-version: ['latest']
18+
include:
19+
- php-version: '7.4'
20+
wp-version: '6.5'
1721

1822
services:
1923
mysql:

tests/phpunit/includes/class-test-adapter-implementation.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,20 @@ class Test_Adapter_Implementation extends Adapter {
3838
* @return array Channels.
3939
*/
4040
public function get_channels( $channels, $user_id ) {
41-
return array(
42-
array(
43-
'uid' => 'notifications',
44-
'name' => 'Notifications',
45-
),
46-
array(
47-
'uid' => 'default',
48-
'name' => 'Home',
49-
),
41+
if ( ! is_array( $channels ) ) {
42+
$channels = array();
43+
}
44+
45+
$channels[] = array(
46+
'uid' => 'notifications',
47+
'name' => 'Notifications',
5048
);
49+
$channels[] = array(
50+
'uid' => 'default',
51+
'name' => 'Home',
52+
);
53+
54+
return $channels;
5155
}
5256

5357
/**

tests/phpunit/tests/class-test-adapter.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ class Test_Adapter extends WP_UnitTestCase {
3131
*/
3232
public function set_up() {
3333
parent::set_up();
34+
// Remove all existing adapter hooks to test in isolation.
35+
remove_all_filters( 'microsub_adapters' );
36+
remove_all_filters( 'microsub_get_channels' );
37+
remove_all_filters( 'microsub_get_timeline' );
38+
remove_all_filters( 'microsub_get_following' );
39+
remove_all_filters( 'microsub_follow' );
40+
remove_all_filters( 'microsub_unfollow' );
3441
$this->adapter = new Test_Adapter_Implementation();
3542
}
3643

tests/phpunit/tests/class-test-rest-controller.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ class Test_Rest_Controller extends WP_UnitTestCase {
3838
public function set_up() {
3939
parent::set_up();
4040

41+
// Remove all existing adapter hooks to test in isolation.
42+
remove_all_filters( 'microsub_adapters' );
43+
remove_all_filters( 'microsub_get_channels' );
44+
remove_all_filters( 'microsub_get_timeline' );
45+
remove_all_filters( 'microsub_get_following' );
46+
remove_all_filters( 'microsub_follow' );
47+
remove_all_filters( 'microsub_unfollow' );
48+
remove_all_filters( 'microsub_timeline_mark_read' );
49+
4150
global $wp_rest_server;
4251
$wp_rest_server = new \WP_REST_Server();
4352
$this->server = $wp_rest_server;

0 commit comments

Comments
 (0)