Guard EDAC_KEY_VALID usage in options page#1402
Guard EDAC_KEY_VALID usage in options page#1402SteveJonesDev wants to merge 1 commit intodevelopfrom
Conversation
Summary of ChangesHello @SteveJonesDev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the robustness of the options page by preventing potential PHP errors related to an undefined constant. It ensures that the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
WalkthroughA PHP notice prevention was implemented by guarding the EDAC_KEY_VALID constant check with a defined() condition, and a corresponding test was added to verify the guard is in place within the source code. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request correctly guards the usage of the EDAC_KEY_VALID constant with a defined() check to prevent errors when the file is loaded in different contexts. It also introduces a new test to ensure this guard remains in place. The changes are logical and improve the robustness of the code. I've added one suggestion to improve the new test by making it less brittle to future formatting changes.
| $this->assertStringContainsString( | ||
| "defined( 'EDAC_KEY_VALID' ) && false === EDAC_KEY_VALID", | ||
| $source | ||
| ); |
There was a problem hiding this comment.
While assertStringContainsString works, it makes this test brittle. Any minor formatting change to the condition in the source code (like adding or removing whitespace) will cause this test to fail. Using assertMatchesRegularExpression with a regular expression that allows for whitespace variations will make the test more robust and less likely to fail on trivial formatting changes. You can replace the multi-line assertion with a single line for conciseness.
$this->assertMatchesRegularExpression("~defined\\(\\s*'EDAC_KEY_VALID'\\s*\\)\\s*&&\\s*false\\s*===\\s*EDAC_KEY_VALID~", $source);There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@tests/phpunit/includes/OptionsPageSourceTest.php`:
- Around line 1-12: The test class OptionsPageSourceTest is in the global
namespace and lacks the required edac_ prefix and
EqualizeDigital\AccessibilityChecker namespace; move the class into the
EqualizeDigital\AccessibilityChecker namespace and either import WP_UnitTestCase
with a use statement or fully qualify it, and rename the class to include the
edac_ prefix (e.g., edac_OptionsPageSourceTest) so it follows the
PSR-4/autoloading and global-prefix rules while keeping references to
WP_UnitTestCase intact.
| <?php | ||
| /** | ||
| * Tests for options-page source safety checks. | ||
| * | ||
| * @package Accessibility_Checker | ||
| */ | ||
|
|
||
| /** | ||
| * Verify options page source keeps EDAC_KEY_VALID usage guarded. | ||
| */ | ||
| class OptionsPageSourceTest extends WP_UnitTestCase { | ||
|
|
There was a problem hiding this comment.
Align the new test class with namespace/prefix guidelines.
This class is in the global namespace without the required edac_ prefix and doesn’t use the required EqualizeDigital\AccessibilityChecker namespace for new classes. Consider namespacing it (and importing WP_UnitTestCase) to satisfy both rules.
🔧 Suggested update
<?php
+namespace EqualizeDigital\AccessibilityChecker\Tests\PHPUnit\Includes;
+
+use WP_UnitTestCase;
/**
* Tests for options-page source safety checks.
*
* `@package` Accessibility_Checker
*/
@@
-class OptionsPageSourceTest extends WP_UnitTestCase {
+class OptionsPageSourceTest extends WP_UnitTestCase {As per coding guidelines, "Use PSR-4 autoloading with EqualizeDigital\AccessibilityChecker namespace for new classes" and "Prefix all functions and classes in global namespace with 'edac_'".
🤖 Prompt for AI Agents
In `@tests/phpunit/includes/OptionsPageSourceTest.php` around lines 1 - 12, The
test class OptionsPageSourceTest is in the global namespace and lacks the
required edac_ prefix and EqualizeDigital\AccessibilityChecker namespace; move
the class into the EqualizeDigital\AccessibilityChecker namespace and either
import WP_UnitTestCase with a use statement or fully qualify it, and rename the
class to include the edac_ prefix (e.g., edac_OptionsPageSourceTest) so it
follows the PSR-4/autoloading and global-prefix rules while keeping references
to WP_UnitTestCase intact.
Summary
EDAC_KEY_VALIDcheck inedac_post_types_cb()withdefined()to avoid undefined-constant errors when the file is loaded outside normal bootstrapOptionsPageSourceTestto lock in the constant guard at source levelTesting
php -l includes/options-page.phpphp -l tests/phpunit/includes/OptionsPageSourceTest.phpnpm run test:php(fails in this environment: Docker socket permission denied at/Users/stevejones/.docker/run/docker.sock)Risk
EDAC_KEY_VALIDis defined.Summary by CodeRabbit
Bug Fixes
Tests