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

remove obsolete legacy support no longer needed #564

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/SymfonyCache/RefreshListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ public static function getSubscribedEvents(): array
public function handleRefresh(CacheEvent $event): void
{
$request = $event->getRequest();
// BC - we can drop this check when we only support Symfony 3.1 and newer
$cacheable = method_exists(Request::class, 'isMethodCacheable')
? $request->isMethodCacheable()
: $request->isMethodSafe(false);

if (!$cacheable
if (!$request->isMethodCacheable()
|| !$request->isNoCache()
|| !$this->isRequestAllowed($request)
) {
Expand Down
22 changes: 0 additions & 22 deletions src/Test/Legacy/PHPUnit/AbstractCacheConstraint.php

This file was deleted.

61 changes: 49 additions & 12 deletions src/Test/PHPUnit/AbstractCacheConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,56 @@
namespace FOS\HttpCache\Test\PHPUnit;

use PHPUnit\Framework\Constraint\Constraint;
use Psr\Http\Message\ResponseInterface;

if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
/*
* Using an early return instead of a else does not work when using the PHPUnit phar due to some weird PHP behavior
* (the class gets defined without executing the code before it and so the definition is not properly conditional)
*/
class_alias('FOS\HttpCache\Test\Legacy\PHPUnit\AbstractCacheConstraint', 'FOS\HttpCache\Test\PHPUnit\AbstractCacheConstraint');
} else {
/**
* Abstract cache constraint.
*/
abstract class AbstractCacheConstraint extends Constraint
abstract class AbstractCacheConstraint extends Constraint
{
protected string $header;

public function __construct(string $header = 'X-Cache')
{
$this->header = $header;
}

public function matches($other): bool
{
if (!$other instanceof ResponseInterface) {
throw new \InvalidArgumentException('compare must compare with '.ResponseInterface::class.' got '.get_debug_type($other));
}
if (!$other->hasHeader($this->header)) {
$message = sprintf(
'Response has no "%s" header. Configure your caching proxy '
.'to set the header with cache hit/miss status.',
$this->header
);
if (200 !== $other->getStatusCode()) {
$message .= sprintf("\nStatus code of response is %s.", $other->getStatusCode());
}

$message .= "\nThe response headers are:\n\n";

foreach ($other->getHeaders() as $name => $values) {
foreach ($values as $value) {
$message .= $name.': '.$value."\n";
}
}

$body = $other->getBody();
$body->rewind();
$message .= sprintf("\nThe response body is:\n\n %s", $body->getContents());

throw new \RuntimeException($message);
}

return str_contains($other->getHeaderLine($this->header), $this->getValue());
}

public function failureDescription($other): string
{
use AbstractCacheConstraintTrait;
return sprintf(
'response (with status code %s) %s',
$other->getStatusCode(),
$this->toString()
);
}
}
74 changes: 0 additions & 74 deletions src/Test/PHPUnit/AbstractCacheConstraintTrait.php

This file was deleted.

Loading