Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codesniffer: Stop suppressing Commenting.WrongStyle in Jetpack-Tests #37290

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions projects/packages/codesniffer/Jetpack-Tests/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,21 @@
<rule ref="Generic.Commenting.DocComment">
<exclude name="Generic.Commenting.DocComment.Missing" />
<exclude name="Generic.Commenting.DocComment.MissingShort" />
<exclude name="Generic.Commenting.DocComment.WrongStyle" />
</rule>
<rule ref="Squiz.Commenting.ClassComment">
<exclude name="Squiz.Commenting.ClassComment.Missing" />
<exclude name="Squiz.Commenting.ClassComment.WrongStyle" />
</rule>
<rule ref="Squiz.Commenting.FileComment">
<exclude name="Squiz.Commenting.FileComment.Missing" />
<exclude name="Squiz.Commenting.FileComment.MissingPackageTag" />
<exclude name="Squiz.Commenting.FileComment.WrongStyle" />
</rule>
<rule ref="Squiz.Commenting.FunctionComment">
<exclude name="Squiz.Commenting.FunctionComment.Missing" />
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment" />
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag" />
<exclude name="Squiz.Commenting.FunctionComment.WrongStyle" />
</rule>
<rule ref="Squiz.Commenting.VariableComment">
<exclude name="Squiz.Commenting.VariableComment.Missing" />
<exclude name="Squiz.Commenting.VariableComment.WrongStyle" />
</rule>

<!-- Tests aren't running inside WordPress, no need to sanitize input, escape output, or use WP-specific functions. -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

