Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #182 from studiopress/fix/phpunit
Browse files Browse the repository at this point in the history
[Dont Merge Yet] Fix PHP unit errors with wp-env phpunit container removal
  • Loading branch information
johnstonphilip authored May 22, 2023
2 parents 03f5ce6 + 07f1281 commit a8cf26c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"test:js": "cd ../../wpps-scripts; sh test-js.sh $npm_package_wpps_options -p \"${OLDPWD}\";",
"zip": "cd ../../wpps-scripts; sh zip.sh $npm_package_wpps_options -p \"${OLDPWD}\";"
}
}
}
4 changes: 2 additions & 2 deletions wp-modules/api-data/tests/ApiDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ApiDataTest extends WP_UnitTestCase {
/**
* @inheritDoc
*/
public function setUp() {
public function setUp() : void {
parent::setUp();
add_filter( 'request_filesystem_credentials', '__return_true' );
add_filter( 'stylesheet_directory', [ $this, 'get_fixtures_directory' ] );
Expand All @@ -31,7 +31,7 @@ public function setUp() {
/**
* @inheritDoc
*/
public function tearDown() {
public function tearDown() : void {
unset( $GLOBALS['wp_rest_server'] );
remove_filter( 'request_filesystem_credentials', '__return_true' );
remove_filter( 'stylesheet_directory', [ $this, 'get_fixtures_directory' ] );
Expand Down
46 changes: 38 additions & 8 deletions wp-modules/editor/tests/EditorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,30 @@ public function test_register_pattern_post_type() {
public function test_register_pattern_post_type_meta_types() {
register_pattern_post_type();

foreach ( array_diff( get_pattern_defaults(), [ 'title' => null ] ) as $meta_key => $default_value ) {
$expected_type = get_registered_meta_keys( 'post', 'pm_pattern' )[ $meta_key ]['type'];
$pattern_default_keys = get_pattern_defaults();
$registered_keys = get_registered_meta_keys( 'post', 'pm_pattern' );

// Loop through each default key to make sure its type matches what was actually registered by WP.
foreach ( $pattern_default_keys as $meta_key => $default_value ) {

// The title and content pattern defaults are not registered meta keys, so skip them.
if ( 'title' === $meta_key || 'content' === $meta_key ) {
continue;
}

$expected_type = $registered_keys[ $meta_key ]['type'];

// Fix the typing for numbers.
if ( 'number' === $expected_type ) {
$expected_type = 'integer';
}

$actual_type = gettype( $default_value );

$this->assertSame(
'number' === $expected_type ? 'integer' : $expected_type,
gettype( $default_value ),
"the type of the default for {$meta_key} is wrong"
$expected_type,
$actual_type,
"The type of the default for {$meta_key} is wrong. It should be {$expected_type} but it was {$actual_type}"
);
}
}
Expand All @@ -54,11 +72,23 @@ public function test_register_pattern_post_type_meta_types() {
public function test_register_pattern_post_type_meta_defaults() {
register_pattern_post_type();

foreach ( array_diff( get_pattern_defaults(), [ 'title' => null ] ) as $meta_key => $default_value ) {
$pattern_default_keys = get_pattern_defaults();
$registered_keys = get_registered_meta_keys( 'post', 'pm_pattern' );

// Loop through each default key to make sure its default value matches what was actually registered by WP.
foreach ( $pattern_default_keys as $meta_key => $default_value ) {

// The title and content pattern defaults are not registered meta keys, so skip them.
if ( 'title' === $meta_key || 'content' === $meta_key ) {
continue;
}

$actual_value = $registered_keys[ $meta_key ]['default'];

$this->assertSame(
$default_value,
get_registered_meta_keys( 'post', 'pm_pattern' )[ $meta_key ]['default'],
"the default value of {$meta_key} is wrong"
$actual_value,
"The value of the default for {$meta_key} is wrong."
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion wp-modules/editor/tests/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UtilsTest extends WP_UnitTestCase {
/**
* @inheritDoc
*/
public function tearDown() {
public function tearDown() : void {
delete_pattern_posts();
parent::tearDown();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Class GetModuleDataTest
* Class PatternManagerGetModuleDataTest
*
* @package pattern-manager
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GetVersionControlTest extends WP_UnitTestCase {
/**
* @inheritDoc
*/
public function setUp() {
public function setUp() : void {
parent::setUp();

$this->user_id = $this->factory->user->create();
Expand All @@ -33,7 +33,7 @@ public function setUp() {
/**
* @inheritDoc
*/
public function tearDown() {
public function tearDown() : void {
delete_user_meta( $this->user_id, get_version_control_meta_key() );
wp_delete_user( $this->user_id );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PatternDataHandlersTest extends WP_UnitTestCase {
/**
* @inheritDoc
*/
public function setUp() {
public function setUp() : void {
parent::setUp();
add_filter( 'request_filesystem_credentials', '__return_true' );
add_filter( 'stylesheet_directory', [ $this, 'get_fixtures_directory' ] );
Expand All @@ -30,7 +30,7 @@ public function setUp() {
/**
* @inheritDoc
*/
public function tearDown() {
public function tearDown() : void {
remove_filter( 'request_filesystem_credentials', '__return_true' );
remove_filter( 'stylesheet_directory', [ $this, 'get_fixtures_directory' ] );
remove_filter( 'stylesheet_directory_uri', [ $this, 'get_stylesheet_directory_uri' ] );
Expand Down

0 comments on commit a8cf26c

Please sign in to comment.