Skip to content

Commit

Permalink
remove obsolete legacy support no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Mar 25, 2024
1 parent c8e58e9 commit 74fb867
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 114 deletions.
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.

0 comments on commit 74fb867

Please sign in to comment.