-
Notifications
You must be signed in to change notification settings - Fork 1
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 #15 from carsdotcom/cache-seed-not-configurable
fix: cache key seed must increment regardless of config of host project
- Loading branch information
Showing
5 changed files
with
127 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Shared assertions about test cases. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Carsdotcom\ApiRequest\Testing; | ||
|
||
use Carsdotcom\ApiRequest\AbstractRequest; | ||
use Illuminate\Support\Facades\Cache; | ||
|
||
trait RequestClassAssertions | ||
{ | ||
/** | ||
* Create a fake cache entry for a given request. | ||
*/ | ||
protected static function mockRequestCachedResponse( | ||
AbstractRequest $request, | ||
string $body, | ||
int $status = 200, | ||
array $headers = [], | ||
array $logs = [], | ||
): void { | ||
$tags = getProperty($request, 'cacheTags'); | ||
Cache::tags($tags)->put($request->cacheKey(), [ | ||
'logs' => $logs, | ||
'response' => [$status, $headers, $body], | ||
]); | ||
} | ||
|
||
/** | ||
* Fetch the cached response to a request and assert that it contains a substring | ||
*/ | ||
protected static function assertRequestCacheBodyContains( | ||
string $substring, | ||
AbstractRequest $request, | ||
string $message = '', | ||
): void { | ||
$cached = callMethod($request, 'responseFromCache'); | ||
self::assertNotNull($cached, 'Cache should not be empty for request.'); | ||
self::assertStringContainsString($substring, (string) $cached->getBody(), $message); | ||
} | ||
} |
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