-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
Feature | Add Context To Fixtures #444
base: v3
Are you sure you want to change the base?
Conversation
I haven'T tested for compatibility with #425 but there shouldn't be any real conflicts. |
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.
I don't see any issues.
But is it worth changing the added types to be nullable, as PHP 8.4 will deprecate implicit nullable types?
I guess it's better to keep it consistent, and fix them all at once in the future, but thought I'd mention it.
Hey @Gummibeer - thanks for this PR, and sorry for the delay, life has been really busy. I will have a look through this and hopefully soon we can merge it in. |
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.
I don't see any issues tbh!
@Gummibeer Seems like something is up with the tests 🤔 Obviously no rush but if you get a spare 5 minutes it'll be good if you could take a look please? (Btw I have merged the latest of v3 into your branch) |
PR for our telegram conversation.
This allows us to have context on fixture files. If you have a general/dynamic connector mock for your tests you will end up with a bunch of fixtures you have no idea where they belong to. It is even worse when you use some payload hashing as below.
As you can see each different request will end up with a corresponding fixture - but you won't be able to tell from a fixture where it belongs to, if it's still needed or anything.
That's where fixture context comes in handy - you can add whatever context you want that will be persisted in your fixture files - for example the plain payload or the name of the test it was used in or anything else.
You can do so by chaining
withContext()
on your fixture instance.usage examples
You have access to the underlying
ArrayStore
viagetContext()
and can use all the methods available there to manipulate or interact with the context. For sure you can also usegetContext()
to retrieve a specific context value.The context isn't used anywhere in Saloon itself - it's only made available and persisted so that you can check it manually or do some checks in your own code with it. So everything you do with it is up to you - only restriction: it has to be JSONable.