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

Log and conventions improvements #21

Merged
merged 3 commits into from
Oct 2, 2023
Merged

Conversation

pionl
Copy link
Contributor

@pionl pionl commented Sep 29, 2023

Changelog

  • Contracts are reserved only for interfaces that are used with DI.
  • Add ability to prevent logging catched exception from a request in desired logger (Like FileLogger on "expected" exception).
  • Group requests in file log by hour and replace : with - (does not work on Mac)
  • Upgrade to PHPStan level 9
  • Use same text format for info / debug logger and
  • Log FAILED/OK text to detect "failed" requests without loosing status code (for connection resets 000 status code is used)
  • Moved logic for request sending to AbstractEndpoint (to allow better testability of code) and we can use endpoint as a immutable "builder".

Upgrade guide

Not full upgrade guide, check the changes.

Use PHPStan to find what to upgrade.

Removals

  • Remove array $overrideEndpoints = [] in your Api definition to make it more lighter (force to use environment)

Replace any usage in endpoints:

  • api->post => sendPost
  • api->get => sendGet
  • api->put => sendPut
  • api->delete => sendDelete

Replace usage of contract that were renamed to interface.

  • use WrkFlow\ApiSdkBuilder\Contracts\OptionsContract;=> use WrkFlow\ApiSdkBuilder\Interfaces\OptionsInterface;
  • Options implements OptionsContract => Options implements OptionsInterface
  • use WrkFlow\ApiSdkBuilder\Contracts\EnvironmentOverrideEndpointsContract; => use WrkFlow\ApiSdkBuilder\Interfaces\EnvironmentOverrideEndpointsInterface;
  • Environment implements EnvironmentOverrideEndpointsContract => Environment implements EnvironmentOverrideEndpointsInterface

Update __construct in any endpoint that is overriding __construct:

  • Replace ApiContract $api replace withEndpointDIEntity $di`
  • Fix fix the parent::construct($api) with parent::construct($di)

Other changes

  • AbstractApi $api usage is replaced with ApiInterface $api
  • TestingEnvironmentMock renamed to TestingEnvironment

TestExpectation

Use of mockery has been removed all test implementation has been added. To upgrade EndpointTestCase use this new universal syntax instead of different methods and expectation entity.

public function testEndpoint(): void
    {
        $this->assertEndpoint(
            call: fn(EndpointDIEntity $di) => (new JsonEndpoint($di))->success(),
            expectedUri: '/json',
            expectedHeaders: [
                'Content-Type' => ['application/json'],
                'Accept' => ['application/json'],
            ],
        );
    }

- Contracts are reserved only for interfaces that are used with DI.
- Add ability to prevent logging catched exception from a request in desired logger (Like FileLogger on "expected" exception).
- Group requests in file log by hour and replace : with - (does not work on Mac)
- Upgrade to PHPStan level 9
- Use same text format for info / debug logger and
- Log FAILED/OK text to detect "failed" requests without loosing status code (for connection resets 000 status code is used)
- Tests are now mockery free.
- Add more tests for Laravel container
@pionl pionl force-pushed the log-and-conventions-improvements branch from 3874a90 to a7d0244 Compare October 2, 2023 15:15
@pionl pionl merged commit a7d0244 into main Oct 2, 2023
7 checks passed
@pionl pionl deleted the log-and-conventions-improvements branch October 2, 2023 17:00
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