generated from Sammyjo20/package-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Sammyjo20/fix/allow-body-to-be-used-in-ca…
…che-key Fix | Allow body to be used in cache key
- Loading branch information
Showing
7 changed files
with
106 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./app</directory> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache"> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">./app</directory> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Saloon\CachePlugin\Tests\Fixtures\Requests; | ||
|
||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use League\Flysystem\Filesystem; | ||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
use Saloon\Contracts\PendingRequest; | ||
use Saloon\CachePlugin\Contracts\Driver; | ||
use Saloon\CachePlugin\Traits\HasCaching; | ||
use Saloon\CachePlugin\Contracts\Cacheable; | ||
use Saloon\CachePlugin\Drivers\FlysystemDriver; | ||
use League\Flysystem\Local\LocalFilesystemAdapter; | ||
use Saloon\CachePlugin\Tests\Fixtures\Connectors\TestConnector; | ||
|
||
class BodyCacheKeyRequest extends Request implements Cacheable, HasBody | ||
{ | ||
use HasCaching; | ||
use HasJsonBody; | ||
|
||
protected ?string $connector = TestConnector::class; | ||
|
||
protected Method $method = Method::GET; | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/user'; | ||
} | ||
|
||
public function resolveCacheDriver(): Driver | ||
{ | ||
return new FlysystemDriver(new Filesystem(new LocalFilesystemAdapter(cachePath()))); | ||
} | ||
|
||
public function cacheExpiryInSeconds(): int | ||
{ | ||
return 60; | ||
} | ||
|
||
protected function cacheKey(PendingRequest $pendingRequest): ?string | ||
{ | ||
return (string)$pendingRequest->body()->all(); | ||
} | ||
} |