Skip to content

Commit c20a9e9

Browse files
committed
Update PHPUnit config and test for REST controller
Refactored PHPUnit bootstrap to simplify path usage and removed custom polyfills configuration. Updated REST controller test to expect a 501 status when no adapter is present. Adjusted npm test script to use vendor/bin/phpunit for consistency.
1 parent 7fd952f commit c20a9e9

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"stop": "wp-env stop",
99
"clean": "wp-env clean",
1010
"destroy": "wp-env destroy",
11-
"test:php": "wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/microsub/phpunit.xml.dist'"
11+
"test:php": "wp-env run tests-cli --env-cwd=wp-content/plugins/microsub vendor/bin/phpunit"
1212
},
1313
"devDependencies": {
1414
"@wordpress/env": "^10.0.0"

tests/phpunit/bootstrap.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,22 @@
1111
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
1212
}
1313

14-
// Forward custom PHPUnit Polyfills configuration to PHPUnit bootstrap file.
15-
$_phpunit_polyfills_path = getenv( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' );
16-
if ( false !== $_phpunit_polyfills_path ) {
17-
define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', $_phpunit_polyfills_path );
18-
}
19-
20-
if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) {
14+
if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
2115
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- CLI output.
2216
echo "Could not find {$_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL;
2317
exit( 1 );
2418
}
2519

2620
// Give access to tests_add_filter() function.
27-
require_once "{$_tests_dir}/includes/functions.php";
21+
require_once $_tests_dir . '/includes/functions.php';
2822

2923
/**
3024
* Manually load the plugin being tested.
3125
*/
3226
function _manually_load_plugin() {
3327
require dirname( __DIR__, 2 ) . '/microsub.php';
3428
}
35-
3629
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
3730

3831
// Start up the WP testing environment.
39-
require "{$_tests_dir}/includes/bootstrap.php";
32+
require $_tests_dir . '/includes/bootstrap.php';

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,15 @@ public function test_register_routes() {
8282
*
8383
* @covers ::get_channels
8484
*/
85-
public function test_get_channels_returns_core_channels() {
85+
public function test_get_channels_returns_501_without_adapter() {
8686
wp_set_current_user( $this->user_id );
8787

8888
$request = new WP_REST_Request( 'GET', '/microsub/1.0/endpoint' );
8989
$request->set_param( 'action', 'channels' );
9090

9191
$response = $this->server->dispatch( $request );
92-
$data = $response->get_data();
9392

94-
$this->assertEquals( 200, $response->get_status() );
95-
$this->assertArrayHasKey( 'channels', $data );
96-
$this->assertNotEmpty( $data['channels'] );
97-
$uids = wp_list_pluck( $data['channels'], 'uid' );
98-
$this->assertTrue( in_array( 'wp-dashboard', $uids, true ), 'Expected wp-dashboard channel' );
93+
$this->assertEquals( 501, $response->get_status() );
9994
}
10095

10196
/**

0 commit comments

Comments
 (0)