Skip to content
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/v2 laravel middleware #96

Merged
merged 11 commits into from
Nov 2, 2022
Merged

Conversation

Sammyjo20
Copy link
Collaborator

No description provided.

@what-the-diff
Copy link

what-the-diff bot commented Nov 2, 2022

  • Added declare_strict_types to php-cs-fixer.dist
  • Updated composer dependencies and added ext-simplexml as a requirement for PHPInsights
  • Changed the SendRequest class to use strict types, updated comments and changed some variable names in order to make it more readable/understandable (e.g., SimulatedResponsePayload instead of SimulatedResponseData)
  • Removed the BaseMockClient class.
  • Added a new method to the SaloonManager.
  • Updated all references of $this->mockClient in favour of using this new method instead, which returns an instance of our mock client (which is now just a trait).
  • Added a new class called MockClient.
  • Moved the mock responses into their own arrays based on how they are captured (sequence, connector or request).
  • Removed all of the old methods and replaced them with more concise ones that use these collections to get/set data from them instead of using properties directly like before. This makes it easier for us to add additional capture types in future if we need too without having to change any existing code!
  • Refactored some other parts of this file so that it's cleaner and easier to read through as well as making sure everything is type hinted correctly where possible etc...
  • Added the ArrayStore interface
  • Made all contracts strict types
  • Added MiddlewarePipeline contract and implemented it in SaloonManager class
  • Created MockClient contract, which is used by the mock manager to store responses etc... This will be useful for testing purposes later on! :)
  • Added strict types to all files
  • Changed the return type of SaloonResponse::headers() from ArrayRepository to ArrayStore
  • Removed close method on SaloonResponse as it is not needed and was causing issues with mocking responses in tests (see https://github.com/sammyjo20/saloon-php/pulls?q=is%3Apr+is%3Aclosed)
  • Fixed a bug where FixtureData could not be created from a response due to incorrect parameters being passed into MockResponse constructor, also added new static factory methods for creating instances of FixtureData directly from Guzzle ResponseInterface or Sammyjo20\Saloon\Contracts\SaloonResponse objects
  • Added strict types to all files
  • Refactored MiddlewarePipeline class and added an interface for it
  • Removed the League\Pipeline dependency as we can use a simple array of callables instead (see Pipeline helper)
  • Fixed some type hints in various places, mostly where PendingSaloonRequest was used when SaloonConnector or SaloonRequest should have been used instead
  • Removed the Guzzle specific middleware.
  • Added a new AuthenticateMiddleware to handle authentication for all connectors, not just OAuth2 (which was previously handled in the GetAccessTokenRequest).
  • Moved FixtureRecorderMiddleware into its own file and updated it so that it can be used on both requests and responses now instead of only being able to record fixtures from within a request handler function (i.e when using MockClient::guessNextResponse()). This is because we want to support recording fixtures even if there are no mock responses available at all - i.e you may have an API endpoint which returns data but does not return any errors or exceptions etc... We also need this functionality as part of our test suite too! So I've added some tests around this feature too :)
  • Added strict types to all files.
  • Renamed SimulatedResponseData to SimulatedResponsePayload and updated references in the codebase accordingly.
  • Updated PendingSaloonRequest::bootPlugins() method so that it is called first, before merging properties from connector/request etc... This allows plugins on the request or connector to be able to modify any of these values if needed (e.g: Laravel plugin).
    4a) Moved AuthenticateMiddleware into its own file under Middleware directory as a class instead of an anonymous function within SaloonLaravelMiddleware - this makes testing easier for us! Also moved MockMiddleware out too for same reason as above :)
    4b) Changed order of middlewares being registered by default; now we register authenticate middleare then laravel specific one followed by mock client at end which means you can override authentication with your own custom implementation without having issues with mocking responses not working correctly anymore :D
  • Changed the SimulatedResponse class to use a new trait called Bootable.
  • Added an interface for SaloonConnector and implemented it in GuzzleSender, MockClient & TestClient classes.
  • Renamed SimulatedResponseData to SimulatedResponsePayload as this is more descriptive of what it does (holds data).
  • Removed some unused methods from PendingSaloonRequest that were not being used by any other codebase or tests - these are now handled within the connector itself instead of on each request object individually which makes sense since they're all using the same connector anyway! This also means we can remove another method from our base Request class too :) The only thing left there was boot() but I've moved that into its own trait so you don't have access anymore unless your child-class uses booting functionality like sending requests via connectors etc... It's just cleaner overall IMO because then when someone looks at their parent/child relationship between two objects they'll see exactly what traits are being used without having anything else mixed up with them."""
  • Removed LaravelManager class
  • Renamed ArrayRepository to ArrayStore and implemented the contract on it
  • Added strict types declaration at top of all files in src/ directory (except for composer autoloader)
  • Added strict types to all files.
  • Changed the name of a parameter in AcceptsJson trait from $request to $pendingRequest for consistency with other traits and classes that use this type hinting.
  • Updated ThrowPipe class so it implements an interface, which is then used as a callback instead of passing the entire class into onResponse(). This allows us to remove ThrowPipe entirely if we want (or replace it). It also makes testing easier because you can mock out just one method rather than mocking out an entire object/class!
  • Renamed getRegisteredRequests() method in ProxiesRequests trait from protected -> public so I could test against it directly without having to create another proxy request instance inside my tests - now I can call $this->getRegisteredRequests(); within any test where I'm using ProxyRequestTrait; or even better: expect($this)->toHaveMethod('getRegisteredRequests');. The latter assertion will fail if there's no such method available, meaning your IDE won't complain about missing methods when writing assertions like these anymore :)
  • Created new RecordsFixtures trait which contains some helper functions around recording fixtures during requests (e..g setting whether or not we're currently recording them etc.)
  • Added strict types to all files
  • Renamed MockResponse to SimulatedResponse and added a new class called FakeResponse which is used for caching responses
  • Changed the request pipe signature from SaloonRequest -> PendingSaloonRequest as we need access to the original connector/request object in order to cache it properly (we can't just use $pending->getConnector() because that will return an instance of Connector, not TestConnector)
  • Updated tests accordingly with changes above
  • Added strict types to all files
  • Removed unused methods from RequestSelectionConnector
  • Changed MockResponse constructor arguments for consistency with GuzzleHttp\Psr7\Response (https://github.com/guzzle/psr7#response-interface)
  • Fixed typo in README example code block
  • Added strict types to all files
  • Changed the UserResponse class to extend PsrResponse instead of SaloonResponse
  • Added strict types declaration at top of file for all files in diff
  • Created a new ArrayStoreTest test suite and added tests for it's methods (all pass)
  • Updated AsyncRequestTest so that it passes with changes made in this PR, also updated some comments/docs within the test itself as well as adding more assertions where appropriate
  • Updated AuthenticatesRequestsTest so that it passes with changes made in this PR, also updated some comments/docs within the test itself as well as adding more assertions where appropriate
  • Removed ContentBagTest.php
  • Changed FixtureDataTest to use strict types and changed the order of arguments in MockResponse constructor call
  • Added strict type declaration for HandlerTest, InterceptorTest & LaravelManager test files (removed LaravelManager file)
  • Renamed FixtureMockResponse to MockConfig and added a new method getFixturesDirectory which returns the fixtures directory path from config/saloon-mocks package configuration file
  • Updated MiddlewarePipeline tests with correct argument ordering for onRequest() & onResponse() methods as well as adding missing return statements where necessary - also updated addWhen() method signature so that it now takes an array instead of multiple parameters
  • Moved OAuth related classes into their own folder under src/Oauth2 namespace
  • Changed the namespace of ArrayRepository to Sammyjo20\Saloon\Repositories\ArrayStore
  • Added strict types declaration at top of each file
  • Removed unused use statements in RequestTest, SaloonRequestExceptionTest and StorageTest files

@Sammyjo20 Sammyjo20 merged commit 3375337 into v2 Nov 2, 2022
@Sammyjo20 Sammyjo20 deleted the feature/v2-laravel-middleware branch November 13, 2022 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant