[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
isOnline
flag 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.php
is 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).tests
directory 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?
ShopifyGuard
to return the currently authenticated session.\App\Models\Session
model extends\Illuminate\Foundation\Auth\User
and implements missinggetAuthIdentifierName
andgetAuthPassword
methods.tests
directory commonly found in fresh Laravel installations. Thetests/TestCase.php
class contains an overriddenactingAs
method 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\Session
instance.config/services.php
.Checklist
Note: once this PR is merged, it becomes a new release for this template.
README.md
file and other related documentation, if applicable