Skip to content

Conversation

@fogelito
Copy link
Contributor

@fogelito fogelito commented Aug 7, 2025

Summary by CodeRabbit

  • Tests
    • Improved and expanded test coverage for relationship data, ensuring attributes and nested relationships are correctly resolved and validated in various query scenarios.
    • Enhanced clarity of test variables for easier understanding and maintenance.
    • Removed unnecessary debug output for cleaner test results.

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 (1)
phpunit.xml (1)

10-10: Consider reverting stopOnFailure before merging

Setting stopOnFailure="true" is useful during local development for debugging specific test failures, but it may not be ideal for CI/CD pipelines where you want to see all test failures in a single run. Consider whether this change should be committed or kept as a local development configuration.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8ab3a7 and 7241f73.

📒 Files selected for processing (2)
  • phpunit.xml (1 hunks)
  • tests/e2e/Adapter/Scopes/RelationshipTests.php (8 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/e2e/Adapter/Scopes/RelationshipTests.php (4)
src/Database/Adapter.php (3)
  • createDocument (680-680)
  • getDocument (670-670)
  • count (805-805)
src/Database/Database.php (4)
  • createDocument (3580-3671)
  • getDocument (3193-3314)
  • count (6257-6293)
  • findOne (6228-6243)
src/Database/Document.php (3)
  • Document (12-462)
  • getId (63-66)
  • getAttribute (216-223)
src/Database/Query.php (4)
  • getAttribute (130-133)
  • Query (8-836)
  • equal (370-373)
  • select (515-518)
🪛 PHPMD (2.15.0)
tests/e2e/Adapter/Scopes/RelationshipTests.php

110-110: Avoid unused local variables such as '$iguana'. (Unused Code Rules)

(UnusedLocalVariable)


130-130: Avoid unused local variables such as '$tiger'. (Unused Code Rules)

(UnusedLocalVariable)


150-150: Avoid unused local variables such as '$lama'. (Unused Code Rules)

(UnusedLocalVariable)


189-189: Avoid unused local variables such as '$trump'. (Unused Code Rules)

(UnusedLocalVariable)


203-203: Avoid unused local variables such as '$bush'. (Unused Code Rules)

(UnusedLocalVariable)


214-214: Avoid unused local variables such as '$biden'. (Unused Code Rules)

(UnusedLocalVariable)

🔇 Additional comments (3)
tests/e2e/Adapter/Scopes/RelationshipTests.php (3)

98-109: Good improvements to test clarity and validation

The variable renaming from $zoo1 to $zoo improves readability, and the added assertions properly validate the document creation.


110-168: Excellent variable naming improvements

The descriptive variable names ($iguana, $tiger, $lama) make the test much more readable and intuitive compared to generic names like $animal1, $animal2, etc. The static analysis warnings about unused variables can be safely ignored as these documents are created and referenced by ID in subsequent assertions.


189-223: Clear and descriptive variable naming

The renamed variables ($trump, $bush, $biden) enhance test readability. These are appropriately used for document creation despite the static analysis warnings.

@utopia-php utopia-php deleted a comment from coderabbitai bot Aug 7, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

Walkthrough

The testZoo method in tests/e2e/Adapter/Scopes/RelationshipTests.php was updated with clearer variable names and extensive new assertions. These additions validate the integrity and correctness of relationships between zoo, animal, veterinarian, and president collections, including checks for nested relationships and selective attribute queries. Debug output was replaced by structured assertions. The populateDocumentRelationships method in src/Database/Database.php was modified to explicitly filter relationship attributes by type and respect selective attribute queries when populating relationships.

Changes

Cohort / File(s) Change Summary
RelationshipTests Enhancements
tests/e2e/Adapter/Scopes/RelationshipTests.php
Refactored variable names for clarity; added comprehensive assertions verifying relationship integrity, nested relationships, and selective attribute queries within the testZoo method; removed debug output.
Database Relationship Population Refinement
src/Database/Database.php
Modified populateDocumentRelationships to replace array_filter with an explicit loop filtering by relationship attribute type; added logic to include only selected relationship attributes or all if none selected.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant ZooCollection
    participant AnimalCollection
    participant VeterinarianCollection
    participant PresidentCollection
    participant Database

    TestRunner->>ZooCollection: Create zoo document
    TestRunner->>AnimalCollection: Create iguana, tiger, lama documents (linked to zoo)
    TestRunner->>VeterinarianCollection: Create veterinarians (linked to animals, presidents)
    TestRunner->>PresidentCollection: Create presidents (linked to animals, veterinarians)
    TestRunner->>Database: Query zoo with relationships and selects
    Database-->>TestRunner: Return zoo with related animals (filtered by selects)
    Database-->>TestRunner: Return animals with related veterinarians and presidents
    Database-->>TestRunner: Return veterinarians with related presidents and animals
    Database-->>TestRunner: Return presidents with related animals and votes
    TestRunner->>TestRunner: Assert relationship and attribute integrity
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • abnegate

Poem

In the zoo of code, where tests now roam, \
Relationships checked in their data home. \
Iguanas and tigers, presidents in tow, \
Assertions abound, as connections grow. \
With clarity and rigor, our logic stands tall— \
A rabbit’s delight in testing it all! 🐇

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch zoo-relations-tests

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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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.

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: 0

♻️ Duplicate comments (1)
tests/e2e/Adapter/Scopes/RelationshipTests.php (1)

322-377: Excellent selective query testing with one unresolved comment

This is sophisticated testing of relationship query selection that properly validates:

  • Basic * select behavior (no relationship resolution)
  • Partial relationship selection (animals.*)
  • Nested relationship resolution (animals.president.*)

However, the commented assertion on line 347 still needs attention as flagged in previous reviews.

Action Required: Please address the commented assertion:

//$this->assertArrayNotHasKey('presidents', $veterinarian); // ???

Either uncomment it if the check is valid, remove it if not needed, or add a clear comment explaining why it's intentionally omitted.

🧹 Nitpick comments (2)
tests/e2e/Adapter/Scopes/RelationshipTests.php (2)

110-167: Excellent variable naming improvements

The rename from generic $animal1/$animal2/$animal3 to descriptive $iguana/$tiger/$lama significantly improves test readability and makes the test structure much clearer.

Note: While static analysis flags these as unused variables, they serve as clear documentation of the test data structure and could be valuable for debugging. Consider if you want to keep them for clarity or remove them to satisfy static analysis.


189-223: Clear and descriptive variable naming

The rename from generic $president1/$president2/$president3 to specific $trump/$bush/$biden makes the test much more readable and easier to follow.

Same note as with the animal variables - these are flagged as unused but serve as useful documentation of the test data structure.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7241f73 and 3e0cc09.

📒 Files selected for processing (1)
  • tests/e2e/Adapter/Scopes/RelationshipTests.php (8 hunks)
🧰 Additional context used
🪛 PHPMD (2.15.0)
tests/e2e/Adapter/Scopes/RelationshipTests.php

110-110: Avoid unused local variables such as '$iguana'. (Unused Code Rules)

(UnusedLocalVariable)


130-130: Avoid unused local variables such as '$tiger'. (Unused Code Rules)

(UnusedLocalVariable)


150-150: Avoid unused local variables such as '$lama'. (Unused Code Rules)

(UnusedLocalVariable)


189-189: Avoid unused local variables such as '$trump'. (Unused Code Rules)

(UnusedLocalVariable)


203-203: Avoid unused local variables such as '$bush'. (Unused Code Rules)

(UnusedLocalVariable)


214-214: Avoid unused local variables such as '$biden'. (Unused Code Rules)

(UnusedLocalVariable)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Adapter Tests (SharedTables/MariaDB)
  • GitHub Check: Adapter Tests (Pool)
  • GitHub Check: Adapter Tests (SharedTables/SQLite)
  • GitHub Check: Adapter Tests (SharedTables/Postgres)
  • GitHub Check: Adapter Tests (SQLite)
  • GitHub Check: Adapter Tests (Postgres)
  • GitHub Check: Adapter Tests (Mirror)
  • GitHub Check: Adapter Tests (SharedTables/MySQL)
  • GitHub Check: Adapter Tests (MySQL)
  • GitHub Check: Adapter Tests (MariaDB)
🔇 Additional comments (5)
tests/e2e/Adapter/Scopes/RelationshipTests.php (5)

98-109: LGTM! Good variable naming and immediate verification

The variable rename from $zoo1 to $zoo improves readability, and adding immediate assertions after document creation is excellent practice for verifying the operation succeeded and the document has expected relationship attributes.


225-245: Comprehensive zoo data validation

Excellent test coverage that validates document structure, relationship attributes, proper counts, and nested relationships. Testing both getDocument() and findOne() methods ensures comprehensive coverage of different retrieval patterns.


246-272: Thorough veterinarian relationship validation

Well-structured assertions that validate the bidirectional relationships (presidents and animals) and ensure nested relationship attributes are properly populated. Good coverage of the complex relationship structure.


273-299: Complete animal relationship validation

Excellent validation of animal documents ensuring all relationship attributes (zoo, veterinarian, president) are properly populated and accessible. The nested attribute checks confirm the relationship data integrity.


300-321: Solid president relationship testing

Good validation of president documents covering both animal relationships and voting relationships with veterinarians. Testing different vote counts (2 vs 0) ensures the relationships work correctly across various scenarios.

@fogelito fogelito requested a review from abnegate August 7, 2025 15:18
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: 1

🧹 Nitpick comments (2)
src/Database/Database.php (1)

3327-3335: Selective relationship resolution looks good; consider a small robustness tweak

The explicit loop that filters only relationship attributes and respects nested selections aligns with how processRelationshipQueries() builds $selects. This avoids unnecessary fetches and matches the new tests.

Optionally, to be defensive against metadata inconsistencies, fall back to '$id' when key is absent:

-        foreach ($attributes as $attribute) {
-            if ($attribute['type'] === Database::VAR_RELATIONSHIP) {
-                if (empty($selects) || array_key_exists($attribute['key'], $selects)) {
-                    $relationships[] = $attribute;
-                }
-            }
-        }
+        foreach ($attributes as $attribute) {
+            if ($attribute['type'] !== Database::VAR_RELATIONSHIP) {
+                continue;
+            }
+            $attrKey = $attribute['key'] ?? $attribute['$id'] ?? null;
+            if ($attrKey === null) {
+                continue;
+            }
+            if (empty($selects) || array_key_exists($attrKey, $selects)) {
+                $relationships[] = $attribute;
+            }
+        }
tests/e2e/Adapter/Scopes/RelationshipTests.php (1)

110-128: Clean up unused locals flagged by static analysis

The return values are not used; keep the side effects by dropping the assignments:

-        $iguana = $database->createDocument('__animals', new Document([
+        $database->createDocument('__animals', new Document([
             ... 
         ]));
 
-        $tiger = $database->createDocument('__animals', new Document([
+        $database->createDocument('__animals', new Document([
             ...
         ]));
 
-        $lama = $database->createDocument('__animals', new Document([
+        $database->createDocument('__animals', new Document([
             ...
         ]));
 
-        $trump = $database->createDocument('presidents', new Document([
+        $database->createDocument('presidents', new Document([
             ...
         ]));
 
-        $bush = $database->createDocument('presidents', new Document([
+        $database->createDocument('presidents', new Document([
             ...
         ]));
 
-        $biden = $database->createDocument('presidents', new Document([
+        $database->createDocument('presidents', new Document([
             ...
         ]));

This addresses PHPMD “UnusedLocalVariable” hints without altering behavior. If you prefer to keep the names for readability, prefix with _ to signal intentional non-use.

Also applies to: 130-148, 150-167, 189-201, 203-213, 214-223

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e0cc09 and 9514f56.

📒 Files selected for processing (2)
  • src/Database/Database.php (1 hunks)
  • tests/e2e/Adapter/Scopes/RelationshipTests.php (8 hunks)
🧰 Additional context used
🪛 PHPMD (2.15.0)
tests/e2e/Adapter/Scopes/RelationshipTests.php

110-110: Avoid unused local variables such as '$iguana'. (Unused Code Rules)

(UnusedLocalVariable)


130-130: Avoid unused local variables such as '$tiger'. (Unused Code Rules)

(UnusedLocalVariable)


150-150: Avoid unused local variables such as '$lama'. (Unused Code Rules)

(UnusedLocalVariable)


189-189: Avoid unused local variables such as '$trump'. (Unused Code Rules)

(UnusedLocalVariable)


203-203: Avoid unused local variables such as '$bush'. (Unused Code Rules)

(UnusedLocalVariable)


214-214: Avoid unused local variables such as '$biden'. (Unused Code Rules)

(UnusedLocalVariable)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Adapter Tests (SharedTables/SQLite)
  • GitHub Check: Adapter Tests (SharedTables/Postgres)
  • GitHub Check: Adapter Tests (Mirror)
  • GitHub Check: Adapter Tests (SharedTables/MySQL)
  • GitHub Check: Adapter Tests (SharedTables/MariaDB)
  • GitHub Check: Adapter Tests (Pool)
  • GitHub Check: Adapter Tests (SQLite)
  • GitHub Check: Adapter Tests (Postgres)
  • GitHub Check: Adapter Tests (MariaDB)
  • GitHub Check: Adapter Tests (MySQL)

@abnegate abnegate merged commit d78413f into main Aug 11, 2025
15 checks passed
@abnegate abnegate deleted the zoo-relations-tests branch August 11, 2025 05:24
@coderabbitai coderabbitai bot mentioned this pull request Nov 24, 2025
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.

3 participants