Jetpack-Tests: No longer exclude `Squiz.Commenting.*.WrongStyle`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Update comments in tests to fix `Squiz.Commenting.*.WrongStyle`.


Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
class WP_Test_Jetpack_Recommendations extends WP_UnitTestCase {

// The videopress recommendation should not be enabled if the module is on
public function test_videopress_is_not_recommended_if_module_enabled() {
\Jetpack::update_active_modules( array( 'videopress' ) );
$site_plan = $this->get_free_plan_mock();
Expand All @@ -21,7 +20,6 @@ public function test_videopress_is_not_recommended_if_module_enabled() {
$this->assertFalse( Jetpack_Recommendations::should_recommend_videopress( $site_plan, $site_products ) );
}

// Videopress recommendation is only be enabled if the site has a free plan
public function test_videopress_is_not_recommended_if_plan_not_free() {
$plans = array(
$this->get_security_plan_mock(),
Expand All @@ -34,23 +32,20 @@ public function test_videopress_is_not_recommended_if_plan_not_free() {
}
}

// Vidopress recommendation should not be enabled if the site has videopress annual product
public function test_videopress_is_not_recommended_if_site_has_videopress_product() {
$site_plan = $this->get_free_plan_mock();
$site_products = array( 'jetpack_videopress' );

$this->assertFalse( Jetpack_Recommendations::should_recommend_videopress( $site_plan, $site_products ) );
}

// Vidopress recommendation should not be enabled if the site has videopress monthly product
public function test_videopress_is_not_recommended_if_site_has_videopress_monthly_product() {
$site_plan = $this->get_free_plan_mock();
$site_products = array( 'jetpack_videopress_monthly' );

$this->assertFalse( Jetpack_Recommendations::should_recommend_videopress( $site_plan, $site_products ) );
}

// Videopress recommendation is enabled when a site has a free plan and no products
public function test_videopress_is_recommended_with_free_plan_and_no_products() {
$site_plan = $this->get_free_plan_mock();
$site_products = array();
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
require __DIR__ . '/lib/mock-functions.php';
require $test_root . '/includes/functions.php';

// Activates this plugin in WordPress so it can be tested.
/** Activates this plugin in WordPress so it can be tested. */
function _manually_load_plugin() {
if ( '1' === getenv( 'JETPACK_TEST_WOOCOMMERCE' ) ) {
require JETPACK_WOOCOMMERCE_INSTALL_DIR . '/woocommerce.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function wpSetUpBeforeClass( $factory ) {
add_filter( 'pre_http_request', array( __CLASS__, 'do_not_verify_mapbox' ), 10, 3 );
}

// GET
/** GET **/
public function test_get_services_api_key_mapbox() {
wp_set_current_user( self::$subscriber_user_id );
$request = new WP_REST_Request( 'GET', '/wpcom/v2/service-api-keys/mapbox' );
Expand All @@ -41,7 +41,7 @@ public function test_get_404_services_api_key_unknow_service() {
$this->assertTrue( isset( $data['message'] ) );
}

// UPDATE
/** UPDATE **/
public function test_update_services_api_key_mapbox_with_permission() {
wp_set_current_user( self::$editor_user_id );
$request = new WP_REST_Request( 'POST', '/wpcom/v2/service-api-keys/mapbox' );
Expand Down Expand Up @@ -102,7 +102,7 @@ public function test_update_404_services_api_key_unknow_service_without_permissi
$this->assertTrue( isset( $data['message'] ) );
}

// DELETE
/** DELETE **/
public function test_delete_service_api_key_mapbox_with_permission() {
wp_set_current_user( self::$editor_user_id );
$request = new WP_REST_Request( 'DELETE', '/wpcom/v2/service-api-keys/mapbox' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service\Jetpack_Token_Subscription_Service;

// Overrides the way Jetpack_Token_Subscription_Service get its JWT key
/** Overrides the way Jetpack_Token_Subscription_Service get its JWT key. */
class Test_Jetpack_Token_Subscription_Service extends Jetpack_Token_Subscription_Service {
public function get_key() {
return 'whatever';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function test_block_is_not_available_when_not_registered_returns_missing_
$this->assertEquals( 'missing_module', $availability['grape']['unavailable_reason'], 'unavailable_reason is not "missing_module"' );
}

// Plugins
/** Plugins **/
public function test_registered_plugin_is_available() {
Jetpack_Gutenberg::set_extension_available( 'jetpack/onion' );
$availability = Jetpack_Gutenberg::get_availability();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Status\Cache as StatusCache;

// Extend with a public constructor so that can be mocked in tests
/** Extend with a public constructor so that can be mocked in tests. */
class MockJetpack extends Jetpack {

/**
Expand Down Expand Up @@ -199,7 +199,7 @@ public function test_absolutize_css_urls_properly_handles_use_cases() {
$this->assertEquals( $expected, $result );
}

/*
/**
* @author tonykova
*/
public function test_implode_frontend_css_enqueues_bundle_file_handle() {
Expand Down Expand Up @@ -341,7 +341,7 @@ public function test_active_modules_filter_restores_state() {
$this->assertEquals( $active_modules, array( 'monitor', 'stats' ) );
}

// This filter overrides the 'monitor' module.
/** This filter overrides the 'monitor' module. */
public static function e2e_test_filter( $modules ) {
$disabled_modules = array( 'monitor' );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
/**
* @package automattic/jetpack
*/

// This is WP_Test_REST_Controller_Testcase without the unneeded abstract methods.
require_once __DIR__ . '/class-wp-test-spy-rest-server.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function test_sitemap_manager_filter_sitemap_location_sets_option_add() {
delete_option( 'jetpack_sitemap_location' );

// Set the location.
function add_location( $string ) { // phpcs:ignore MediaWiki.Usage.NestedFunctions.NestedFunction
function add_location( $string ) { // phpcs:ignore MediaWiki.Usage.NestedFunctions.NestedFunction,Squiz.Commenting.FunctionComment.WrongStyle
$string .= '/blah';
return $string;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php // phpcs:ignore WordPress.Files.FileName

// special factory that creates transient versions of various WP objects
/** Special factory that creates transient versions of various WP objects. */
class JetpackSyncTestObjectFactory {
public static $default_post_props = array(
'post_title' => 'The Title',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function current_theme_supports( $feature ) {
return isset( $theme_supports[ $feature ] );
}

// meta
/** Meta **/
public function get_metadata( $type, $object_id, $meta_key = '', $single = false ) {

$object_id = absint( $object_id );
Expand Down Expand Up @@ -267,7 +267,7 @@ public function get_metadata( $type, $object_id, $meta_key = '', $single = false
return $meta_values;
}

// this is just here to support checksum histograms
/** This is just here to support checksum histograms */
public function get_post_meta_by_id( $meta_id ) {
$matching_metas = array();
$metas = $this->meta[ get_current_blog_id() ]['post'];
Expand All @@ -279,7 +279,7 @@ public function get_post_meta_by_id( $meta_id ) {
return reset( $matching_metas );
}

// this is just here to support checksum histograms
/** This is just here to support checksum histograms */
public function get_comment_meta_by_id( $meta_id ) {
$matching_metas = array();
$metas = $this->meta[ get_current_blog_id() ]['comment'];
Expand Down Expand Up @@ -339,7 +339,7 @@ public function delete_batch_metadata( $type, $object_ids, $meta_key ) {
}
}

// constants
/** Constants **/
public function get_constant( $constant ) {
if ( ! isset( $this->constants[ get_current_blog_id() ][ $constant ] ) ) {
return null;
Expand All @@ -354,7 +354,7 @@ public function set_constant( $constant, $value ) {
return $this->constants[ get_current_blog_id() ][ $constant ];
}

// updates
/** Updates **/
public function get_updates( $type ) {
if ( ! isset( $this->updates[ get_current_blog_id() ][ $type ] ) ) {
return null;
Expand All @@ -367,7 +367,7 @@ public function set_updates( $type, $updates ) {
$this->updates[ get_current_blog_id() ][ $type ] = $updates;
}

// updates
/** Updates **/
public function get_callable( $function ) {
if ( ! isset( $this->callable[ get_current_blog_id() ][ $function ] ) ) {
return null;
Expand All @@ -380,7 +380,7 @@ public function set_callable( $name, $value ) {
$this->callable[ get_current_blog_id() ][ $name ] = $value;
}

// network options
/** Network options **/
public function get_site_option( $option ) {
return isset( $this->network_options[ get_current_blog_id() ][ $option ] ) ? $this->network_options[ get_current_blog_id() ][ $option ] : false;
}
Expand All @@ -393,7 +393,7 @@ public function delete_site_option( $option ) {
$this->network_options[ get_current_blog_id() ][ $option ] = false;
}

// terms
/** Terms **/
public function get_terms( $taxonomy ) {
return isset( $this->terms[ get_current_blog_id() ][ $taxonomy ] ) ? $this->terms[ get_current_blog_id() ][ $taxonomy ] : array();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
require_once $sync_server_dir . 'class.jetpack-sync-server-eventstore.php';
require_once $sync_server_dir . 'class.jetpack-sync-test-helper.php';

/*
/**
* Base class for Sync tests - establishes connection between local
* Automattic\Jetpack\Sync\Sender and dummy server implementation,
* and registers a Replicastore and Eventstore implementation to
* process events.
*/

class WP_Test_Jetpack_Sync_Base extends WP_UnitTestCase {
protected $listener;
protected $sender;
Expand Down Expand Up @@ -130,9 +129,11 @@ protected function assertDataIsSynced() {
$this->assertEquals( $local->get_comments(), $remote->get_comments() );
}

// asserts that two objects are the same if they're both "objectified",
// i.e. json_encoded and then json_decoded
// this is useful because we json encode everything sent to the server
/**
* Asserts that two objects are the same if they're both "objectified",
* i.e. json_encoded and then json_decoded
* this is useful because we json encode everything sent to the server
*/
protected function assertEqualsObject( $object_1, $object_2, $message = null ) {
$this->assertEquals( $this->objectify( $object_1 ), $this->objectify( $object_2 ), $message );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function test_modify_comment_multiple_attributes() {
$this->modify_comment_helper( $comment, $expected_variable );
}

/*
/**
* Updates comment, checks that event args match expected, checks event is not duplicated
*/
private function modify_comment_helper( $comment, $expected_variable ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function set_up() {
// TODO:
// Add tests for Syncing data on shutdown
// Add tests that prove that we know constants change
// phpcs:ignore Squiz.Commenting.FunctionComment.WrongStyle -- Confuses this for a function comment.

public function test_white_listed_constant_is_synced() {
$helper = new Jetpack_Sync_Test_Helper();
$helper->array_override = array( 'TEST_FOO' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function test_sync_health_in_sync_on_full_sync_end() {
$this->assertEquals( Health::get_status(), Health::STATUS_IN_SYNC );
}

// this only applies to the test replicastore - in production we overlay data
/** This only applies to the test replicastore - in production we overlay data. */
public function test_sync_start_resets_storage() {
self::factory()->post->create();
$this->sender->do_sync();
Expand Down Expand Up @@ -371,7 +371,6 @@ public function test_full_sync_sends_previous_interval_end_for_users() {
$this->assertEquals( '~0', $previous_interval_end );
}

// phpunit -c tests/php.multisite.xml --filter test_full_sync_sends_only_current_blog_users_in_multisite
public function test_full_sync_sends_only_current_blog_users_in_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Run it in multi site mode' );
Expand Down Expand Up @@ -557,7 +556,6 @@ public function test_full_sync_sends_all_options() {
$this->assertFalse( $this->server_replica_storage->get_option( 'non_existant' ) );
}

// to test run phpunit -c tests/php.multisite.xml --filter test_full_sync_sends_all_network_options
public function test_full_sync_sends_all_network_options() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Run it in multi site mode' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function test_enqueues_sync_start_action_without_post_sends_empty_range()
$this->assertFalse( isset( $empty['comments'] ) );
}

// this only applies to the test replicastore - in production we overlay data
/** This only applies to the test replicastore - in production we overlay data */
public function test_sync_start_resets_storage() {
self::factory()->post->create();
$this->sender->do_sync();
Expand Down Expand Up @@ -540,7 +540,6 @@ public function test_full_sync_sends_previous_interval_end_for_users() {
$this->full_sync->reset_data();
}

// phpunit -c tests/php.multisite.xml --filter test_full_sync_sends_only_current_blog_users_in_multisite
public function test_full_sync_sends_only_current_blog_users_in_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Run it in multi site mode' );
Expand Down Expand Up @@ -733,7 +732,6 @@ public function test_full_sync_sends_all_options() {
$this->assertFalse( $this->server_replica_storage->get_option( 'non_existant' ) );
}

// to test run phpunit -c tests/php.multisite.xml --filter test_full_sync_sends_all_network_options
public function test_full_sync_sends_all_network_options() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Run it in multi site mode' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,33 @@ public function test_import_sync_sends_class_for_unknown_importer() {
}
}

// We try to detect importers based in extending `WP_Importer`. Mock that class, if needed.
// phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound
/**
* We try to detect importers based in extending `WP_Importer`. Mock that class, if needed.
*/
if ( ! class_exists( 'WP_Importer', false ) ) {
class WP_Importer {}
}

// Mock known importer. Uses class name of a real importer plugin.
// @phan-suppress-next-line PhanRedefinedExtendedClass -- Ignore stub definition above.
/**
* Mock known importer. Uses class name of a real importer plugin.
*/
class RSS_Import extends WP_Importer {
// @phan-suppress-previous-line PhanRedefinedExtendedClass -- Ignore stub definition above.

/** Start fake import. */
public function start_fake_rss_import() {
do_action( 'import_start' );
}
}

// Mock unknown importer.
// @phan-suppress-next-line PhanRedefinedExtendedClass -- Ignore stub definition above.
/**
* Mock unknown importer.
*/
class Unknown_Import extends WP_Importer {
// @phan-suppress-previous-line PhanRedefinedExtendedClass -- Ignore stub definition above.

/** Start fake import. */
public function start_fake_import() {
do_action( 'import_start' );
}
Expand Down
Loading
Loading