-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[in_app_purchase] Remove use of Pigeon's Dart test generator #10328
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: main
Are you sure you want to change the base?
[in_app_purchase] Remove use of Pigeon's Dart test generator #10328
Conversation
Updates the production code to use a single instance of each of the two Pigeon host APIs, rather than a private per-file copy, so that tests can inject an alternate implementation directly instead of relying on the method channel hook and Pigeon's dartHostTestHandler. Part of flutter/flutter#159886
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.
Code Review
This pull request refactors the in_app_purchase_storekit package to improve testability by removing the use of Pigeon's Dart test generator. The changes introduce a centralized mechanism for managing Pigeon host API instances, using global variables that can be replaced with mocks in tests. This is achieved by creating a new in_app_purchase_apis.dart file. The production code is updated to use these global API instances, and the test files are updated to use the new mocking strategy. The fake platform implementations are also updated to implement the real API interfaces, which makes the test setup more realistic. The changes are consistent, well-structured, and effectively achieve the goal of improving the testing architecture. The code quality is excellent.
|
This is less clean that all the other PRs for flutter/flutter#159886 because we don't have one central class to DI the alternate implementation into, and in fact there are static methods and top-level functions that use this. The other alternative I can see here is to make a test injection method per file, like the (unused) one that used to be in sk_payment_queue_wrapper.dart, but that seems less maintainable. |
| expect( | ||
| () async => SKReceiptManager.retrieveReceiptData(), | ||
| throwsA(const TypeMatcher<PlatformException>()), | ||
| throwsA(const TypeMatcher<Exception>()), |
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.
This change is because the test started failing. The FakeStoreKitPlatform in this file throws an Exception, not a PlatformException. There is a different FakeStoreKitPlatform in a different file that throws a PlatformException, so it seems like this test was probably passing because somehow the wrong fake implementation was registered when it ran?
Updates the production code to use a single instance of each of the two Pigeon host APIs, rather than a private per-file copy, so that tests can inject an alternate implementation directly instead of relying on the method channel hook and Pigeon's dartHostTestHandler.
Part of flutter/flutter#159886
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3