-
Notifications
You must be signed in to change notification settings - Fork 191
fix php tests #1262
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
base: master
Are you sure you want to change the base?
fix php tests #1262
Conversation
Expanded api.twig to support 'location' method type. Enhanced IDTest.php.twig to check unique ID length. Refactored QueryTest.php.twig to validate JSON structure and content of Query methods instead of string output. Updated ServiceTest.php.twig to import enum types and use enum values for parameters, and to support additional method types in mocks.
WalkthroughThree PHP test template files are being updated. The IDTest template now validates generated ID length rather than a fixed string. The QueryTest template replaces direct string assertions with JSON-based parsing and structural validation across multiple query operators. The ServiceTest template adds dynamic enum type imports based on method parameters, extends array return-type handling, adjusts mock setup for webAuth methods, and enhances parameter generation to output concrete enum values when applicable. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
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: 0
🧹 Nitpick comments (1)
templates/php/tests/Services/ServiceTest.php.twig (1)
9-19: Enum imports generation is sound; consider normalizing names for dedupeThe pre-pass over
service.methodscorrectly emitsuse Appwrite\Enums\...only once perenumName, which should fix missing-import TypeErrors in generated tests.If you ever end up with inconsistent casing for
parameter.enumNameacross methods, you could normalize before checkingaddedto avoid duplicateuselines, e.g. storeparameter.enumName | caseUcfirstin a temp variable and use that for both theuseand theaddedarray. This is purely defensive and not required for current usage.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
templates/php/tests/Services/ServiceTest.php.twig(2 hunks)
🔇 Additional comments (3)
templates/php/tests/Services/ServiceTest.php.twig (3)
42-52: Array return-type handling extension looks correctTreating
(method.responseModel == 'any')and(method | getReturn == 'array')as array responses and initializing$data = array();keeps the test stubs aligned with actual service return types while preserving the structured-model and string fallbacks. This is a clean, targeted fix with no obvious side effects.
54-55: Conditional extraMockery::any()forwebAuthmethods matches call signatureExtending the
allows()->call(...)expectation to include a fifthMockery::any()whenmethod.type == 'webAuth'makes the mock signature align with the client’scallusage for those methods, fixing argument-count mismatches while keeping non‑webAuthmethods unchanged.
57-59: Enum parameter emission now matches official PHP SDK usageSwitching enum-typed parameters to
{{ EnumName | caseUcfirst }}::{{ ... | caseEnumKey }}()aligns generated tests with the documented PHP SDK style (use Appwrite\Enums\AuthenticatorType; ... AuthenticatorType::TOTP()). (appwrite.io)This should resolve prior TypeErrors where raw strings were passed instead of enum instances, while leaving all non-enum parameter cases (objects, arrays, files, scalars) unchanged.
What does this PR do?
This PR fixes multiple issues in the PHP SDK test templates that were causing significant test failures (TypeErrors and Assertion failures).
Specifically, it addresses the following:
ServiceTest.php.twigto correctly import and use Enum classes for method parameters instead of passing raw strings. This resolves theTypeErrors seen inAccountTest,UsersTest, etc., where arguments were expected to be specific Enum instances (e.g.,Appwrite\Enums\AuthenticatorType).QueryTest.php.twigto parse the returned JSON string fromQuerymethods and assert against the structured data (method, attribute, values) instead of performing exact string matching. This fixes failures where the tests expected a function-like string (e.g.,equal("attr", ["s"])) but received a JSON string.IDTest.php.twigto verify the length of the generated unique ID (20 chars) instead of asserting equality with the literal string'unique()'.api.twigto correctly handle thelocationmethod type in theClient::callarguments.Test Plan
regenerate sdk, run php tests


before:
after:
Related PRs and Issues
(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)
Have you read the Contributing Guidelines on issues?
YES
Summary by CodeRabbit
Tests
✏️ Tip: You can customize this high-level summary in your review settings.