Skip to content

chore: Add PHPUnit check to CI workflow #2780

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

shohag121
Copy link
Member

@shohag121 shohag121 commented Jul 1, 2025

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

Closes

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

No change log needed.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • New Features

    • Added WordPress development environment configuration for easier local setup.
    • Introduced new npm scripts for managing the WordPress environment and running PHP unit tests.
    • Expanded support for UI components, drag-and-drop functionality, and WordPress API integration through new dependencies.
  • Chores

    • Enhanced automated testing workflows to include Node.js build steps and integrated PHP/WordPress testing.
    • Updated and reorganized development dependencies for improved consistency.

Copy link
Contributor

coderabbitai bot commented Jul 1, 2025

Walkthrough

The updates introduce a new .wp-env.json configuration for WordPress development, expand package.json with new scripts and dependencies for environment management and testing, and enhance the GitHub Actions workflow to set up Node.js, build assets, start a WordPress environment, and run PHPUnit tests as part of the CI process.

Changes

File(s) Change Summary
.github/workflows/phpcs.yml Extended workflow: adds Node.js setup, runs npm install, npm run build, starts WP env, and runs PHPUnit.
.wp-env.json New file: configures WordPress dev environment (PHP 7.4, plugins, WooCommerce).
package.json Adds WP env/testing scripts, updates devDependencies, adds new dependencies for WP and UI, removes duplicates.

Sequence Diagram(s)

sequenceDiagram
    participant GitHub Actions
    participant Node.js
    participant npm
    participant PHP
    participant WP Env
    participant PHPUnit

    GitHub Actions->>Node.js: Setup Node.js v20
    GitHub Actions->>npm: npm install
    GitHub Actions->>npm: npm run build
    GitHub Actions->>PHP: Setup PHP
    GitHub Actions->>npm: npm run phpcs
    GitHub Actions->>WP Env: npm run env:start
    GitHub Actions->>PHPUnit: npm run phpunit
Loading

Assessment against linked issues

Objective Addressed Explanation
Add PHPUnit to GitHub Actions workflow (#624)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Addition of multiple UI and WordPress API dependencies in package.json (lines: dependencies section) These new dependencies are not directly related to the objective of adding PHPUnit to the workflow.
Addition of new npm scripts for WP environment management in package.json (scripts section) These scripts support environment management, which is adjacent but not strictly required for PHPUnit integration.
Introduction of .wp-env.json for WP environment configuration This file supports the test environment but is not explicitly required by the objective.

Suggested labels

QA approved, :+1: Dev Review Done

Suggested reviewers

  • mrabbani

Poem

A bunny hops through code so bright,
With PHPUnit now in the light.
WordPress spins with Woo in tow,
New scripts and builds begin to grow.
CI now checks with every run—
This rabbit’s work is never done!
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
.github/workflows/phpcs.yml (2)

11-21: Use npm ci for reproducible installs & faster caching.

npm i ignores the lock-file’s exact versions and is slower.
npm ci is purpose-built for CI, guarantees deterministic installs, and works seamlessly with setup-node’s built-in cache.

-      - name: Npm install and build
-        run: |
-            npm i
-            npm run build
+      - name: Install deps & build
+        run: |
+            npm ci
+            npm run build

52-58: Gracefully shut down Docker containers at job end.

wp-env start leaves containers running until the runner is torn down. While the runner is ephemeral, a tidy shutdown avoids stray logs, eases local reuse of the workflow, and prepares for potential parallel jobs.

       - name: Running the phpunit tests
         run: |
             npm run phpunit
+
+      - name: Stop WordPress Environment
+        if: always()
+        run: |
+            npm run env:stop
package.json (2)

22-29: test:phpunit script can race if wp-env start is still booting.

wp-env start returns immediately once Docker compose is up, but WP may not yet respond to CLI commands, causing flaky runs locally.
Add --wait=60 (or similar) to ensure the environment is ready before invoking PHPUnit.

-    "test:phpunit": "wp-env start && npm run phpunit && wp-env stop"
+    "test:phpunit": "wp-env start --wait=60 && npm run phpunit && wp-env stop"

27-28: Quoting the PHPUnit path improves cross-platform safety.

Paths containing hyphens or spaces can break when parsed by the shell. Wrapping the path guards against that.

-    "phpunit": "wp-env run cli --env-cwd=wp-content/plugins/dokan vendor/bin/phpunit -c phpunit.xml",
+    "phpunit": "wp-env run cli --env-cwd=wp-content/plugins/dokan \"vendor/bin/phpunit\" -c phpunit.xml",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97b88e3 and ecbf952.

📒 Files selected for processing (3)
  • .github/workflows/phpcs.yml (2 hunks)
  • .wp-env.json (1 hunks)
  • package.json (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: api tests (1, 1)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: e2e tests (1, 3)
  • GitHub Check: Run PHPCS inspection
🔇 Additional comments (1)
.wp-env.json (1)

3-3: Re-evaluate the PHP 7.4 requirement.

WordPress currently recommends PHP 8.1+. Running tests on an EOL PHP version diminishes coverage for supported stacks and loses out on performance/security improvements.
If Dokan still supports 7.4, add a matrix to run against both 7.4 and 8.1; otherwise bump this value.

Comment on lines +2 to +4
"core": null,
"phpVersion": "7.4",
"plugins": [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Pin WordPress Core to a deterministic version.

Leaving "core": null implicitly pulls the latest nightly build every time the workflow runs, which may introduce breaking changes outside your control.
Consider locking to the latest stable (e.g. "core": "6.5"), or at least "core": "latest" to stay on stable releases.

-  "core": null,
+  "core": "latest",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"core": null,
"phpVersion": "7.4",
"plugins": [
"core": "latest",
"phpVersion": "7.4",
"plugins": [
🤖 Prompt for AI Agents
In the .wp-env.json file around lines 2 to 4, the "core" property is set to
null, which causes the environment to pull the latest nightly WordPress build on
each run. To fix this, replace null with a specific stable version string like
"6.5" or "latest" to ensure the environment uses a deterministic and stable
WordPress core version.

Comment on lines +51 to 52
"tailwind-merge": "^2.6.0",
"tailwindcss": "^3.3.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove the duplicated tailwind-merge entry to avoid version conflicts.

The package exists in both devDependencies (^2.6.0) and dependencies (^2.5.5). NPM will dedupe, but the older prod-level entry may override the newer dev version, leading to subtle build issues.

-    "tailwind-merge": "^2.5.5",

Also applies to: 102-102

🤖 Prompt for AI Agents
In package.json around lines 51-52 and line 102, remove the duplicated
"tailwind-merge" entry from either devDependencies or dependencies to avoid
version conflicts. Keep only one entry with the desired version (preferably the
newer "^2.6.0") and delete the other to ensure consistent package resolution and
prevent subtle build issues.

@shohag121 shohag121 self-assigned this Jul 1, 2025
@shohag121 shohag121 added Needs: Testing This requires further testing Needs: Dev Review It requires a developer review and approval labels Jul 1, 2025
@shohag121 shohag121 requested a review from mrabbani July 1, 2025 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Dev Review It requires a developer review and approval Needs: Testing This requires further testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant