-
Notifications
You must be signed in to change notification settings - Fork 109
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
Improve Test Coverage for Speculation Rules Plugin #1845
base: trunk
Are you sure you want to change the base?
Improve Test Coverage for Speculation Rules Plugin #1845
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## trunk #1845 +/- ##
==========================================
+ Coverage 65.97% 67.66% +1.69%
==========================================
Files 88 87 -1
Lines 6895 6863 -32
==========================================
+ Hits 4549 4644 +95
+ Misses 2346 2219 -127
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
plugins/speculation-rules/tests/test-speculation-rules-settings.php
Outdated
Show resolved
Hide resolved
plugins/speculation-rules/tests/test-speculation-rules-settings.php
Outdated
Show resolved
Hide resolved
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @[email protected]. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
plugins/speculation-rules/tests/test-speculation-rules-settings.php
Outdated
Show resolved
Hide resolved
plugins/speculation-rules/tests/test-speculation-rules-settings.php
Outdated
Show resolved
Hide resolved
} | ||
|
||
/** | ||
* Function to test sanitize_setting() with various inputs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Function to test sanitize_setting() with various inputs. | |
* Function to test sanitize_setting() with various inputs. | |
* | |
* @covers ::plsr_sanitize_setting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I kept the @covers
annotation just like suggested changes however that's resulting in reduced code coverage.
If covers annotation is not there it automatically finds the function that is being tested.
However if we are specifying like this then coverage reduced. Also tested with ClassName::FunctionName
annotation.
- Without coverage annotation :
![image](https://private-user-images.githubusercontent.com/69689387/410170740-b60510d0-3248-4a58-8448-5458e86ef0ec.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwODA3NzEsIm5iZiI6MTczOTA4MDQ3MSwicGF0aCI6Ii82OTY4OTM4Ny80MTAxNzA3NDAtYjYwNTEwZDAtMzI0OC00YTU4LTg0NDgtNTQ1OGU4NmVmMGVjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA1NTQzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQxZjYxZWQwY2M1YWI1N2U4YzhhNjc2YzMwNjBjZWVjYjhmNDU1YzI5OWUxMmZiZWNkNThmN2FhNjY5M2Q0ODUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.2lw5ieebpD7cIHJR6kExLuadR-8eGQ5GpESZ1bA-IfQ)
![image](https://private-user-images.githubusercontent.com/69689387/410170619-926c064f-9246-4a50-97a0-a41deeca1146.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwODA3NzEsIm5iZiI6MTczOTA4MDQ3MSwicGF0aCI6Ii82OTY4OTM4Ny80MTAxNzA2MTktOTI2YzA2NGYtOTI0Ni00YTUwLTk3YTAtYTQxZGVlY2ExMTQ2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA1NTQzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJiMDRkODNjYzExZDNhZTk4MWZmZGVmMDdiY2JmOGVjNzMxZGEyMDdjYzg5ZDI3YzEzNWI5N2ZlN2FiNTVmODQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.r6dFTezM2b6YygEHdc7r55eHa0mz_ASLY_sqoPaVYXo)
- With coverage annotation :
![image](https://private-user-images.githubusercontent.com/69689387/410170176-efb4369b-d8ea-4ee0-92f3-600baa69fea7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwODA3NzEsIm5iZiI6MTczOTA4MDQ3MSwicGF0aCI6Ii82OTY4OTM4Ny80MTAxNzAxNzYtZWZiNDM2OWItZDhlYS00ZWUwLTkyZjMtNjAwYmFhNjlmZWE3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA1NTQzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTM1NjFlNDFjOTRhMzlhNjcwOGE4Yzc0ZDViODFlOTI0MmNmMzdlZDk1NGYxZjMzN2M1YWMzNTRjNzJkNWY4ZTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.6P5IiCm9bCWO4xTJqTwMHQ4aQnUvE7MrWCP5PxMsFlI)
![image](https://private-user-images.githubusercontent.com/69689387/410170373-5ef2c3b6-b2ab-430e-9500-cde5229d0b1c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwODA3NzEsIm5iZiI6MTczOTA4MDQ3MSwicGF0aCI6Ii82OTY4OTM4Ny80MTAxNzAzNzMtNWVmMmMzYjYtYjJhYi00MzBlLTk1MDAtY2RlNTIyOWQwYjFjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA1NTQzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRlMjYwZDBmMzY1ODVmNmZjNWY2ZGVhZjhkNzk5YjNkZDRmZDdjZjQxNDFlNGIzYmIzYmMwZmE5NzQwMzZkOTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.v1yUezmVMSH3t3OsUaLM2-qIH_bvix4l6WW_9Bp47fY)
cc : @westonruter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange. I don't know why that would be.
Nevertheless, I see that the test_plsr_sanitize_setting()
test is already covering plsr_sanitize_setting
. Therefore, do we even need this test_sanitize_setting
test? Should its test cases not be put into the data_plsr_sanitize_setting
data provider?
In performance/plugins/speculation-rules/uninstall.php Lines 9 to 12 in 68c6deb
Can be updated to follow Optimization Detective to add the performance/plugins/optimization-detective/uninstall.php Lines 9 to 12 in 68c6deb
|
* @covers ::plsr_get_setting_default | ||
* @covers ::plsr_register_setting | ||
*/ | ||
public function test_register_settings(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think better name this test_plsr_register_setting
in accordance with the primary method it tests.
public function test_register_settings(): void { | |
public function test_plsr_register_setting(): void { |
public function test_register_settings(): void { | ||
plsr_register_setting(); | ||
$settings = plsr_get_setting_default(); | ||
$this->assertArrayHasKey( 'mode', $settings ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we check this, we should probably also check for the eagerness
key.
$this->assertArrayHasKey( 'mode', $settings ); | |
$this->assertArrayHasKey( 'mode', $settings ); | |
$this->assertArrayHasKey( 'eagerness', $settings ); | |
/** | ||
* Function to test sanitize_setting() with various inputs. | ||
*/ | ||
public function test_sanitize_setting(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above:
public function test_sanitize_setting(): void { | |
public function test_plsr_sanitize_setting(): void { |
/** | ||
* @covers ::plsr_add_setting_ui | ||
*/ | ||
public function test_add_setting_ui(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function test_add_setting_ui(): void { | |
public function test_plsr_add_setting_ui(): void { |
plugins/speculation-rules/tests/test-speculation-rules-settings.php
Outdated
Show resolved
Hide resolved
@@ -29,8 +29,6 @@ private function require_uninstall(): void { | |||
|
|||
/** | |||
* Test option deletion. | |||
* | |||
* @covers ::plsr_delete_plugin_option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this? The function is located in uninstall.php
so when that file is being required, then that function is indeed being loaded and executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned here #1845 (comment)
for some functions adding @Covers annotation is reducing code coverage and exactly why it's happening is still not known. I thought it might be a case where some functions are not accessible (private or protected) but tested that as well, it's happening for public functions as well.
Without adding @covers ::plsr_delete_plugin_option
![image](https://private-user-images.githubusercontent.com/69689387/410362059-8eac2f66-a81d-4e34-a3a9-a5be8c696a2b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwODA3NzEsIm5iZiI6MTczOTA4MDQ3MSwicGF0aCI6Ii82OTY4OTM4Ny80MTAzNjIwNTktOGVhYzJmNjYtYTgxZC00ZTM0LWEzYTktYTViZThjNjk2YTJiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA1NTQzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ4ZmUyYzUyM2M2YzBiZWY3OTA1ODk4NjFhZDRlZmM0ODk1MTY2ZjYyNzc0ZWYxYTJmMmM5YzMyOTYzMWY3ZTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.cHp59v1nIPJAEXyqOaqvYUwuvQOBlrFlSOWdYyRz0Iw)
![image](https://private-user-images.githubusercontent.com/69689387/410362208-7f7aa1f0-dc86-4511-aabd-30a6448d39fc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwODA3NzEsIm5iZiI6MTczOTA4MDQ3MSwicGF0aCI6Ii82OTY4OTM4Ny80MTAzNjIyMDgtN2Y3YWExZjAtZGM4Ni00NTExLWFhYmQtMzBhNjQ0OGQzOWZjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA1NTQzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNmZWNkYmQzMWE1M2RjN2UzNjg5OWRhZmFhNWUyODJlYjQ2NzYwYmEwNTM1ZjZlN2UwMzY1OThkOTkxMmY4MDMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.qsnFqs3G-6ezuvoHp1CsEDwHwEjjR0fQkIbpaeV6tFY)
After adding @covers ::plsr_delete_plugin_option
![image](https://private-user-images.githubusercontent.com/69689387/410362545-c18252ab-258d-4485-a0d1-8b2093a3d4e3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwODA3NzEsIm5iZiI6MTczOTA4MDQ3MSwicGF0aCI6Ii82OTY4OTM4Ny80MTAzNjI1NDUtYzE4MjUyYWItMjU4ZC00NDg1LWEwZDEtOGIyMDkzYTNkNGUzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA1NTQzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWUxOWNjOTAxNTZlODBkYzI3Yzg3Yjg4ODA2NWFkYjgxMGJmZGUwZjY1YjBiMzM3NDYwZmUxMjEwNzE2OTk5MTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.oYvShmJthAH7wWkQVE_EqfRlAyKcVcop9zvr_jyyhlc)
![image](https://private-user-images.githubusercontent.com/69689387/410362622-cf43317b-f5f7-413b-bdff-52f63d283ff7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwODA3NzEsIm5iZiI6MTczOTA4MDQ3MSwicGF0aCI6Ii82OTY4OTM4Ny80MTAzNjI2MjItY2Y0MzMxN2ItZjVmNy00MTNiLWJkZmYtNTJmNjNkMjgzZmY3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA1NTQzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZhMzA3OGE3NDRmNmQyZThhNDliOWE3NmNhMThhNmJkNDBhNjk0MzdiNTUwOGI1Yzc3ZDdmNTg1MDNjNzcwZTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Z_v33pwExpL48Lblr0usTD8MhDWs7HrN2O-Nef5QWN0)
cc : @westonruter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange!
Summary
This is part of #1789:
@covers
Annotationscc : @westonruter