Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on improving the robustness and developer experience of the module. It refines how API errors are processed and presented to the user, making them clearer and more actionable. Concurrently, it establishes a foundational unit testing framework and enhances the local development environment setup through Makefile additions, ensuring better code quality and maintainability. Highlights
Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
Bootstrap test infrastructure without composer install — uses a PSR-4 autoloader and Magento stub classes so tests run with just a phpunit phar on a bare PHP image. - 38 tests (65 assertions) covering getErrorFromResponse(), getFieldNameFromLoc(), getCheckoutApiUrl(), getCheckoutPageUrl() - Docker-based `make test` target and CI workflow (PHP 7.4/8.1/8.2) - Fix return type bug: SCHEMA_ERROR/ORDER_INVALID now returns Phrase Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
c526a82 to
d5ca31d
Compare
There was a problem hiding this comment.
Code Review
This pull request significantly improves error handling by providing more specific and user-friendly messages from the API, especially for validation errors. It also introduces a robust unit testing setup with stubs and a comprehensive test suite for the new error handling logic and URL generation, which is a great step towards better code quality and maintainability. The refactoring to use Magento's AppState instead of getenv is also a good practice. I've added a couple of suggestions to improve the developer experience with the new test runner and to prevent a potential translation bug.
I am having trouble creating individual review comments. Click here to see my feedback.
Model/Two.php (351-364)
Using a static variable to cache the $fieldNames array can lead to bugs related to translation. The __() calls are evaluated only once when the static variable is initialized. If the locale changes during a single PHP request (which can happen in some Magento API scenarios), this method will return stale translations from the previously active locale.
Since this array is small, the performance benefit of caching is negligible. It's safer to remove the static variable and initialize the array on every call.
$fieldNames = [
'["buyer","representative","phone_number"]' => __('Phone Number'),
'["buyer","company","organization_number"]' => __('Company ID'),
'["buyer","representative","first_name"]' => __('First Name'),
'["buyer","representative","last_name"]' => __('Last Name'),
'["buyer","representative","email"]' => __('Email Address'),
'["billing_address","street_address"]' => __('Street Address'),
'["billing_address","city"]' => __('City'),
'["billing_address","country"]' => __('Country'),
'["billing_address","postal_code"]' => __('Zip/Postal Code'),
];Makefile (100-101)
The test target downloads phpunit.phar on every run. This can slow down the test cycle.
To improve this, you could download it into a local bin directory, which is then available inside the container via the volume mount. This way, it's downloaded only once.
Remember to add bin/ to your .gitignore file.
"if [ ! -f /app/bin/phpunit.phar ]; then mkdir -p /app/bin && php -r \"copy('https://phar.phpunit.de/phpunit-9.6.phar', '/app/bin/phpunit.phar');\"; fi; \
php /app/bin/phpunit.phar"
Add tests asserting that in developer mode, TWO_API_BASE_URL and TWO_CHECKOUT_BASE_URL env vars take precedence even when an explicit $mode parameter is passed to getCheckoutApiUrl/getCheckoutPageUrl. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Pin to phpunit-9.6.34 with hardcoded SHA256 hash in both CI workflow and Makefile to prevent supply chain attacks via compromised CDN. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds Test/E2E/ with a RealCurl HTTP implementation and three tests covering valid key, invalid key (401), and bad payload. make test runs Unit only (defaultTestSuite); make test-e2e forwards TWO_API_KEY/TWO_API_BASE_URL into Docker and runs the E2E suite. Missing key fails naturally at the assertion rather than skipping.
Stubs for Curl, LocalizedException, BundlePrice, ProductType; unit tests for Adapter, OrderShouldSkip, and addVersionDataInURL; bootstrap wiring; session summary and plan docs.
Remove session summaries and implementation plans that were accidentally committed. Add Session Artifacts section to AGENTS.md clarifying that session-specific content must not be committed to this public repository. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Previously flagged issues are addressed: PHAR checksum verification is now in place for both the CI workflow and the make test target. The docs/plans/ file was removed and the thread resolved.
No new critical issues found in the current diff. The Model/Two.php fix (ensuring $reason is always a Phrase) is correct. The test infrastructure looks solid. Ready for human approval.
No description provided.