-
Notifications
You must be signed in to change notification settings - Fork 14
Adds Testing #75
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
Merged
Merged
Adds Testing #75
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The main goal of this PR is to bring test coverage to a respectable percent (8% -> 90%), and build in some mechanics to make it super simple to write tests for alchemy apps.
Sadly,
async
tests are still unavailable on Linux so I'll wait to merge this into main until then.I also updated how configs work (hopefully for the last time) to something that can be nicely isolated in independent config files.
Testing
There's tons of affordance for testing & making assertions on services like Database, Cache, Queue, Client, etc. Most of the interfaces are heavily inspired by Laravel.
There's a new
AlchemyTest
target that adds a bunch of convenience methods for mocking various service. Using theTestCase<MyApp>
target, you can easily test the various routes of your app.Client
The request builder functions for
TestCase
made perfect sense as a convenience wrapper aroundHTTPClient
, so there's a new Client class, with a default instance aliased toHttp
to make it easy to make HTTP requests.Configs
Previously, configs were all done in the
boot
function. It made things a messy and meant that lots of logic configuring separate services was in the same function. To keep configuration logic isolated on a per service basis, there's a newConfigurable
protocol to indicate a service for which your app has custom configurations. Services like Database, Cache, and Queue offer config types for your app to provide.Note the new database
Seeder
s.In tests, you can easily sub a more test appropriate interface of a service (in memory cache / queue, in memory SQLite database, etc) into your app's service container using
.fake()
methods inAlchemyTest
.This means that mocking your database with an in memory SQLite instance is breeze.