Skip to content

feat: add unit tests#670

Open
rosinghal wants to merge 6 commits intomainfrom
rohit/neighbouring-quelea
Open

feat: add unit tests#670
rosinghal wants to merge 6 commits intomainfrom
rohit/neighbouring-quelea

Conversation

@rosinghal
Copy link
Copy Markdown
Member

@rosinghal rosinghal commented Apr 15, 2026

Summary by CodeRabbit

  • Chores
    • Added testing infrastructure including continuous integration pipeline configuration, development dependencies, and unit test suites.

@rosinghal rosinghal requested review from Akhill2020 and enginnk April 15, 2026 07:11
@rosinghal rosinghal self-assigned this Apr 15, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

Warning

Rate limit exceeded

@rosinghal has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 6 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 2 minutes and 6 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c670e046-663d-4ef5-9edc-cfc925f9c47d

📥 Commits

Reviewing files that changed from the base of the PR and between 6f96092 and 8a4eb08.

📒 Files selected for processing (11)
  • phpunit.xml.dist
  • tests/Unit/Events/EventBuilderLimitWordsTest.php
  • tests/Unit/Events/EventTest.php
  • tests/Unit/Events/EventsCollectionTest.php
  • tests/Unit/Functions/AdminFunctionsTest.php
  • tests/Unit/Functions/SharedFunctionsTest.php
  • tests/Unit/ObjectsTest.php
  • tests/Unit/Requirements/WpRequirementsTest.php
  • tests/Unit/TestCase.php
  • tests/bootstrap.php
  • tests/wp-stubs.php
📝 Walkthrough

Walkthrough

The PR introduces comprehensive test infrastructure for the SimpleCalendar project, including PHPUnit configuration, a WordPress-compatible base test class using Brain Monkey for function stubbing, test bootstrap setup, and unit test suites for the Event class, shared utility functions, and Objects initialization logic.

Changes

Cohort / File(s) Summary
CI & Build Configuration
.github/workflows/build.yml, .gitignore, composer.json
Added GitHub Actions test job that runs PHPUnit with PHP 8.1 and Guzzle stubs. Updated .gitignore to exclude PHPUnit cache. Extended composer.json with test script, test autoload path (tests/), and dev dependencies (phpunit, brain/monkey, mockery).
Test Framework Setup
tests/bootstrap.php, tests/unit/TestCase.php
Added test environment bootstrap defining constants (ABSPATH, version, paths) and loading autoloaders. Created abstract base test class with Brain Monkey initialization and WordPress function stubs for esc_attr, esc_html, esc_url_raw, wp_kses_post, absint, sanitize_title, and __.
Unit Test Suites
tests/unit/Events/EventTest.php, tests/unit/Functions/SharedFunctionsTest.php, tests/unit/ObjectsTest.php
Added 36 test methods for Event class constructor, properties, timezone handling, and getters. Added 15 test methods for shared utility functions (timezone escaping, GMT offset parsing, date format ordering). Added 8 test methods for Objects class name generation across different object types using reflection.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 With twitching nose and careful paw,
We test each hop without a flaw,
EventTest hops, SharedFunctions flow,
Objects dance with Bootstrap's glow!
PHPUnit's magic, Brain Monkey's jest,
Our SimpleCalendar passes the test! 🌙✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add unit tests' directly and accurately describes the main change: introducing a comprehensive unit test suite across multiple test files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rohit/neighbouring-quelea

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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 (2)
.github/workflows/build.yml (1)

21-22: Prefer the Composer script as the CI test entrypoint.

Using composer test here keeps local and CI execution paths aligned with composer.json.

Suggested tweak
       - name: Run unit tests
-        run: vendor/bin/phpunit
+        run: composer test
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/build.yml around lines 21 - 22, Replace the direct PHPUnit
invocation in the "Run unit tests" step (currently running vendor/bin/phpunit)
with the Composer script entrypoint by calling composer test so CI uses the same
test command as local runs; update the run command from vendor/bin/phpunit to
composer test and ensure the composer.json "test" script exists and invokes
phpunit (adjust the step name only if desired).
tests/unit/Events/EventTest.php (1)

