From 5b937ac9b3a011d6962b1658a76607b5d6900c28 Mon Sep 17 00:00:00 2001 From: Dik Takken Date: Mon, 23 Sep 2024 16:38:27 +0200 Subject: [PATCH 1/8] (chore): Apply PHP CS Fixer --- config/seopress_api.php | 2 +- src/Base/Admin/AdminServiceProvider.php | 2 +- src/Base/Foundation/DependencyChecker.php | 2 +- src/Base/Metabox/Commands/AbstractConvert.php | 2 +- src/Base/Metabox/Commands/ConvertExpirationDate.php | 2 +- src/Base/RestAPI/Controllers/ThemeController.php | 4 ++-- src/Base/Settings/SettingsServiceProvider.php | 2 +- tests/Unit/Base/RestAPI/Controllers/ItemControllerTest.php | 7 +++---- 8 files changed, 11 insertions(+), 12 deletions(-) diff --git a/config/seopress_api.php b/config/seopress_api.php index 48e774a..a6b4c62 100644 --- a/config/seopress_api.php +++ b/config/seopress_api.php @@ -17,4 +17,4 @@ '_seopress_social_twitter_img_width', '_seopress_social_twitter_img_height', ] -]; \ No newline at end of file +]; diff --git a/src/Base/Admin/AdminServiceProvider.php b/src/Base/Admin/AdminServiceProvider.php index 21a2ef4..d1abc89 100644 --- a/src/Base/Admin/AdminServiceProvider.php +++ b/src/Base/Admin/AdminServiceProvider.php @@ -33,7 +33,7 @@ public function filterPostLink(string $link, WP_Post $post, bool $leavename, $sa */ public function filterPreviewLink(string $link, WP_Post $post): string { - if ($post->post_type !== 'openpub-item' || ! $this->plugin->settings->isPortalSlugValid()) { + if ($post->post_type !== 'openpub-item' || ! $this->plugin->settings->isPortalSlugValid()) { return $link; } diff --git a/src/Base/Foundation/DependencyChecker.php b/src/Base/Foundation/DependencyChecker.php index 91b82a2..c82012a 100644 --- a/src/Base/Foundation/DependencyChecker.php +++ b/src/Base/Foundation/DependencyChecker.php @@ -123,7 +123,7 @@ private function checkVersion(array $dependency): bool { try { $file = file_get_contents(WP_PLUGIN_DIR . '/' . $dependency['file']); - } catch(\Exception $e) { + } catch (\Exception $e) { return false; } diff --git a/src/Base/Metabox/Commands/AbstractConvert.php b/src/Base/Metabox/Commands/AbstractConvert.php index 398f5ce..f976886 100644 --- a/src/Base/Metabox/Commands/AbstractConvert.php +++ b/src/Base/Metabox/Commands/AbstractConvert.php @@ -31,7 +31,7 @@ public function execute(): void foreach ($this->flattenArray($holder) as $item) { try { $this->convert($item); - } catch(Exception $e) { + } catch (Exception $e) { WP_CLI::error(sprintf('Something went wrong with converting item [%s]. Error: %s', $item->post_title, $e->getMessage())); } } diff --git a/src/Base/Metabox/Commands/ConvertExpirationDate.php b/src/Base/Metabox/Commands/ConvertExpirationDate.php index d157ca8..bcf4635 100644 --- a/src/Base/Metabox/Commands/ConvertExpirationDate.php +++ b/src/Base/Metabox/Commands/ConvertExpirationDate.php @@ -31,7 +31,7 @@ protected function convertDateToTimeStamp(WP_Post $item): ?int try { $object = new DateTime($date); - } catch(Exception $e) { + } catch (Exception $e) { return null; } diff --git a/src/Base/RestAPI/Controllers/ThemeController.php b/src/Base/RestAPI/Controllers/ThemeController.php index 92c9a61..75b74e7 100644 --- a/src/Base/RestAPI/Controllers/ThemeController.php +++ b/src/Base/RestAPI/Controllers/ThemeController.php @@ -2,10 +2,10 @@ namespace OWC\OpenPub\Base\RestAPI\Controllers; -use WP_Post; +use OWC\OpenPub\Base\Repositories\Theme; use WP_Error; +use WP_Post; use WP_REST_Request; -use OWC\OpenPub\Base\Repositories\Theme; class ThemeController extends BaseController { diff --git a/src/Base/Settings/SettingsServiceProvider.php b/src/Base/Settings/SettingsServiceProvider.php index ebb493e..a4f8739 100644 --- a/src/Base/Settings/SettingsServiceProvider.php +++ b/src/Base/Settings/SettingsServiceProvider.php @@ -17,7 +17,7 @@ public function register() public function registerMissingNumberField($field, $escapedValue, $objectID, $objectType, $fieldTypeObject): void { - echo $fieldTypeObject->input(array( 'type' => 'number' )); + echo $fieldTypeObject->input([ 'type' => 'number' ]); } public function registerSettingsPages(): void diff --git a/tests/Unit/Base/RestAPI/Controllers/ItemControllerTest.php b/tests/Unit/Base/RestAPI/Controllers/ItemControllerTest.php index bdaf425..fa6371d 100644 --- a/tests/Unit/Base/RestAPI/Controllers/ItemControllerTest.php +++ b/tests/Unit/Base/RestAPI/Controllers/ItemControllerTest.php @@ -7,7 +7,6 @@ use OWC\OpenPub\Base\Foundation\Loader; use OWC\OpenPub\Base\Foundation\Plugin; use OWC\OpenPub\Base\RestAPI\Controllers\ItemController; -use OWC\OpenPub\Base\RestAPI\ItemFields\FeaturedImageField; use OWC\OpenPub\Tests\TestCase; use WP_Mock; use WP_Post; @@ -44,9 +43,9 @@ public function it_transforms_a_wp_object_to_array() $post->post_date = '01-01-2021'; $post->post_name = 'test-test'; - $itemController = m::mock(ItemController::class)->makePartial(); + $itemController = m::mock(ItemController::class)->makePartial(); - $itemController->shouldReceive('getImageUrl')->andReturn([]); + $itemController->shouldReceive('getImageUrl')->andReturn([]); WP_Mock::userFunction('get_the_post_thumbnail_url', [ 'args' => [ @@ -63,7 +62,7 @@ public function it_transforms_a_wp_object_to_array() 'excerpt' => 'Test excerpt', 'date' => '01-01-2021', 'thumbnail_url' => 'url-to-image', - 'image' => [], + 'image' => [], 'slug' => 'test-test', ]; From 99fd74c5c3eefbe4bfb974c666ce068c253c5259 Mon Sep 17 00:00:00 2001 From: Dik Takken Date: Mon, 23 Sep 2024 16:27:29 +0200 Subject: [PATCH 2/8] (chore): convert old PHPUnit config format --- phpunit.xml.dist | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6b9c4dc..96ac44f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,28 +1,16 @@ - - - - ./tests/Unit - - - - - ./src/Base/ - - - - - + + + + + ./src/Base/ + + + + + ./tests/Unit + + + + + From 41c26e4f67c7c625c8356f7d9dd1b6008f5f288f Mon Sep 17 00:00:00 2001 From: Dik Takken Date: Mon, 23 Sep 2024 16:35:30 +0200 Subject: [PATCH 3/8] (fix): Fix incorrect indentation specification in .editorconfig --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index 76ff616..35ba4d8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,6 +15,9 @@ indent_style = tab space_around_brackets = true indent_size = 4 +[*.php] +indent_style = space + [{.jshintrc,*.json,*.yml}] indent_style = space indent_size = 2 From d1529842de565f517d3eb65d227dd35fe94f6976 Mon Sep 17 00:00:00 2001 From: Dik Takken Date: Mon, 23 Sep 2024 16:28:28 +0200 Subject: [PATCH 4/8] (fix): Expiration dates are timestamps these days --- src/Base/RestAPI/ItemFields/ExpiredField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Base/RestAPI/ItemFields/ExpiredField.php b/src/Base/RestAPI/ItemFields/ExpiredField.php index c9f0b1f..fe25922 100644 --- a/src/Base/RestAPI/ItemFields/ExpiredField.php +++ b/src/Base/RestAPI/ItemFields/ExpiredField.php @@ -32,7 +32,7 @@ private function getExpiredStatus(WP_Post $post): array $timezone = \wp_timezone_string(); $dateNow = new DateTime('now', new DateTimeZone($timezone)); - $date = new DateTime(date('Y-m-d H:i:s', $date), new DateTimeZone($timezone)); // The date is saved in the timezone of the Wordpress installation. + $date = (new DateTime())->setTimestamp($date)->setTimezone(new DateTimeZone($timezone)); // The date is saved in the timezone of the Wordpress installation. return [ 'message' => ($date->getTimestamp() < $dateNow->getTimestamp()) ? 'Item is expired' : '', From 8674a6981658bde2d93fa6a38a1a392e70d13e72 Mon Sep 17 00:00:00 2001 From: Dik Takken Date: Mon, 23 Sep 2024 16:29:45 +0200 Subject: [PATCH 5/8] (fix): putenv() does not update $_ENV --- src/Base/Settings/SettingsServiceProvider.php | 2 +- tests/Unit/Base/ElasticPress/ElasticPressTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Base/Settings/SettingsServiceProvider.php b/src/Base/Settings/SettingsServiceProvider.php index a4f8739..30df692 100644 --- a/src/Base/Settings/SettingsServiceProvider.php +++ b/src/Base/Settings/SettingsServiceProvider.php @@ -43,7 +43,7 @@ public function registerSettingsPages(): void } } - protected function registerSettingsPage(array $page): void + public function registerSettingsPage(array $page): void { $fields = $page['fields'] ?? []; unset($page['fields']); // Fields will be added later on. diff --git a/tests/Unit/Base/ElasticPress/ElasticPressTest.php b/tests/Unit/Base/ElasticPress/ElasticPressTest.php index 2c43385..bd01c58 100644 --- a/tests/Unit/Base/ElasticPress/ElasticPressTest.php +++ b/tests/Unit/Base/ElasticPress/ElasticPressTest.php @@ -124,21 +124,21 @@ public function it_sets_the_correct_index_name() $indexName = ''; $siteID = 1; - putenv('environment=development'); + $_ENV['environment'] = 'development'; $expected = 'owc-openpub--1--development'; $actual = $this->service->setIndexNameByEnvironment($indexName, $siteID); $this->assertEquals($expected, $actual); - putenv('environment=test'); + $_ENV['environment'] = 'test'; $expected = 'owc-openpub--1--test'; $actual = $this->service->setIndexNameByEnvironment($indexName, $siteID); $this->assertEquals($expected, $actual); - putenv('environment='); + $_ENV['environment'] = ''; $expected = 'owc-openpub--1'; $actual = $this->service->setIndexNameByEnvironment($indexName, $siteID); @@ -146,7 +146,7 @@ public function it_sets_the_correct_index_name() $this->assertEquals($expected, $actual); define('EP_INDEX_PREFIX', 'prefix'); - putenv('environment=test'); + $_ENV['environment'] = 'test'; $expected = 'prefix--owc-openpub--1--test'; $actual = $this->service->setIndexNameByEnvironment($indexName, $siteID); From 58a0cc0e4fdba1021f133ddf1d02e81bd15040fd Mon Sep 17 00:00:00 2001 From: Dik Takken Date: Mon, 23 Sep 2024 17:25:47 +0200 Subject: [PATCH 6/8] (feat): Add github action for PHP CS Fixer --- .github/workflows/php-cs-fixer.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/php-cs-fixer.yml diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 0000000..bb9b7ad --- /dev/null +++ b/.github/workflows/php-cs-fixer.yml @@ -0,0 +1,25 @@ +name: Code Style + +on: + pull_request: + paths: + - '**.php' + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Run php-cs-fixer + uses: docker://oskarstark/php-cs-fixer-ga + + - uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: '(auto): apply php-cs-fixer changes' + push_options: '--force' + env: + GITHUB_TOKEN: ${{ secrets.YARD_BOT_PAT }} From a1704bcfe586cce793c1ce6f5f44894f8a1297f0 Mon Sep 17 00:00:00 2001 From: Dik Takken Date: Mon, 23 Sep 2024 16:32:02 +0200 Subject: [PATCH 7/8] (fix): Update unit tests --- .../Metabox/MetaboxServiceProviderTest.php | 130 +++------------ .../PostType/PostTypeServiceProviderTest.php | 8 + .../RestAPI/ItemFields/ExpiredFieldTest.php | 12 +- .../RestAPI/RestAPIServiceProviderTest.php | 2 +- .../Settings/SettingsServiceProviderTest.php | 149 ++---------------- 5 files changed, 54 insertions(+), 247 deletions(-) diff --git a/tests/Unit/Base/Metabox/MetaboxServiceProviderTest.php b/tests/Unit/Base/Metabox/MetaboxServiceProviderTest.php index e208f29..338fd80 100644 --- a/tests/Unit/Base/Metabox/MetaboxServiceProviderTest.php +++ b/tests/Unit/Base/Metabox/MetaboxServiceProviderTest.php @@ -6,6 +6,7 @@ use OWC\OpenPub\Base\Foundation\Config; use OWC\OpenPub\Base\Foundation\Loader; use OWC\OpenPub\Base\Foundation\Plugin; +use OWC\OpenPub\Base\Metabox\AdminNotice; use OWC\OpenPub\Base\Metabox\MetaboxServiceProvider; use OWC\OpenPub\Tests\TestCase; use WP_Mock; @@ -55,12 +56,20 @@ public function check_registration_of_metaboxes() $service = new MetaboxServiceProvider($plugin); - $plugin->loader->shouldReceive('addFilter')->withArgs([ - 'rwmb_meta_boxes', + $plugin->loader->shouldReceive('addAction')->withArgs([ + 'cmb2_admin_init', $service, 'registerMetaboxes', 10, - 1 + 0 + ])->once(); + + $plugin->loader->shouldReceive('addAction')->withArgs([ + 'admin_notices', + \Mockery::type(AdminNotice::class), + 'upgradeAdminNotice', + 10, + 0 ])->once(); $service->register(); @@ -100,113 +109,20 @@ public function check_registration_of_metaboxes() ] ]; - $prefix = MetaboxServiceProvider::PREFIX; - - $expectedMetaboxes = [ - 0 => [ - 'id' => 'metadata', - 'fields' => [ - [ - 'type' => 'heading' - ], - [ - 'id' => $prefix . 'metabox_id1' - ], - [ - 'id' => $prefix . 'metabox_id2' - ] - ] - ], - 1 => [ - 'id' => 'escape_element', - 'fields' => [ - [ - 'type' => 'heading' - ], - [ - 'id' => $prefix . 'metabox_id1' - ], - [ - 'id' => $prefix . 'metabox_id2' - ] - ] - ] - ]; - - $config->shouldReceive('get')->with('metaboxes')->once()->andReturn($configMetaboxes); - $config->shouldReceive('get')->with('escape_element_metabox')->once()->andReturn($configMetaboxes); - - //test for filter being called - \WP_Mock::expectFilter('owc/openpub/base/before-register-metaboxes', $expectedMetaboxes); - - $this->assertEquals($expectedMetaboxes, $service->registerMetaboxes([])); - - $existingMetaboxes = [ - 0 => [ - 'id' => 'existing_metadata', - 'fields' => [ - [ - 'type' => 'existing_heading' - ], - [ - 'id' => $prefix . 'existing_metabox_id1' - ], - [ - 'id' => $prefix . 'existing_metabox_id2' - ] - ] - ] - ]; + $config->shouldReceive('get')->with('cmb2_metaboxes')->once()->andReturn($configMetaboxes['base']); + $config->shouldReceive('get')->with('escape_element_metabox')->once()->andReturn($configMetaboxes['escape_element']); - $expectedMetaboxesAfterMerge = [ + $cmb2 = \Mockery::mock('CMB2'); + $cmb2->shouldReceive('add_field')->with(['type' => 'heading']); + $cmb2->shouldReceive('add_field')->with(['id' => '_owc_metabox_id1']); + $cmb2->shouldReceive('add_field')->with(['id' => '_owc_metabox_id2']); - 0 => [ - 'id' => 'existing_metadata', - 'fields' => [ - [ - 'type' => 'existing_heading' - ], - [ - 'id' => $prefix . 'existing_metabox_id1' - ], - [ - 'id' => $prefix . 'existing_metabox_id2' - ] - ] - ], - 1 => [ - 'id' => 'metadata', - 'fields' => [ - [ - 'type' => 'heading' - ], - [ - 'id' => $prefix . 'metabox_id1' - ], - [ - 'id' => $prefix . 'metabox_id2' - ] - ] - ], - 2 => [ - 'id' => 'escape_element', - 'fields' => [ - [ - 'type' => 'heading' - ], - [ - 'id' => $prefix . 'metabox_id1' - ], - [ - 'id' => $prefix . 'metabox_id2' - ] - ] - ] - ]; + \WP_Mock::userFunction('new_cmb2_box', [ + 'return' => $cmb2, + ]); - $config->shouldReceive('get')->with('metaboxes')->once()->andReturn($configMetaboxes); - $config->shouldReceive('get')->with('escape_element_metabox')->once()->andReturn($configMetaboxes); + $service->registerMetaboxes(); - $this->assertEquals($expectedMetaboxesAfterMerge, $service->registerMetaboxes($existingMetaboxes)); + $this->expectNotToPerformAssertions(); } } diff --git a/tests/Unit/Base/PostType/PostTypeServiceProviderTest.php b/tests/Unit/Base/PostType/PostTypeServiceProviderTest.php index 0e26ad0..9b083de 100644 --- a/tests/Unit/Base/PostType/PostTypeServiceProviderTest.php +++ b/tests/Unit/Base/PostType/PostTypeServiceProviderTest.php @@ -67,6 +67,14 @@ public function check_registration_of_posttypes() 'orderByPublishedDate', ])->once(); + $plugin->loader->shouldReceive('addAction')->withArgs([ + 'wp_insert_post_data', + $service, + 'fillPostName', + 10, + 4, + ])->once(); + /** * Examples of registering post types: http://johnbillion.com/extended-cpts/ */ diff --git a/tests/Unit/Base/RestAPI/ItemFields/ExpiredFieldTest.php b/tests/Unit/Base/RestAPI/ItemFields/ExpiredFieldTest.php index dbfeb4a..6e323b9 100644 --- a/tests/Unit/Base/RestAPI/ItemFields/ExpiredFieldTest.php +++ b/tests/Unit/Base/RestAPI/ItemFields/ExpiredFieldTest.php @@ -88,7 +88,7 @@ public function return_expired_status_when_date_is_in_future() 'true' ], 'times' => 1, - 'return' => $futureDate->format(self::DATETIMEFORMAT) + 'return' => $futureDate->getTimestamp() ]); $expiredField = new ExpiredField($this->plugin); @@ -97,7 +97,7 @@ public function return_expired_status_when_date_is_in_future() $this->assertEquals([ 'message' => '', 'status' => false, - 'on' => $futureDate + 'on' => $futureDate->format(self::DATETIMEFORMAT) ], $status); } @@ -114,7 +114,7 @@ public function return_expired_status_when_date_has_no_time() 'true' ], 'times' => 1, - 'return' => $futureDate->format(self::DATEFORMAT) + 'return' => $futureDate->getTimestamp() ]); $expiredField = new ExpiredField($this->plugin); @@ -123,7 +123,7 @@ public function return_expired_status_when_date_has_no_time() $this->assertEquals([ 'message' => '', 'status' => false, - 'on' => $futureDate + 'on' => $futureDate->format(self::DATETIMEFORMAT) ], $status); } @@ -140,7 +140,7 @@ public function return_expired_status_when_date_is_in_past() 'true' ], 'times' => 1, - 'return' => $pastDate->format(self::DATETIMEFORMAT) + 'return' => $pastDate->getTimestamp() ]); $expiredField = new ExpiredField($this->plugin); @@ -149,7 +149,7 @@ public function return_expired_status_when_date_is_in_past() $this->assertEquals([ 'message' => 'Item is expired', 'status' => true, - 'on' => $pastDate + 'on' => $pastDate->format(self::DATETIMEFORMAT) ], $status); } } diff --git a/tests/Unit/Base/RestAPI/RestAPIServiceProviderTest.php b/tests/Unit/Base/RestAPI/RestAPIServiceProviderTest.php index dfc872e..f75aa84 100644 --- a/tests/Unit/Base/RestAPI/RestAPIServiceProviderTest.php +++ b/tests/Unit/Base/RestAPI/RestAPIServiceProviderTest.php @@ -3,7 +3,7 @@ namespace OWC\OpenPub\Tests\Base\RestAPI; use Mockery as m; -use OWC\OpenPub\Base\Config; +use OWC\OpenPub\Base\Foundation\Config; use OWC\OpenPub\Base\Foundation\Loader; use OWC\OpenPub\Base\Foundation\Plugin; use OWC\OpenPub\Base\RestAPI\RestAPIServiceProvider; diff --git a/tests/Unit/Base/Settings/SettingsServiceProviderTest.php b/tests/Unit/Base/Settings/SettingsServiceProviderTest.php index d5bca20..ee756f4 100644 --- a/tests/Unit/Base/Settings/SettingsServiceProviderTest.php +++ b/tests/Unit/Base/Settings/SettingsServiceProviderTest.php @@ -55,34 +55,30 @@ public function check_registration_of_settings_metaboxes() $service = new SettingsServiceProvider($plugin); - $plugin->loader->shouldReceive('addFilter')->withArgs([ - 'mb_settings_pages', + $plugin->loader->shouldReceive('addAction')->withArgs([ + 'cmb2_render_number', $service, - 'registerSettingsPage', + 'registerMissingNumberField', 10, - 1 + 5 ])->once(); - $plugin->loader->shouldReceive('addFilter')->withArgs([ - 'rwmb_meta_boxes', + $plugin->loader->shouldReceive('addAction')->withArgs([ + 'cmb2_admin_init', $service, - 'registerSettings', + 'registerSettingsPages', 10, - 1 + 0 ])->once(); - $service->register(); - - $configSettingsPage = [ - 'base' => [ - 'id' => '_owc_openpub_base_settings', - 'option_name' => '_owc_openpub_base_settings' - ] - ]; + $cmb2 = \Mockery::mock('CMB2'); - $config->shouldReceive('get')->with('settings_pages')->once()->andReturn($configSettingsPage); + \WP_Mock::userFunction('new_cmb2_box', [ + 'return' => $cmb2, + ]); - $this->assertEquals($configSettingsPage, $service->registerSettingsPage([])); + $service->register(); + $service->registerSettingsPage([]); $existingSettingsPage = [ 0 => [ @@ -91,121 +87,8 @@ public function check_registration_of_settings_metaboxes() ] ]; - $existingSettingsPageAfterMerge = [ - - 0 => [ - 'id' => 'existing_settings_page', - 'option_name' => 'existing_settings_page' - ], - 'base' => [ - 'id' => '_owc_openpub_base_settings', - 'option_name' => '_owc_openpub_base_settings' - ] - ]; - - $config->shouldReceive('get')->with('settings_pages')->once()->andReturn($configSettingsPage); - - $this->assertEquals($existingSettingsPageAfterMerge, $service->registerSettingsPage($existingSettingsPage)); - - $configMetaboxes = [ - 'base' => [ - 'id' => 'metadata', - 'settings_pages' => 'base_settings_page', - 'fields' => [ - 'general' => [ - 'testfield_noid' => [ - 'type' => 'heading' - ], - 'testfield1' => [ - 'id' => 'metabox_id1' - ], - 'testfield2' => [ - 'id' => 'metabox_id2' - ] - ] - ] - ] - ]; - - $prefix = SettingsServiceProvider::PREFIX; - - $expectedMetaboxes = [ - 0 => [ - 'id' => 'metadata', - 'settings_pages' => 'base_settings_page', - 'fields' => [ - [ - 'type' => 'heading' - ], - [ - 'id' => $prefix . 'metabox_id1' - ], - [ - 'id' => $prefix . 'metabox_id2' - ] - ] - ] - ]; - - $config->shouldReceive('get')->with('settings')->once()->andReturn($configMetaboxes); - - //test for filter being called - \WP_Mock::expectFilter('owc/openpub/base/before-register-settings', $expectedMetaboxes); - - $this->assertEquals($expectedMetaboxes, $service->registerSettings([])); - - $existingMetaboxes = [ - 0 => [ - 'id' => 'existing_metadata', - 'fields' => [ - [ - 'type' => 'existing_heading' - ], - [ - 'id' => $prefix . 'existing_metabox_id1' - ], - [ - 'id' => $prefix . 'existing_metabox_id2' - ] - ] - ] - ]; - - $expectedMetaboxesAfterMerge = [ - - 0 => [ - 'id' => 'existing_metadata', - 'fields' => [ - [ - 'type' => 'existing_heading' - ], - [ - 'id' => $prefix . 'existing_metabox_id1' - ], - [ - 'id' => $prefix . 'existing_metabox_id2' - ] - ] - ], - 1 => [ - 'id' => 'metadata', - 'settings_pages' => 'base_settings_page', - 'fields' => [ - [ - 'type' => 'heading' - ], - [ - 'id' => $prefix . 'metabox_id1' - ], - [ - 'id' => $prefix . 'metabox_id2' - ] - ] - ] - ]; - - $config->shouldReceive('get')->with('settings')->once()->andReturn($configMetaboxes); + $service->registerSettingsPage($existingSettingsPage); - $this->assertEquals($expectedMetaboxesAfterMerge, $service->registerSettings($existingMetaboxes)); + $this->expectNotToPerformAssertions(); } } From bf8f82cb7fc0b1405d34b7afea026a2fd5cfbe39 Mon Sep 17 00:00:00 2001 From: Dik Takken Date: Tue, 24 Sep 2024 14:53:54 +0200 Subject: [PATCH 8/8] (feat): Generate coverage info --- .github/workflows/run-tests.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b0e65f9..47ea70d 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -36,16 +36,21 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} + extensions: xdebug tools: composer:v2 - coverage: none + coverage: xdebug - name: Install dependencies run: composer update --no-interaction --no-progress --prefer-dist --no-scripts - name: Execute tests - run: vendor/bin/phpunit --testsuite "Unit Test Suite" - + run: vendor/bin/phpunit --testsuite "Unit Test Suite" --coverage-clover coverage.xml + - name: Coverage Report as Comment (Clover) + if: github.event_name == 'pull_request' + uses: lucassabreu/comment-coverage-clover@main + with: + file: coverage.xml # Job to check if certain files have changed what-has-changed: