-
Notifications
You must be signed in to change notification settings - Fork 55
Select nested relationships #643
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
Conversation
WalkthroughThis update refines relationship handling in the database logic by improving conditional checks, loop structures, and nested selection processing in Changes
Sequence Diagram(s)sequenceDiagram
participant TestRunner
participant Database
participant CollectionZoo
participant CollectionVeterinarians
participant CollectionPresidents
participant CollectionAnimals
TestRunner->>Database: Create collections (zoo, veterinarians, presidents, animals)
TestRunner->>Database: Define attributes and relationships
TestRunner->>Database: Insert documents with relationships
TestRunner->>Database: Query veterinarians with nested animals and zoos
Database->>CollectionVeterinarians: Fetch veterinarians
Database->>CollectionAnimals: Fetch related animals
Database->>CollectionZoo: Fetch related zoos for animals
Database-->>TestRunner: Return nested query result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ Finishing Touches
🧪 Generate unit 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 2
🧹 Nitpick comments (3)
tests/e2e/Adapter/Base.php (1)
6-12: Consider removing unused imports if traits are permanently disabled.If the commented-out traits (lines 20-24) are permanently disabled, these import statements should also be removed to keep the code clean and avoid confusion.
If the trait commenting is permanent, apply this diff to remove unused imports:
-use Tests\E2E\Adapter\Scopes\AttributeTests; -use Tests\E2E\Adapter\Scopes\CollectionTests; -use Tests\E2E\Adapter\Scopes\DocumentTests; -use Tests\E2E\Adapter\Scopes\IndexTests; -use Tests\E2E\Adapter\Scopes\PermissionTests;src/Database/Database.php (1)
3530-3530: Consider removing commented debug code.The commented
var_dump($queries)statement should be removed before merging to production to maintain code cleanliness, unless there's a specific reason to keep it for ongoing debugging purposes.- //var_dump($queries);tests/e2e/Adapter/Scopes/RelationshipTests.php (1)
222-222: Remove debug code before production.The
var_dumpstatement appears to be debugging code that should be removed.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/Database/Database.php(6 hunks)tests/e2e/Adapter/Base.php(1 hunks)tests/e2e/Adapter/Scopes/RelationshipTests.php(1 hunks)
🧰 Additional context used
🪛 PHPMD (2.15.0)
tests/e2e/Adapter/Scopes/RelationshipTests.php
107-107: Avoid unused local variables such as '$animal1'. (Unused Code Rules)
(UnusedLocalVariable)
127-127: Avoid unused local variables such as '$animal2'. (Unused Code Rules)
(UnusedLocalVariable)
147-147: Avoid unused local variables such as '$animal3'. (Unused Code Rules)
(UnusedLocalVariable)
186-186: Avoid unused local variables such as '$president1'. (Unused Code Rules)
(UnusedLocalVariable)
200-200: Avoid unused local variables such as '$president2'. (Unused Code Rules)
(UnusedLocalVariable)
211-211: Avoid unused local variables such as '$president3'. (Unused Code Rules)
(UnusedLocalVariable)
224-224: Avoid unused local variables such as '$docs'. (Unused Code Rules)
(UnusedLocalVariable)
🔇 Additional comments (4)
tests/e2e/Adapter/Base.php (1)
20-24: Clarify intent: temporary debugging or permanent test scope reduction?The trait imports are commented out rather than removed entirely, which suggests this might be temporary for debugging or development focus. However, this significantly reduces test coverage by excluding CollectionTests, DocumentTests, AttributeTests, IndexTests, and PermissionTests.
If this is temporary for debugging relationship functionality, please:
- Document this intent with a comment explaining why and when to re-enable
- Consider using a separate test configuration instead of modifying the base class
If this is a permanent change to focus only on relationship testing:
- Remove the commented imports entirely to avoid confusion
- Ensure other test suites cover the excluded functionality elsewhere
Could you clarify the intent behind this change?
src/Database/Database.php (3)
3286-3286: LGTM! Good defensive programming practice.The additional
!empty($relationships)check prevents unnecessary calls topopulateDocumentRelationshipswhen no relationships are defined, improving performance and code clarity. This change is consistent with the same pattern used later in thefindmethod.
6096-6096: LGTM! Consistent defensive programming.This change mirrors the improvement made in the
getDocumentmethod, maintaining consistency across the codebase by adding the same!empty($relationships)check before attempting to populate document relationships.
6807-6809: Excellent refactoring for performance and readability.This refactoring eliminates duplicate
explode('.', $value)calls by extracting the result into a$nestingvariable that's reused throughout the method. The changes provide:
- Performance improvement: Avoids multiple string parsing operations
- Code clarity: The
$nestingvariable name clearly indicates the dot-notation hierarchy- Maintainability: Single point of string parsing logic
- Better formatting: Added blank line improves code structure
The functionality remains identical while the implementation is more efficient.
Also applies to: 6822-6823, 6852-6852
| public function testZoo(): void | ||
| { | ||
| /** @var Database $database */ | ||
| $database = static::getDatabase(); | ||
|
|
||
| if (!$database->getAdapter()->getSupportForRelationships()) { | ||
| $this->expectNotToPerformAssertions(); | ||
| return; | ||
| } | ||
|
|
||
| $database->createCollection('zoo'); | ||
| $database->createAttribute('zoo', 'name', Database::VAR_STRING, 256, true); | ||
|
|
||
| $database->createCollection('veterinarians'); | ||
| $database->createAttribute('veterinarians', 'fullname', Database::VAR_STRING, 256, true); | ||
|
|
||
| $database->createCollection('presidents'); | ||
| $database->createAttribute('presidents', 'first_name', Database::VAR_STRING, 256, true); | ||
| $database->createAttribute('presidents', 'last_name', Database::VAR_STRING, 256, true); | ||
| $database->createRelationship( | ||
| collection: 'presidents', | ||
| relatedCollection: 'veterinarians', | ||
| type: Database::RELATION_MANY_TO_MANY, | ||
| twoWay: true, | ||
| id: 'votes', | ||
| twoWayKey: 'presidents' | ||
| ); | ||
|
|
||
| $database->createCollection('animals'); | ||
| $database->createAttribute('animals', 'name', Database::VAR_STRING, 256, true); | ||
| $database->createAttribute('animals', 'age', Database::VAR_INTEGER, 0, false); | ||
| $database->createAttribute('animals', 'price', Database::VAR_FLOAT, 0, false); | ||
| $database->createAttribute('animals', 'date_of_birth', Database::VAR_DATETIME, 0, true, filters:['datetime']); | ||
| $database->createAttribute('animals', 'longtext', Database::VAR_STRING, 100000000, false); | ||
| $database->createAttribute('animals', 'is_active', Database::VAR_BOOLEAN, 0, false, default: true); | ||
| $database->createAttribute('animals', 'integers', Database::VAR_INTEGER, 0, false, array: true); | ||
| $database->createAttribute('animals', 'email', Database::VAR_STRING, 255, false); | ||
| $database->createAttribute('animals', 'ip', Database::VAR_STRING, 255, false); | ||
| $database->createAttribute('animals', 'url', Database::VAR_STRING, 255, false); | ||
| $database->createAttribute('animals', 'enum', Database::VAR_STRING, 255, false); | ||
|
|
||
| $database->createRelationship( | ||
| collection: 'presidents', | ||
| relatedCollection: 'animals', | ||
| type: Database::RELATION_ONE_TO_ONE, | ||
| twoWay: true, | ||
| id: 'animal', | ||
| twoWayKey: 'president' | ||
| ); | ||
|
|
||
| $database->createRelationship( | ||
| collection: 'veterinarians', | ||
| relatedCollection: 'animals', | ||
| type: Database::RELATION_ONE_TO_MANY, | ||
| twoWay: true, | ||
| id: 'animals', | ||
| twoWayKey: 'veterinarian' | ||
| ); | ||
|
|
||
| $database->createRelationship( | ||
| collection: 'animals', | ||
| relatedCollection: 'zoo', | ||
| type: Database::RELATION_MANY_TO_ONE, | ||
| twoWay: true, | ||
| id: 'zoo', | ||
| twoWayKey: 'animals' | ||
| ); | ||
|
|
||
| $zoo1 = $database->createDocument('zoo', new Document([ | ||
| '$id' => 'zoo1', | ||
| '$permissions' => [ | ||
| Permission::read(Role::any()), | ||
| Permission::update(Role::any()), | ||
| ], | ||
| 'name' => 'Bronx Zoo' | ||
| ])); | ||
|
|
||
| $animal1 = $database->createDocument('animals', new Document([ | ||
| '$id' => 'iguana', | ||
| '$permissions' => [ | ||
| Permission::read(Role::any()), | ||
| Permission::update(Role::any()), | ||
| ], | ||
| 'name' => 'Iguana', | ||
| 'age' => 11, | ||
| 'price' => 50.5, | ||
| 'date_of_birth' => '1975-06-12', | ||
| 'longtext' => 'I am a pretty long text', | ||
| 'is_active' => true, | ||
| 'integers' => [1, 2, 3], | ||
| 'email' => 'iguana@appwrite.io', | ||
| 'enum' => 'maybe', | ||
| 'ip' => '127.0.0.1', | ||
| 'url' => 'https://appwrite.io/', | ||
| 'zoo' => $zoo1->getId(), | ||
| ])); | ||
|
|
||
| $animal2 = $database->createDocument('animals', new Document([ | ||
| '$id' => 'tiger', | ||
| '$permissions' => [ | ||
| Permission::read(Role::any()), | ||
| Permission::update(Role::any()), | ||
| ], | ||
| 'name' => 'Tiger', | ||
| 'age' => 5, | ||
| 'price' => 1000, | ||
| 'date_of_birth' => '2020-06-12', | ||
| 'longtext' => 'I am a hungry tiger', | ||
| 'is_active' => false, | ||
| 'integers' => [9, 2, 3], | ||
| 'email' => 'tiger@appwrite.io', | ||
| 'enum' => 'yes', | ||
| 'ip' => '255.0.0.1', | ||
| 'url' => 'https://appwrite.io/', | ||
| 'zoo' => $zoo1->getId(), | ||
| ])); | ||
|
|
||
| $animal3 = $database->createDocument('animals', new Document([ | ||
| '$id' => 'lama', | ||
| '$permissions' => [ | ||
| Permission::read(Role::any()), | ||
| Permission::update(Role::any()), | ||
| ], | ||
| 'name' => 'Lama', | ||
| 'age' => 15, | ||
| 'price' => 1000, | ||
| 'date_of_birth' => '1975-06-12', | ||
| 'is_active' => true, | ||
| 'integers' => null, | ||
| 'email' => null, | ||
| 'enum' => null, | ||
| 'ip' => '255.0.0.1', | ||
| 'url' => 'https://appwrite.io/', | ||
| 'zoo' => null, | ||
| ])); | ||
|
|
||
| $veterinarian1 = $database->createDocument('veterinarians', new Document([ | ||
| '$id' => 'dr.pol', | ||
| '$permissions' => [ | ||
| Permission::read(Role::any()), | ||
| Permission::update(Role::any()), | ||
| ], | ||
| 'fullname' => 'The Incredible Dr. Pol', | ||
| 'animals' => ['iguana'], | ||
| ])); | ||
|
|
||
| $veterinarian2 = $database->createDocument('veterinarians', new Document([ | ||
| '$id' => 'dr.seuss', | ||
| '$permissions' => [ | ||
| Permission::read(Role::any()), | ||
| Permission::update(Role::any()), | ||
| ], | ||
| 'fullname' => 'Dr. Seuss', | ||
| 'animals' => ['tiger'], | ||
| ])); | ||
|
|
||
| $president1 = $database->createDocument('presidents', new Document([ | ||
| '$id' => 'trump', | ||
| '$permissions' => [ | ||
| Permission::read(Role::any()), | ||
| Permission::update(Role::any()), | ||
| ], | ||
| 'first_name' => 'Donald', | ||
| 'last_name' => 'Trump', | ||
| 'votes' => [ | ||
| $veterinarian1->getId(), | ||
| $veterinarian2->getId(), | ||
| ], | ||
| ])); | ||
|
|
||
| $president2 = $database->createDocument('presidents', new Document([ | ||
| '$id' => 'bush', | ||
| '$permissions' => [ | ||
| Permission::read(Role::any()), | ||
| Permission::update(Role::any()), | ||
| ], | ||
| 'first_name' => 'George', | ||
| 'last_name' => 'Bush', | ||
| 'animal' => 'iguana', | ||
| ])); | ||
|
|
||
| $president3 = $database->createDocument('presidents', new Document([ | ||
| '$id' => 'biden', | ||
| '$permissions' => [ | ||
| Permission::read(Role::any()), | ||
| Permission::update(Role::any()), | ||
| ], | ||
| 'first_name' => 'Joe', | ||
| 'last_name' => 'Biden', | ||
| 'animal' => 'tiger', | ||
| ])); | ||
|
|
||
| var_dump('=== start === === start === === start === === start === === start === === start === === start === === start === === start ==='); | ||
|
|
||
| $docs = $database->find('veterinarians', | ||
| [ | ||
| Query::select([ | ||
| '*', | ||
| 'animals.*', | ||
| 'animals.zoo.*', | ||
| //'animals.president.*', | ||
| ]) | ||
| ] | ||
| ); | ||
|
|
||
| $this->assertEquals('shmuel', 'fogel'); | ||
| } | ||
|
|
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.
🛠️ Refactor suggestion
Comprehensive test setup but needs completion and cleanup.
This test method creates a complex relationship scenario which is excellent for testing nested relationship queries. However, several issues need attention:
- Unused variables: Static analysis correctly identifies unused document variables
- Debug code: The
var_dumpstatement should be removed - Placeholder assertion: The final assertion doesn't validate the actual test results
Apply this diff to address the critical issues:
- $animal1 = $database->createDocument('animals', new Document([
+ $database->createDocument('animals', new Document([
'$id' => 'iguana',
// ... rest of document
]));
- $animal2 = $database->createDocument('animals', new Document([
+ $database->createDocument('animals', new Document([
'$id' => 'tiger',
// ... rest of document
]));
- $animal3 = $database->createDocument('animals', new Document([
+ $database->createDocument('animals', new Document([
'$id' => 'lama',
// ... rest of document
]));
- $veterinarian1 = $database->createDocument('veterinarians', new Document([
+ $database->createDocument('veterinarians', new Document([
'$id' => 'dr.pol',
// ... rest of document
]));
- $veterinarian2 = $database->createDocument('veterinarians', new Document([
+ $database->createDocument('veterinarians', new Document([
'$id' => 'dr.seuss',
// ... rest of document
]));
- $president1 = $database->createDocument('presidents', new Document([
+ $database->createDocument('presidents', new Document([
'$id' => 'trump',
// ... rest of document
]));
- $president2 = $database->createDocument('presidents', new Document([
+ $database->createDocument('presidents', new Document([
'$id' => 'bush',
// ... rest of document
]));
- $president3 = $database->createDocument('presidents', new Document([
+ $database->createDocument('presidents', new Document([
'$id' => 'biden',
// ... rest of document
]));
- var_dump('=== start === === start === === start === === start === === start === === start === === start === === start === === start ===');
$docs = $database->find('veterinarians',
[
Query::select([
'*',
'animals.*',
'animals.zoo.*',
- //'animals.president.*',
])
]
);
- $this->assertEquals('shmuel', 'fogel');
+ // Add meaningful assertions here to validate the nested relationship query results
+ $this->assertNotEmpty($docs);
+ // TODO: Add specific assertions to validate the structure and content of returned documentsCommittable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 PHPMD (2.15.0)
107-107: Avoid unused local variables such as '$animal1'. (Unused Code Rules)
(UnusedLocalVariable)
127-127: Avoid unused local variables such as '$animal2'. (Unused Code Rules)
(UnusedLocalVariable)
147-147: Avoid unused local variables such as '$animal3'. (Unused Code Rules)
(UnusedLocalVariable)
186-186: Avoid unused local variables such as '$president1'. (Unused Code Rules)
(UnusedLocalVariable)
200-200: Avoid unused local variables such as '$president2'. (Unused Code Rules)
(UnusedLocalVariable)
211-211: Avoid unused local variables such as '$president3'. (Unused Code Rules)
(UnusedLocalVariable)
224-224: Avoid unused local variables such as '$docs'. (Unused Code Rules)
(UnusedLocalVariable)
🤖 Prompt for AI Agents
In tests/e2e/Adapter/Scopes/RelationshipTests.php from lines 30 to 237, the
testZoo method has unused document variables, a var_dump debug statement, and a
placeholder assertion that does not validate test results. Remove the var_dump
statement, replace the placeholder assertion with meaningful assertions that
verify the expected outcomes of the relationship queries, and clean up any
unused variables to ensure the test is complete and clean.
| ] | ||
| ); | ||
|
|
||
| $this->assertEquals('shmuel', 'fogel'); |
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.
Replace placeholder assertion with meaningful tests.
The current assertion compares two unrelated strings and doesn't validate the test results. This test should verify that the nested relationship query returns the expected structure and data.
The test should validate:
- That documents are returned with the correct structure
- That nested relationships (animals.zoo.*) are properly populated
- That the relationship data is accurate
Would you like me to help generate proper assertions for this complex relationship scenario?
🤖 Prompt for AI Agents
In tests/e2e/Adapter/Scopes/RelationshipTests.php at line 235, replace the
placeholder assertion comparing unrelated strings with meaningful assertions
that verify the nested relationship query results. Specifically, assert that the
returned documents have the correct structure, that nested relationships under
animals.zoo are properly populated, and that the relationship data matches
expected values. Use assertions to check the presence and correctness of nested
data rather than simple string equality.
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.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
src/Database/Database.php (1)
6810-6836: Critical: Remove debug statements immediatelyThe refactoring to explode the string once is good, but the debug
var_dumpstatements must be removed. These will output to the response in production, potentially exposing sensitive information and breaking API responses.- $nesting = \explode('.', $value); - $selectedKey = \array_shift($nesting); // Remove and return first item + $nesting = \explode('.', $value); + $selectedKey = \array_shift($nesting); // Remove and return first item $relationship = \array_values(\array_filter( $relationships, fn (Document $relationship) => $relationship->getAttribute('key') === $selectedKey, ))[0] ?? null; if (!$relationship) { continue; } // Shift the top level off the dot-path to pass the selection down the chain // 'foo.bar.baz' becomes 'bar.baz' $nestedSelections[] = Query::select([ \implode('.', $nesting) ]); $type = $relationship->getAttribute('options')['relationType']; $side = $relationship->getAttribute('options')['side']; - var_dump('=========== in ========'); - var_dump($selectedKey); - var_dump($nesting); - var_dump($type); - var_dump($side); - switch ($type) {
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Database/Database.php(8 hunks)
⏰ 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 (MySQL)
- GitHub Check: Adapter Tests (SharedTables/SQLite)
- GitHub Check: Adapter Tests (SharedTables/MySQL)
- GitHub Check: Adapter Tests (Pool)
- GitHub Check: Adapter Tests (Mirror)
- GitHub Check: Adapter Tests (SharedTables/MariaDB)
- GitHub Check: Adapter Tests (SharedTables/Postgres)
- GitHub Check: Adapter Tests (SQLite)
- GitHub Check: Adapter Tests (Postgres)
- GitHub Check: Adapter Tests (MariaDB)
🔇 Additional comments (3)
src/Database/Database.php (3)
3286-3288: Good performance optimization!Adding the check for non-empty relationships before attempting to populate them prevents unnecessary processing when no relationships are defined.
5095-5108: Safe iteration pattern adoptedGood change from reference-based to indexed iteration. This approach is safer and avoids potential issues with PHP references while maintaining the same functionality.
6352-6359: Consistent iteration patternGood consistency with the indexed iteration pattern used elsewhere in the codebase.
src/Database/Database.php
Outdated
| //var_dump($queries); | ||
|
|
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.
Remove commented debug statement
Debug statements should not be committed to production code. Please remove this commented var_dump statement.
if (!empty($relatedIds)) {
- //var_dump($queries);
-
$foundRelated = $this->find($relatedCollection->getId(), [📝 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.
| //var_dump($queries); | |
| if (!empty($relatedIds)) { | |
| $foundRelated = $this->find($relatedCollection->getId(), [ |
🤖 Prompt for AI Agents
In src/Database/Database.php around lines 3530 to 3531, there is a commented out
debug statement using var_dump. Remove this commented var_dump line entirely to
clean up the production code and avoid leaving debug artifacts.
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.
Actionable comments posted: 1
♻️ Duplicate comments (3)
tests/e2e/Adapter/Scopes/RelationshipTests.php (3)
238-239: Add meaningful test assertions.The placeholder assertion is commented out and doesn't validate the nested relationship query results. This test should verify that the complex relationship structure is correctly populated.
Replace the commented placeholder with assertions that validate:
- Documents are returned with correct structure
- Nested relationships (animals.zoo.*) are properly populated
- Relationship data matches expected values
- //$this->assertEquals('shmuel', 'fogel'); + // Validate that veterinarian documents are returned + $this->assertNotEmpty($docs); + $this->assertCount(2, $docs); + + // Validate nested animal relationships are populated + foreach ($docs as $veterinarian) { + $this->assertArrayHasKey('animals', $veterinarian); + $animals = $veterinarian->getAttribute('animals'); + + if (!empty($animals)) { + foreach ($animals as $animal) { + // Validate zoo relationship is populated + $this->assertArrayHasKey('zoo', $animal); + if (!empty($animal->getAttribute('zoo'))) { + $zoo = $animal->getAttribute('zoo'); + $this->assertEquals('Bronx Zoo', $zoo->getAttribute('name')); + } + } + } + }
222-222: Remove debug statement before merging.The
var_dumpstatement should be removed as it's debug code that doesn't belong in the final test.- var_dump('=== start === === start === === start === === start === === start === === start === === start === === start === === start ===');
224-234: Validate the relationship query structure.The nested selection query
['*', 'animals.*', 'animals.zoo.*']is testing complex relationship functionality. Consider adding assertions to validate that this query structure works correctly and returns the expected nested data.Add validation for the query structure:
$docs = $database->find( 'veterinarians', [ Query::select([ '*', 'animals.*', 'animals.zoo.*', - //'animals.president.*', ]) ] ); + + // Validate the query returns expected structure + foreach ($docs as $doc) { + // Verify veterinarian attributes are selected + $this->assertArrayHasKey('fullname', $doc); + + // Verify animals relationship is properly nested + if (!empty($doc->getAttribute('animals'))) { + foreach ($doc->getAttribute('animals') as $animal) { + $this->assertArrayHasKey('name', $animal); + $this->assertArrayHasKey('zoo', $animal); + } + } + }
🧹 Nitpick comments (1)
tests/e2e/Adapter/Scopes/RelationshipTests.php (1)
107-107: Consider removing unused variables or add assertions.Static analysis correctly identifies that the document creation return values are unused. While not critical for tests, you could either remove the variable assignments or use them in assertions to validate document creation.
For cleaner code, consider either:
Option 1 - Remove variable assignments:
- $animal1 = $database->createDocument('__animals', new Document([ + $database->createDocument('__animals', new Document([Option 2 - Add basic validation assertions:
$animal1 = $database->createDocument('__animals', new Document([ // ... document data ])); + $this->assertEquals('iguana', $animal1->getId());Also applies to: 127-127, 147-147, 166-166, 176-176, 186-186, 200-200, 211-211
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/Database/Database.php(10 hunks)tests/e2e/Adapter/Scopes/RelationshipTests.php(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Database/Database.php
🧰 Additional context used
🪛 PHPMD (2.15.0)
tests/e2e/Adapter/Scopes/RelationshipTests.php
107-107: Avoid unused local variables such as '$animal1'. (Unused Code Rules)
(UnusedLocalVariable)
127-127: Avoid unused local variables such as '$animal2'. (Unused Code Rules)
(UnusedLocalVariable)
147-147: Avoid unused local variables such as '$animal3'. (Unused Code Rules)
(UnusedLocalVariable)
186-186: Avoid unused local variables such as '$president1'. (Unused Code Rules)
(UnusedLocalVariable)
200-200: Avoid unused local variables such as '$president2'. (Unused Code Rules)
(UnusedLocalVariable)
211-211: Avoid unused local variables such as '$president3'. (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 (MySQL)
- GitHub Check: Adapter Tests (Mirror)
- GitHub Check: Adapter Tests (SharedTables/Postgres)
- GitHub Check: Adapter Tests (SharedTables/MySQL)
- GitHub Check: Adapter Tests (Postgres)
- GitHub Check: Adapter Tests (SharedTables/SQLite)
- GitHub Check: Adapter Tests (Pool)
- GitHub Check: Adapter Tests (MariaDB)
- GitHub Check: Adapter Tests (SQLite)
- GitHub Check: Adapter Tests (SharedTables/MariaDB)
| ] | ||
| ); | ||
|
|
||
| var_dump($docs); |
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.
Remove debug output.
The var_dump($docs) statement should be removed as it's debug code.
- var_dump($docs);📝 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.
| var_dump($docs); | |
| // Add meaningful assertions here to validate the nested relationship query results | |
| $this->assertNotEmpty($docs); | |
| // TODO: Add specific assertions to validate the structure and content of returned documents |
🤖 Prompt for AI Agents
In tests/e2e/Adapter/Scopes/RelationshipTests.php at line 236, remove the
var_dump($docs) statement as it is debug output and should not be present in the
final test code.
Summary by CodeRabbit
Bug Fixes
Tests