From 723d89e9c6cb6337469b1d2aef40e7b4a3dd8582 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Thu, 30 Sep 2021 13:27:36 +0100 Subject: [PATCH] Add namespaces to some files See #396. Also move integration tests around - fixes #425. --- src/class-parsely-recommended-widget.php | 5 +- .../Integrations/IntegrationsTest.php | 3 +- tests/Integration/RecommendedApiTest.php | 4 +- .../CustomPostTypeArchiveTest.php | 2 +- .../CustomTaxonomyTermArchiveTest.php | 2 +- tests/{ => Integration}/UI/RowActionsTest.php | 4 +- tests/Integration/bootstrap.php | 2 + tests/UI/PluginsActionsTest.php | 47 ------------------- tests/Unit/bootstrap.php | 2 + wp-parsely.php | 20 +++++--- 10 files changed, 26 insertions(+), 65 deletions(-) rename tests/{ => Integration}/StructuredData/CustomPostTypeArchiveTest.php (98%) rename tests/{ => Integration}/StructuredData/CustomTaxonomyTermArchiveTest.php (98%) rename tests/{ => Integration}/UI/RowActionsTest.php (99%) delete mode 100644 tests/UI/PluginsActionsTest.php diff --git a/src/class-parsely-recommended-widget.php b/src/class-parsely-recommended-widget.php index 9c186e580..62b3e22c4 100644 --- a/src/class-parsely-recommended-widget.php +++ b/src/class-parsely-recommended-widget.php @@ -12,10 +12,7 @@ declare(strict_types=1); /** - * This is the class for the recommended widget - * - * @category Class - * @package Parsely_Recommended_Widget + * This is the class for the recommended widget. */ class Parsely_Recommended_Widget extends WP_Widget { /** diff --git a/tests/Integration/Integrations/IntegrationsTest.php b/tests/Integration/Integrations/IntegrationsTest.php index c0fbbe14f..584051f69 100644 --- a/tests/Integration/Integrations/IntegrationsTest.php +++ b/tests/Integration/Integrations/IntegrationsTest.php @@ -12,6 +12,7 @@ use Parsely\Integrations\Integrations; use Parsely\Tests\Integration\TestCase; use ReflectionClass; +use function Parsely\parsely_integrations; /** * Test plugin integrations collection class. @@ -38,7 +39,7 @@ function( $integrations ) { } ); - $integrations = \parsely_integrations(); + $integrations = parsely_integrations(); // Use Reflection to look inside the collection. $reflector_property = ( new ReflectionClass( $integrations ) )->getProperty( 'integrations' ); diff --git a/tests/Integration/RecommendedApiTest.php b/tests/Integration/RecommendedApiTest.php index 476231bcd..cf04e040d 100644 --- a/tests/Integration/RecommendedApiTest.php +++ b/tests/Integration/RecommendedApiTest.php @@ -61,8 +61,8 @@ public function data_recommended_api_url(): array { * Test the basic generation of the API URL. * * @dataProvider data_recommended_api_url - * @covers \Parsely_Recommended_Widget::get_api_url - * @uses \Parsely_Recommended_Widget::__construct + * @covers \Parsely\Widgets\Recommended_Widget::get_api_url + * @uses \Parsely\Widgets\Recommended_Widget::__construct * @group widgets * * @param string $api_key Publisher Site ID (API key). diff --git a/tests/StructuredData/CustomPostTypeArchiveTest.php b/tests/Integration/StructuredData/CustomPostTypeArchiveTest.php similarity index 98% rename from tests/StructuredData/CustomPostTypeArchiveTest.php rename to tests/Integration/StructuredData/CustomPostTypeArchiveTest.php index 85660b7df..70b45deb1 100644 --- a/tests/StructuredData/CustomPostTypeArchiveTest.php +++ b/tests/Integration/StructuredData/CustomPostTypeArchiveTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\StructuredData; +namespace Parsely\Tests\Integration\StructuredData; /** * Structured Data Tests for the custom post type (archive). diff --git a/tests/StructuredData/CustomTaxonomyTermArchiveTest.php b/tests/Integration/StructuredData/CustomTaxonomyTermArchiveTest.php similarity index 98% rename from tests/StructuredData/CustomTaxonomyTermArchiveTest.php rename to tests/Integration/StructuredData/CustomTaxonomyTermArchiveTest.php index 415ca513c..1402c86ad 100644 --- a/tests/StructuredData/CustomTaxonomyTermArchiveTest.php +++ b/tests/Integration/StructuredData/CustomTaxonomyTermArchiveTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\StructuredData; +namespace Parsely\Tests\Integration\StructuredData; /** * Structured Data Tests for the custom taxonomy term (archive). diff --git a/tests/UI/RowActionsTest.php b/tests/Integration/UI/RowActionsTest.php similarity index 99% rename from tests/UI/RowActionsTest.php rename to tests/Integration/UI/RowActionsTest.php index 8d6b7662b..b24eb633b 100644 --- a/tests/UI/RowActionsTest.php +++ b/tests/Integration/UI/RowActionsTest.php @@ -7,10 +7,10 @@ declare(strict_types=1); -namespace Parsely\Tests\UI; +namespace Parsely\Tests\Integration\UI; use Parsely; -use Parsely\Tests\TestCase; +use Parsely\Tests\Integration\TestCase; use Parsely\UI\Row_Actions; /** diff --git a/tests/Integration/bootstrap.php b/tests/Integration/bootstrap.php index 6af53efa3..89826361e 100644 --- a/tests/Integration/bootstrap.php +++ b/tests/Integration/bootstrap.php @@ -7,6 +7,8 @@ declare(strict_types=1); +namespace Parsely\Tests\Integration; + use Yoast\WPTestUtils\WPIntegration; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound diff --git a/tests/UI/PluginsActionsTest.php b/tests/UI/PluginsActionsTest.php deleted file mode 100644 index 93772cd22..000000000 --- a/tests/UI/PluginsActionsTest.php +++ /dev/null @@ -1,47 +0,0 @@ -run(); - - self::assertNotFalse( has_filter( 'plugin_action_links_' . plugin_dir_path( PARSELY_FILE ), array( $plugins_screen, 'add_plugin_meta_links' ) ) ); - } - - /** - * Check that plugins screen will add a hook to change the plugin action links. - * - * @covers \Parsely\UI\Plugins_Actions::run - * @covers \Parsely\UI\Plugins_Actions::add_plugin_meta_links - * @uses \Parsely::get_settings_url - * @group ui - */ - public function test_plugins_screen_adds_a_settings_action_link(): void { - $actions = array(); - $plugins_screen = new Plugins_Actions(); - $actions = $plugins_screen->add_plugin_meta_links( $actions ); - - self::assertCount( 1, $actions ); - } -} diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php index 0ad23bae8..575d97b08 100644 --- a/tests/Unit/bootstrap.php +++ b/tests/Unit/bootstrap.php @@ -7,6 +7,8 @@ declare(strict_types=1); +namespace Parsely\Tests\Unit; + /** * Require BrainMonkey files and autoload the plugin code. */ diff --git a/wp-parsely.php b/wp-parsely.php index 2684ed588..4fa1a5f35 100644 --- a/wp-parsely.php +++ b/wp-parsely.php @@ -24,12 +24,17 @@ declare(strict_types=1); +namespace Parsely; + +use Parsely; use Parsely\Integrations\Amp; use Parsely\Integrations\Facebook_Instant_Articles; use Parsely\Integrations\Integrations; +use Parsely\UI\Plugins_Actions; use Parsely\UI\Row_Actions; +use Parsely_Recommended_Widget; -if ( class_exists( 'Parsely' ) ) { +if ( class_exists( Parsely::class ) ) { return; } @@ -51,7 +56,8 @@ function(): void { add_action( 'admin_init', function(): void { - $GLOBALS['parsely_ui_plugins_actions'] = new Parsely\UI\Plugins_Actions(); + $GLOBALS['parsely_ui_plugins_actions'] = new Plugins_Actions(); + $GLOBALS['parsely_ui_plugins_actions']->run(); $row_actions = new Row_Actions( $GLOBALS['parsely'] ); @@ -59,19 +65,19 @@ function(): void { } ); -require __DIR__ . '/src/class-parsely-recommended-widget.php'; +require __DIR__ . '/src/Widgets/class-parsely-recommended-widget.php'; -add_action( 'widgets_init', 'parsely_recommended_widget_register' ); +add_action( 'widgets_init', __NAMESPACE__ . '\\parsely_recommended_widget_register' ); /** * Register the Parse.ly Recommended widget. * * @return void */ function parsely_recommended_widget_register(): void { - register_widget( 'Parsely_Recommended_Widget' ); + register_widget( Parsely_Recommended_Widget::class ); } -add_action( 'init', 'parsely_load_textdomain' ); +add_action( 'init', __NAMESPACE__ . '\\parsely_load_textdomain' ); /** * Load plugin textdomain. * @@ -94,7 +100,7 @@ function parsely_load_textdomain(): void { require __DIR__ . '/src/Integrations/class-amp.php'; require __DIR__ . '/src/Integrations/class-facebook-instant-articles.php'; -add_action( 'init', 'parsely_integrations' ); +add_action( 'init', __NAMESPACE__ . '\\parsely_integrations' ); /** * Instantiate Integrations collection and register built-in integrations. *