-
-
Notifications
You must be signed in to change notification settings - Fork 342
fix: Restore direct pointer match in equalTo for array value queries #527
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
dacdoyx
wants to merge
3
commits into
parse-community:master
Choose a base branch
from
dacdoyx:fix/equalTo-array-values
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| <?php | ||
| spl_autoload_register(function ($class) { | ||
| $prefix = 'Parse\\'; | ||
| $base = __DIR__ . '/src/Parse/'; | ||
| if (strpos($class, $prefix) !== 0) return; | ||
| $relative = substr($class, strlen($prefix)); | ||
| $file = $base . str_replace('\\', '/', $relative) . '.php'; | ||
| if (file_exists($file)) require_once $file; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| use Parse\ParseClient; | ||
| use Parse\ParseObject; | ||
| use Parse\ParseQuery; | ||
|
|
||
| ParseClient::initialize('appId', 'restKey', 'https://api.example.com'); | ||
|
|
||
| $passed = 0; | ||
| $failed = 0; | ||
|
|
||
| function check($name, $condition) { | ||
| global $passed, $failed; | ||
| if ($condition) { echo " PASS: $name\n"; $passed++; } | ||
| else { echo " FAIL: $name\n"; $failed++; } | ||
| } | ||
|
|
||
| echo "=== equalTo Fix Verification ===\n\n"; | ||
|
|
||
| // Test 1: ParseObject value should use direct pointer match at query build time | ||
| echo "Test 1: ParseObject uses direct pointer match in built query\n"; | ||
| $user = ParseObject::create('_User', 'user123'); | ||
| $query = new ParseQuery('ParseRole'); | ||
| $query->equalTo('users', $user); | ||
| $opts = $query->_getOptions(); | ||
| $encoded = json_encode($opts['where'] ?? []); | ||
| echo " Built query where = $encoded\n"; | ||
| check('should NOT have $eq in output', strpos($encoded, '$eq') === false); | ||
| check('should NOT have $eq_pointer in output', strpos($encoded, '$eq_pointer') === false); | ||
| check('should have __type=Pointer in output', strpos($encoded, '"__type":"Pointer"') !== false); | ||
| check('should have className=_User', strpos($encoded, '"className":"_User"') !== false); | ||
| check('should have objectId=user123', strpos($encoded, '"objectId":"user123"') !== false); | ||
|
|
||
| // Test 2: String value still uses $eq | ||
| echo "\nTest 2: String uses \$eq\n"; | ||
| $query2 = new ParseQuery('TestClass'); | ||
| $query2->equalTo('foo', 'bar'); | ||
| $opts2 = $query2->_getOptions(); | ||
| $encoded2 = json_encode($opts2['where'] ?? []); | ||
| echo " where = $encoded2\n"; | ||
| check('foo should have $eq', strpos($encoded2, '$eq') !== false); | ||
| check('foo $eq should be bar', strpos($encoded2, '"bar"') !== false); | ||
|
|
||
| // Test 3: Number value still uses $eq | ||
| echo "\nTest 3: Number uses \$eq\n"; | ||
| $query3 = new ParseQuery('TestClass'); | ||
| $query3->equalTo('number', 17); | ||
| $opts3 = $query3->_getOptions(); | ||
| $encoded3 = json_encode($opts3['where'] ?? []); | ||
| echo " where = $encoded3\n"; | ||
| check('number should have $eq', strpos($encoded3, '$eq') !== false); | ||
|
|
||
| // Test 4: Chained constraints on same key still work | ||
| echo "\nTest 4: Chained constraints on same key\n"; | ||
| $query4 = new ParseQuery('TestClass'); | ||
| $query4->equalTo('foo', 'bar'); | ||
| $query4->greaterThan('foo', 10); | ||
| $opts4 = $query4->_getOptions(); | ||
| $encoded4 = json_encode($opts4['where'] ?? []); | ||
| echo " where = $encoded4\n"; | ||
| check('foo should have both $eq and $gt', strpos($encoded4, '$eq') !== false && strpos($encoded4, '$gt') !== false); | ||
|
|
||
| // Test 5: ParseObject + another constraint on SAME key (mixed case) | ||
| echo "\nTest 5: ParseObject with other constraints on same key\n"; | ||
| $query5 = new ParseQuery('TestClass'); | ||
| $query5->equalTo('users', $user); | ||
| $query5->exists('users'); | ||
| $opts5 = $query5->_getOptions(); | ||
| $encoded5 = json_encode($opts5['where'] ?? []); | ||
| echo " where = $encoded5\n"; | ||
| check('should NOT have $eq_pointer in output', strpos($encoded5, '$eq_pointer') === false); | ||
| check('users should still contain the pointer payload', strpos($encoded5, '"__type":"Pointer"') !== false); | ||
| check('users should still contain the sibling operator', strpos($encoded5, '$exists') !== false); | ||
|
|
||
| echo "\n=== Results: $passed passed, $failed failed ===\n"; | ||
| exit($failed > 0 ? 1 : 0); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /** | ||
| * Standalone verification for equalTo fix | ||
| * Tests that ParseObject values use direct pointer matching (not $eq) | ||
| * and non-Object values still use $eq | ||
| */ | ||
|
|
||
| require_once __DIR__ . '/src/Parse/ParseClient.php'; | ||
| require_once __DIR__ . '/src/Parse/ParseObject.php'; | ||
| require_once __DIR__ . '/src/Parse/ParseQuery.php'; | ||
| require_once __DIR__ . '/src/Parse/ParseUser.php'; | ||
| require_once __DIR__ . '/src/Parse/ParseRole.php'; | ||
| require_once __DIR__ . '/src/Parse/Internal/Encodable.php'; | ||
|
|
||
| use Parse\ParseClient; | ||
| use Parse\ParseObject; | ||
| use Parse\ParseQuery; | ||
| use Parse\ParseUser; | ||
| use Parse\ParseRole; | ||
|
|
||
| // Initialize Parse client | ||
| ParseClient::initialize('appId', 'restKey', 'https://api.example.com'); | ||
|
|
||
| $passed = 0; | ||
| $failed = 0; | ||
|
|
||
| function assert_test($name, $condition) { | ||
| global $passed, $failed; | ||
| if ($condition) { | ||
| echo " ✓ $name\n"; | ||
| $passed++; | ||
| } else { | ||
| echo " ✗ FAIL: $name\n"; | ||
| $failed++; | ||
| } | ||
| } | ||
|
|
||
| echo "=== equalTo Fix Verification ===\n\n"; | ||
|
|
||
| // Test 1: ParseObject value should use direct pointer match (NOT $eq) | ||
| echo "Test 1: ParseObject value uses direct pointer match\n"; | ||
| $user = ParseObject::create('_User', 'user123'); | ||
| $query = ParseQuery::getQuery('ParseRole'); | ||
| $query->equalTo('users', $user); | ||
| $where = $query->getWhere(); | ||
|
|
||
| assert_test( | ||
| "where['users'] should NOT have \$eq key", | ||
| !isset($where['users']['$eq']) | ||
| ); | ||
| assert_test( | ||
| "where['users'] should have __type = Pointer", | ||
| isset($where['users']['__type']) && $where['users']['__type'] === 'Pointer' | ||
| ); | ||
| assert_test( | ||
| "where['users'] should have className = _User", | ||
| isset($where['users']['className']) && $where['users']['className'] === '_User' | ||
| ); | ||
| assert_test( | ||
| "where['users'] should have objectId = user123", | ||
| isset($where['users']['objectId']) && $where['users']['objectId'] === 'user123' | ||
| ); | ||
|
|
||
| // Test 2: String value should still use $eq | ||
| echo "\nTest 2: String value uses \$eq\n"; | ||
| $query2 = ParseQuery::getQuery('TestClass'); | ||
| $query2->equalTo('foo', 'bar'); | ||
| $where2 = $query2->getWhere(); | ||
|
|
||
| assert_test( | ||
| "where['foo'] should have \$eq key", | ||
| isset($where2['foo']['$eq']) | ||
| ); | ||
| assert_test( | ||
| "where['foo']['\$eq'] should be 'bar'", | ||
| isset($where2['foo']['$eq']) && $where2['foo']['$eq'] === 'bar' | ||
| ); | ||
|
|
||
| // Test 3: Number value should still use $eq | ||
| echo "\nTest 3: Number value uses \$eq\n"; | ||
| $query3 = ParseQuery::getQuery('TestClass'); | ||
| $query3->equalTo('number', 17); | ||
| $where3 = $query3->getWhere(); | ||
|
|
||
| assert_test( | ||
| "where['number'] should have \$eq key", | ||
| isset($where3['number']['$eq']) | ||
| ); | ||
| assert_test( | ||
| "where['number']['\$eq'] should be 17", | ||
| isset($where3['number']['$eq']) && $where3['number']['$eq'] === 17 | ||
| ); | ||
|
|
||
| // Test 4: null value should still use $eq | ||
| echo "\nTest 4: null value uses \$eq\n"; | ||
| $query4 = ParseQuery::getQuery('TestClass'); | ||
| $query4->equalTo('num', null); | ||
| $where4 = $query4->getWhere(); | ||
|
|
||
| assert_test( | ||
| "where['num'] should have \$eq key", | ||
| isset($where4['num']['$eq']) | ||
| ); | ||
| assert_test( | ||
| "where['num']['\$eq'] should be null", | ||
| isset($where4['num']['$eq']) && $where4['num']['$eq'] === null | ||
| ); | ||
|
|
||
| // Test 5: Array value should still use $eq | ||
| echo "\nTest 5: Array value uses \$eq\n"; | ||
| $query5 = ParseQuery::getQuery('TestClass'); | ||
| $query5->equalTo('tags', ['foo', 'bar']); | ||
| $where5 = $query5->getWhere(); | ||
|
|
||
| assert_test( | ||
| "where['tags'] should have \$eq key", | ||
| isset($where5['tags']['$eq']) | ||
| ); | ||
|
|
||
| echo "\n=== Results ===\n"; | ||
| echo "Passed: $passed\n"; | ||
| echo "Failed: $failed\n"; | ||
|
|
||
| if ($failed > 0) { | ||
| echo "\n❌ SOME TESTS FAILED\n"; | ||
| exit(1); | ||
| } else { | ||
| echo "\n✅ ALL TESTS PASSED\n"; | ||
| exit(0); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.