23-27: Use fixed timestamps in defaults for deterministic fixtures.

Using multiple Carbon::now() calls in Line 23-Line 27 can introduce subtle, time-dependent fixture variance. A fixed epoch in the default payload keeps tests fully repeatable.

Suggested tweak
-            'start' => Carbon::now('UTC')->getTimestamp(),
-            'start_utc' => Carbon::now('UTC')->getTimestamp(),
+            'start' => 1700000000,
+            'start_utc' => 1700000000,
             'start_timezone' => 'America/New_York',
-            'end' => Carbon::now('UTC')->addHour()->getTimestamp(),
-            'end_utc' => Carbon::now('UTC')->addHour()->getTimestamp(),
+            'end' => 1700003600,
+            'end_utc' => 1700003600,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/Events/EventTest.php` around lines 23 - 27, The default fixture
uses multiple Carbon::now() calls for the 'start', 'start_utc',
'start_timezone', 'end', and 'end_utc' keys in EventTest which makes tests
time-dependent; replace the dynamic Carbon::now() calls with a single fixed
epoch (e.g. a constant timestamp or a fixed Carbon created from a literal) and
compute both start and end from that fixed value (end = start + 3600) so the
payload in EventTest is deterministic and repeatable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/build.yml:
- Around line 15-20: The CI step "Create guzzle function stubs" is overwriting
files under vendor/, which hides real dependency/autoload issues; instead stop
writing into vendor/ and place any test stubs under the repository (e.g.,
tests/mocks or phpunit bootstrap) and load them via composer autoload-dev or
your test bootstrap. Remove the commands that create vendor/guzzlehttp/... files
from the workflow, create the stub file(s) in a non-vendor path (referenced as
tests/mocks/functions_include.php), and ensure composer.json's autoload-dev or
your test bootstrap requires that path so tests run without modifying vendor.
Use this change to preserve real install behavior and surface missing
dependency/autoload problems.

In `@tests/bootstrap.php`:
- Line 3: The tests/bootstrap.php file unconditionally defines the ABSPATH
constant which can trigger "already defined" warnings; wrap the definition in a
guard that checks defined('ABSPATH') before calling define so ABSPATH is only
set when not already present (replace the current define('ABSPATH',
'/tmp/fake-wp/'); with an if (!defined('ABSPATH')) { define('ABSPATH',
'/tmp/fake-wp/'); } pattern to avoid redefinition warnings).

---

Nitpick comments:
In @.github/workflows/build.yml:
- Around line 21-22: Replace the direct PHPUnit invocation in the "Run unit
tests" step (currently running vendor/bin/phpunit) with the Composer script
entrypoint by calling composer test so CI uses the same test command as local
runs; update the run command from vendor/bin/phpunit to composer test and ensure
the composer.json "test" script exists and invokes phpunit (adjust the step name
only if desired).

In `@tests/unit/Events/EventTest.php`:
- Around line 23-27: The default fixture uses multiple Carbon::now() calls for
the 'start', 'start_utc', 'start_timezone', 'end', and 'end_utc' keys in
EventTest which makes tests time-dependent; replace the dynamic Carbon::now()
calls with a single fixed epoch (e.g. a constant timestamp or a fixed Carbon
created from a literal) and compute both start and end from that fixed value
(end = start + 3600) so the payload in EventTest is deterministic and
repeatable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b87c3bb5-3a43-43be-85e8-d7c518234e86

📥 Commits

Reviewing files that changed from the base of the PR and between 1c78ce0 and 6f96092.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • .github/workflows/build.yml
  • .gitignore
  • composer.json
  • tests/bootstrap.php
  • tests/unit/Events/EventTest.php
  • tests/unit/Functions/SharedFunctionsTest.php
  • tests/unit/ObjectsTest.php
  • tests/unit/TestCase.php

Comment on lines +15 to +20
- name: Create guzzle function stubs
run: |
mkdir -p vendor/guzzlehttp/guzzle/src
echo '<?php' > vendor/guzzlehttp/guzzle/src/functions_include.php
mkdir -p vendor/guzzlehttp/promises/src
echo '<?php' > vendor/guzzlehttp/promises/src/functions_include.php
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid overwriting dependency files in CI setup.

Lines 17-20 currently overwrite files in vendor/, which can mask autoload/dependency problems and make test behavior diverge from real installs.

Suggested safe change
       - name: Create guzzle function stubs
         run: |
           mkdir -p vendor/guzzlehttp/guzzle/src
-          echo '<?php' > vendor/guzzlehttp/guzzle/src/functions_include.php
+          [ -f vendor/guzzlehttp/guzzle/src/functions_include.php ] || printf '%s\n' '<?php' > vendor/guzzlehttp/guzzle/src/functions_include.php
           mkdir -p vendor/guzzlehttp/promises/src
-          echo '<?php' > vendor/guzzlehttp/promises/src/functions_include.php
+          [ -f vendor/guzzlehttp/promises/src/functions_include.php ] || printf '%s\n' '<?php' > vendor/guzzlehttp/promises/src/functions_include.php
📝 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
- name: Create guzzle function stubs
run: |
mkdir -p vendor/guzzlehttp/guzzle/src
echo '<?php' > vendor/guzzlehttp/guzzle/src/functions_include.php
mkdir -p vendor/guzzlehttp/promises/src
echo '<?php' > vendor/guzzlehttp/promises/src/functions_include.php
- name: Create guzzle function stubs
run: |
mkdir -p vendor/guzzlehttp/guzzle/src
[ -f vendor/guzzlehttp/guzzle/src/functions_include.php ] || printf '%s\n' '<?php' > vendor/guzzlehttp/guzzle/src/functions_include.php
mkdir -p vendor/guzzlehttp/promises/src
[ -f vendor/guzzlehttp/promises/src/functions_include.php ] || printf '%s\n' '<?php' > vendor/guzzlehttp/promises/src/functions_include.php
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/build.yml around lines 15 - 20, The CI step "Create guzzle
function stubs" is overwriting files under vendor/, which hides real
dependency/autoload issues; instead stop writing into vendor/ and place any test
stubs under the repository (e.g., tests/mocks or phpunit bootstrap) and load
them via composer autoload-dev or your test bootstrap. Remove the commands that
create vendor/guzzlehttp/... files from the workflow, create the stub file(s) in
a non-vendor path (referenced as tests/mocks/functions_include.php), and ensure
composer.json's autoload-dev or your test bootstrap requires that path so tests
run without modifying vendor. Use this change to preserve real install behavior
and surface missing dependency/autoload problems.

Comment thread tests/bootstrap.php
@@ -0,0 +1,28 @@
<?php

define('ABSPATH', '/tmp/fake-wp/');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Guard ABSPATH before defining it.

Line 3 can raise “already defined” warnings in shared/embedded test runners.

Suggested fix
-define('ABSPATH', '/tmp/fake-wp/');
+if (!defined('ABSPATH')) {
+    define('ABSPATH', '/tmp/fake-wp/');
+}
📝 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
define('ABSPATH', '/tmp/fake-wp/');
if (!defined('ABSPATH')) {
define('ABSPATH', '/tmp/fake-wp/');
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/bootstrap.php` at line 3, The tests/bootstrap.php file unconditionally
defines the ABSPATH constant which can trigger "already defined" warnings; wrap
the definition in a guard that checks defined('ABSPATH') before calling define
so ABSPATH is only set when not already present (replace the current
define('ABSPATH', '/tmp/fake-wp/'); with an if (!defined('ABSPATH')) {
define('ABSPATH', '/tmp/fake-wp/'); } pattern to avoid redefinition warnings).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant