[WIP] [Feature] Implement custom auth guard for Shopify sessions and enable unit and feature testing. #469
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.
WHY are these changes introduced?
Fixes #466
Please review the changes and suggest feedback. I am still pending resolving one issue with how to dynamically provide the
isOnlineflag when loading the current Shopify session from the Shopify PHP library. I wanted to submit this now to incorporate feedback sooner before I remove this from being WIP.Here's why I've decided to introduce these changes:
ShopifyGuard: Laravel provides many conveniences around when handling authentication through the framework, but the project in its current state bypasses Laravel's authentication (config/auth.phpis completely commented out). Not being able to leverage framework benefits hurts developer productivity, causes a lot of code redundancy, and makes testing a pain (if not impossible).testsdirectory despite having PHPUnit configured. Developers need to be able to write unit and feature tests. Developers should not have to resort to 100% manual testing. Enabling automated testing would decrease the number of bugs escaping into deployed Shopify apps and result in a better overall brand image.WHAT is this pull request doing?
ShopifyGuardto return the currently authenticated session.\App\Models\Sessionmodel extends\Illuminate\Foundation\Auth\Userand implements missinggetAuthIdentifierNameandgetAuthPasswordmethods.testsdirectory commonly found in fresh Laravel installations. Thetests/TestCase.phpclass contains an overriddenactingAsmethod that additionally injects a mock Authorization Bearer token. It also disables the Shopify middleware to allow requests in feature tests to reach the controller while still returning an authenticated\App\Models\Sessioninstance.config/services.php.Checklist
Note: once this PR is merged, it becomes a new release for this template.
README.mdfile and other related documentation, if applicable