diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 00000000..974f5fa5 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1 @@ +preset: symfony diff --git a/src/CacheInvalidator.php b/src/CacheInvalidator.php index 4027c9e1..89969c77 100644 --- a/src/CacheInvalidator.php +++ b/src/CacheInvalidator.php @@ -76,7 +76,7 @@ class CacheInvalidator private $headerLength = 7500; /** - * Constructor + * Constructor. * * @param ProxyClientInterface $cache HTTP cache */ @@ -112,12 +112,12 @@ public function supports($operation) case self::INVALIDATE: return $this->cache instanceof BanInterface; default: - throw new InvalidArgumentException('Unknown operation ' . $operation); + throw new InvalidArgumentException('Unknown operation '.$operation); } } /** - * Set event dispatcher + * Set event dispatcher. * * @param EventDispatcherInterface $eventDispatcher * @@ -136,7 +136,7 @@ public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) } /** - * Get event dispatcher + * Get event dispatcher. * * @return EventDispatcherInterface */ @@ -150,7 +150,7 @@ public function getEventDispatcher() } /** - * Add subscriber + * Add subscriber. * * @param EventSubscriberInterface $subscriber * @@ -166,7 +166,7 @@ public function addSubscriber(EventSubscriberInterface $subscriber) } /** - * Set the HTTP header name that will hold cache tags + * Set the HTTP header name that will hold cache tags. * * @param string $tagsHeader * @@ -184,7 +184,7 @@ public function setTagsHeader($tagsHeader) } /** - * Get the HTTP header name that will hold cache tags + * Get the HTTP header name that will hold cache tags. * * @return string * @@ -196,7 +196,7 @@ public function getTagsHeader() } /** - * Invalidate a path or URL + * Invalidate a path or URL. * * @param string $path Path or URL * @param array $headers HTTP headers (optional) @@ -217,7 +217,7 @@ public function invalidatePath($path, array $headers = array()) } /** - * Refresh a path or URL + * Refresh a path or URL. * * @param string $path Path or URL * @param array $headers HTTP headers (optional) diff --git a/src/Event.php b/src/Event.php index 633af04f..ca850e9a 100644 --- a/src/Event.php +++ b/src/Event.php @@ -18,7 +18,7 @@ class Event extends BaseEvent private $exception; /** - * Set exception + * Set exception. * * @param \Exception $exception */ @@ -28,7 +28,7 @@ public function setException(\Exception $exception) } /** - * Get exception + * Get exception. * * @return \Exception */ diff --git a/src/EventListener/LogSubscriber.php b/src/EventListener/LogSubscriber.php index 28a40535..04e910de 100644 --- a/src/EventListener/LogSubscriber.php +++ b/src/EventListener/LogSubscriber.php @@ -36,7 +36,7 @@ public static function getSubscribedEvents() { return array( Events::PROXY_UNREACHABLE_ERROR => 'onProxyUnreachableError', - Events::PROXY_RESPONSE_ERROR => 'onProxyResponseError' + Events::PROXY_RESPONSE_ERROR => 'onProxyResponseError', ); } @@ -53,7 +53,7 @@ public function onProxyResponseError(Event $event) private function log($level, \Exception $exception) { $context = array( - 'exception' => $exception + 'exception' => $exception, ); $this->logger->log($level, $exception->getMessage(), $context); diff --git a/src/Events.php b/src/Events.php index eb9c518d..2610729e 100644 --- a/src/Events.php +++ b/src/Events.php @@ -12,10 +12,10 @@ namespace FOS\HttpCache; /** - * Events thrown by the FOSHttpCache library + * Events thrown by the FOSHttpCache library. */ final class Events { const PROXY_UNREACHABLE_ERROR = 'fos_http_cache.error.proxy_unreachable'; - const PROXY_RESPONSE_ERROR = 'fos_http_cache.error.response'; + const PROXY_RESPONSE_ERROR = 'fos_http_cache.error.response'; } diff --git a/src/Exception/ExceptionCollection.php b/src/Exception/ExceptionCollection.php index 44bb313b..155f900f 100644 --- a/src/Exception/ExceptionCollection.php +++ b/src/Exception/ExceptionCollection.php @@ -13,14 +13,14 @@ /** * A collection of exceptions that might occur during the flush operation of a - * ProxyClientInterface implementation + * ProxyClientInterface implementation. */ -class ExceptionCollection extends \Exception implements \IteratorAggregate, \Countable, HttpCacheExceptionInterface +class ExceptionCollection extends \Exception implements \IteratorAggregate, \Countable, HttpCacheExceptionInterface { private $exceptions = array(); /** - * Add an exception to the collection + * Add an exception to the collection. * * @param \Exception $e * @@ -48,11 +48,11 @@ public function getFirst() return $this->exceptions[0]; } - return null; + return; } /** - * Get exception iterator + * Get exception iterator. * * @return \ArrayIterator */ @@ -62,7 +62,7 @@ public function getIterator() } /** - * Get number of exceptions in collection + * Get number of exceptions in collection. * * @return int */ diff --git a/src/Exception/HttpCacheExceptionInterface.php b/src/Exception/HttpCacheExceptionInterface.php index fd9887c2..f86606f6 100644 --- a/src/Exception/HttpCacheExceptionInterface.php +++ b/src/Exception/HttpCacheExceptionInterface.php @@ -15,4 +15,5 @@ * Common interface for all exceptions thrown by this library. */ interface HttpCacheExceptionInterface -{} +{ +} diff --git a/src/Exception/InvalidUrlException.php b/src/Exception/InvalidUrlException.php index 6a4ba991..ad49258c 100644 --- a/src/Exception/InvalidUrlException.php +++ b/src/Exception/InvalidUrlException.php @@ -29,7 +29,7 @@ public static function invalidUrl($url, $reason = null) $msg .= sprintf('Reason: %s', $reason); } - return new InvalidUrlException($msg); + return new self($msg); } /** @@ -40,7 +40,7 @@ public static function invalidUrl($url, $reason = null) */ public static function invalidUrlParts($server, array $allowed) { - return new InvalidUrlException(sprintf( + return new self(sprintf( 'Server "%s" is invalid. Only %s URL parts are allowed.', $server, implode(', ', $allowed) @@ -56,7 +56,7 @@ public static function invalidUrlParts($server, array $allowed) */ public static function invalidUrlScheme($url, $scheme, array $allowed) { - return new InvalidUrlException(sprintf( + return new self(sprintf( 'Host "%s" with scheme "%s" is invalid. Only schemes "%s" are supported', $url, $scheme, diff --git a/src/Exception/MissingHostException.php b/src/Exception/MissingHostException.php index 0454ffbc..d1695bb3 100644 --- a/src/Exception/MissingHostException.php +++ b/src/Exception/MissingHostException.php @@ -26,11 +26,11 @@ public static function missingHost($path) { $msg = sprintf( 'Path "%s" cannot be invalidated without a host. ' - . 'Either invalidate full URLs containing hostnames instead of paths ' - . 'or configure the caching proxy class with a hostname in the base path.', + .'Either invalidate full URLs containing hostnames instead of paths ' + .'or configure the caching proxy class with a hostname in the base path.', $path ); - return new MissingHostException($msg); + return new self($msg); } } diff --git a/src/Exception/ProxyResponseException.php b/src/Exception/ProxyResponseException.php index 8ecc7ead..445ac7db 100644 --- a/src/Exception/ProxyResponseException.php +++ b/src/Exception/ProxyResponseException.php @@ -37,6 +37,6 @@ public static function proxyResponse($host, $statusCode, $statusMessage, $detail $message .= ". $details"; } - return new ProxyResponseException($message, $statusCode, $previous); + return new self($message, $statusCode, $previous); } } diff --git a/src/Exception/ProxyUnreachableException.php b/src/Exception/ProxyUnreachableException.php index 6c735306..3f1f94c5 100644 --- a/src/Exception/ProxyUnreachableException.php +++ b/src/Exception/ProxyUnreachableException.php @@ -36,7 +36,7 @@ public static function proxyUnreachable($host, $message, $details = '', \Excepti $message .= ". $details"; } - return new ProxyUnreachableException( + return new self( $message, 0, $previous diff --git a/src/Handler/TagHandler.php b/src/Handler/TagHandler.php index a8c43a7d..47566b7e 100644 --- a/src/Handler/TagHandler.php +++ b/src/Handler/TagHandler.php @@ -43,7 +43,7 @@ class TagHandler private $tags = array(); /** - * Constructor + * Constructor. * * @param CacheInvalidator $invalidator The invalidator instance. * @param string $tagsHeader Header to use for tags, defaults to X-Cache-Tags. @@ -137,7 +137,7 @@ public function invalidateTags(array $tags) * header length by the largest tag (minus 1 for the implode character) */ $tagsize = max(array_map('mb_strlen', $escapedTags)); - $elems = floor($this->headerLength / ($tagsize - 1)) ? : 1; + $elems = floor($this->headerLength / ($tagsize - 1)) ?: 1; } else { $elems = count($escapedTags); } diff --git a/src/ProxyClient/AbstractProxyClient.php b/src/ProxyClient/AbstractProxyClient.php index ebf81c33..957ca425 100644 --- a/src/ProxyClient/AbstractProxyClient.php +++ b/src/ProxyClient/AbstractProxyClient.php @@ -23,35 +23,35 @@ use Guzzle\Http\Message\RequestInterface; /** - * Guzzle-based abstract caching proxy client + * Guzzle-based abstract caching proxy client. * * @author David de Boer */ abstract class AbstractProxyClient implements ProxyClientInterface { /** - * IP addresses/hostnames of all caching proxy servers + * IP addresses/hostnames of all caching proxy servers. * * @var array */ private $servers; /** - * HTTP client + * HTTP client. * * @var ClientInterface */ private $client; /** - * Request queue + * Request queue. * * @var array|RequestInterface[] */ private $queue; /** - * Constructor + * Constructor. * * @param array $servers Caching proxy server hostnames or IP addresses, * including port if not port 80. @@ -73,7 +73,7 @@ public function __construct(array $servers, $baseUrl = null, ClientInterface $cl } /** - * Set caching proxy servers + * Set caching proxy servers. * * @param array $servers Caching proxy proxy server hostnames or IP * addresses, including port if not port 80. @@ -92,7 +92,7 @@ public function setServers(array $servers) /** * Set application hostname, optionally including a base URL, for purge and - * refresh requests + * refresh requests. * * @param string $url Your application’s base URL or hostname */ @@ -106,7 +106,7 @@ public function setBaseUrl($url) } /** - * Get application base URL + * Get application base URL. * * @return string Your application base url */ @@ -132,7 +132,7 @@ public function flush() } /** - * Add a request to the queue + * Add a request to the queue. * * @param string $method HTTP method * @param string $url URL @@ -163,7 +163,7 @@ private function getSignature($method, $url, array $headers) } /** - * Create request + * Create request. * * @param string $method HTTP method * @param string $url URL @@ -177,7 +177,7 @@ protected function createRequest($method, $url, array $headers = array()) } /** - * Sends all requests to each caching proxy server + * Sends all requests to each caching proxy server. * * Requests are sent in parallel to minimise impact on performance. * @@ -213,7 +213,7 @@ private function sendRequests(array $requests) } /** - * Handle request exception + * Handle request exception. * * @param GuzzleExceptionCollection $exceptions * @@ -253,7 +253,7 @@ protected function handleException(GuzzleExceptionCollection $exceptions) } /** - * Filter a URL + * Filter a URL. * * Prefix the URL with "http://" if it has no scheme, then check the URL * for validity. You can specify what parts of the URL are allowed. @@ -296,7 +296,7 @@ protected function filterUrl($url, array $allowedParts = array()) } /** - * Get default scheme + * Get default scheme. * * @return string */ @@ -306,7 +306,7 @@ protected function getDefaultScheme() } /** - * Get schemes allowed by caching proxy + * Get schemes allowed by caching proxy. * * @return string[] Array of schemes allowed by caching proxy, e.g. 'http' * or 'https' diff --git a/src/ProxyClient/Invalidation/BanInterface.php b/src/ProxyClient/Invalidation/BanInterface.php index 0f783d4a..58c472e9 100644 --- a/src/ProxyClient/Invalidation/BanInterface.php +++ b/src/ProxyClient/Invalidation/BanInterface.php @@ -15,7 +15,7 @@ /** * An HTTP cache that supports invalidation by banning, that is, removing - * objects from the cache that match a regular expression + * objects from the cache that match a regular expression. */ interface BanInterface extends ProxyClientInterface { @@ -23,7 +23,7 @@ interface BanInterface extends ProxyClientInterface const CONTENT_TYPE_ALL = self::REGEX_MATCH_ALL; /** - * Ban cached objects matching HTTP headers + * Ban cached objects matching HTTP headers. * * Each header is either a: * - regular string ('X-Host' => 'example.com') diff --git a/src/ProxyClient/Invalidation/PurgeInterface.php b/src/ProxyClient/Invalidation/PurgeInterface.php index 55017b18..be714ba0 100644 --- a/src/ProxyClient/Invalidation/PurgeInterface.php +++ b/src/ProxyClient/Invalidation/PurgeInterface.php @@ -23,7 +23,7 @@ interface PurgeInterface extends ProxyClientInterface { /** - * Purge a URL + * Purge a URL. * * Purging a URL will remove the cache for the URL (including the query string) * diff --git a/src/ProxyClient/Nginx.php b/src/ProxyClient/Nginx.php index dcb9e66d..ec17db55 100644 --- a/src/ProxyClient/Nginx.php +++ b/src/ProxyClient/Nginx.php @@ -22,9 +22,9 @@ */ class Nginx extends AbstractProxyClient implements PurgeInterface, RefreshInterface { - const HTTP_METHOD_PURGE = 'PURGE'; - const HTTP_METHOD_REFRESH = 'GET'; - const HTTP_HEADER_REFRESH = 'X-Refresh'; + const HTTP_METHOD_PURGE = 'PURGE'; + const HTTP_METHOD_REFRESH = 'GET'; + const HTTP_HEADER_REFRESH = 'X-Refresh'; /** * Path location that triggers purging. If false, same location purging is @@ -91,7 +91,7 @@ protected function getAllowedSchemes() } /** - * Create the correct URL to purge a resource + * Create the correct URL to purge a resource. * * @param string $url URL * diff --git a/src/ProxyClient/ProxyClientInterface.php b/src/ProxyClient/ProxyClientInterface.php index 6d0ca364..b193f590 100644 --- a/src/ProxyClient/ProxyClientInterface.php +++ b/src/ProxyClient/ProxyClientInterface.php @@ -14,7 +14,7 @@ use FOS\HttpCache\Exception\ExceptionCollection; /** - * An HTTP caching reverse proxy client + * An HTTP caching reverse proxy client. * * Implementations should implement at least one of the Invalidation interfaces. */ diff --git a/src/ProxyClient/Symfony.php b/src/ProxyClient/Symfony.php index d9125d8a..f7bdfe16 100644 --- a/src/ProxyClient/Symfony.php +++ b/src/ProxyClient/Symfony.php @@ -11,9 +11,6 @@ namespace FOS\HttpCache\ProxyClient; -use FOS\HttpCache\Exception\InvalidArgumentException; -use FOS\HttpCache\Exception\MissingHostException; -use FOS\HttpCache\ProxyClient\Invalidation\BanInterface; use FOS\HttpCache\ProxyClient\Invalidation\PurgeInterface; use FOS\HttpCache\ProxyClient\Invalidation\RefreshInterface; use FOS\HttpCache\SymfonyCache\PurgeSubscriber; @@ -38,7 +35,7 @@ class Symfony extends AbstractProxyClient implements PurgeInterface, RefreshInte private $options; /** - * {@inheritDoc} + * {@inheritdoc} * * When creating the client, you can configure options: * diff --git a/src/ProxyClient/Varnish.php b/src/ProxyClient/Varnish.php index 8b95b3ab..f98d2720 100644 --- a/src/ProxyClient/Varnish.php +++ b/src/ProxyClient/Varnish.php @@ -24,11 +24,11 @@ */ class Varnish extends AbstractProxyClient implements BanInterface, PurgeInterface, RefreshInterface { - const HTTP_METHOD_BAN = 'BAN'; - const HTTP_METHOD_PURGE = 'PURGE'; - const HTTP_METHOD_REFRESH = 'GET'; - const HTTP_HEADER_HOST = 'X-Host'; - const HTTP_HEADER_URL = 'X-Url'; + const HTTP_METHOD_BAN = 'BAN'; + const HTTP_METHOD_PURGE = 'PURGE'; + const HTTP_METHOD_REFRESH = 'GET'; + const HTTP_HEADER_HOST = 'X-Host'; + const HTTP_HEADER_URL = 'X-Url'; const HTTP_HEADER_CONTENT_TYPE = 'X-Content-Type'; /** @@ -37,9 +37,9 @@ class Varnish extends AbstractProxyClient implements BanInterface, PurgeInterfac * @var array */ private $defaultBanHeaders = array( - self::HTTP_HEADER_HOST => self::REGEX_MATCH_ALL, - self::HTTP_HEADER_URL => self::REGEX_MATCH_ALL, - self::HTTP_HEADER_CONTENT_TYPE => self::REGEX_MATCH_ALL + self::HTTP_HEADER_HOST => self::REGEX_MATCH_ALL, + self::HTTP_HEADER_URL => self::REGEX_MATCH_ALL, + self::HTTP_HEADER_CONTENT_TYPE => self::REGEX_MATCH_ALL, ); /** @@ -88,7 +88,7 @@ public function banPath($path, $contentType = null, $hosts = null) if (!count($hosts)) { throw new InvalidArgumentException('Either supply a list of hosts or null, but not an empty array.'); } - $hosts = '^('.join('|', $hosts).')$'; + $hosts = '^('.implode('|', $hosts).')$'; } $headers = array( @@ -131,7 +131,6 @@ public function refresh($url, array $headers = array()) * * @throws MissingHostException If a relative path is queued for purge/ * refresh and no base URL is set - * */ protected function createRequest($method, $url, array $headers = array()) { diff --git a/src/SymfonyCache/AccessControlledSubscriber.php b/src/SymfonyCache/AccessControlledSubscriber.php index 3016a07b..95c787b0 100644 --- a/src/SymfonyCache/AccessControlledSubscriber.php +++ b/src/SymfonyCache/AccessControlledSubscriber.php @@ -14,9 +14,6 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestMatcher; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; -use Symfony\Component\HttpKernel\HttpKernelInterface; /** * Base class for handlers for the symfony built-in HttpCache that need access @@ -64,7 +61,7 @@ public function __construct(RequestMatcher $requestMatcher = null, $ips = null) * * @param Request $request The request to check. * - * @return boolean Whether access is granted. + * @return bool Whether access is granted. */ protected function isRequestAllowed(Request $request) { diff --git a/src/SymfonyCache/EventDispatchingHttpCache.php b/src/SymfonyCache/EventDispatchingHttpCache.php index 065364cc..840e4608 100644 --- a/src/SymfonyCache/EventDispatchingHttpCache.php +++ b/src/SymfonyCache/EventDispatchingHttpCache.php @@ -38,7 +38,7 @@ abstract class EventDispatchingHttpCache extends HttpCache implements CacheInval private $eventDispatcher; /** - * Get event dispatcher + * Get event dispatcher. * * @return EventDispatcherInterface */ @@ -52,7 +52,7 @@ public function getEventDispatcher() } /** - * Add subscriber + * Add subscriber. * * @param EventSubscriberInterface $subscriber */ @@ -62,7 +62,7 @@ public function addSubscriber(EventSubscriberInterface $subscriber) } /** - * {@inheritDoc} + * {@inheritdoc} * * Adding the Events::PRE_HANDLE event. */ @@ -82,7 +82,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ /** * Made public to allow event subscribers to do refresh operations. * - * {@inheritDoc} + * {@inheritdoc} */ public function fetch(Request $request, $catch = false) { @@ -90,7 +90,7 @@ public function fetch(Request $request, $catch = false) } /** - * {@inheritDoc} + * {@inheritdoc} * * Adding the Events::PRE_INVALIDATE event. */ diff --git a/src/SymfonyCache/PurgeSubscriber.php b/src/SymfonyCache/PurgeSubscriber.php index 8e3cbd63..ea3d0233 100644 --- a/src/SymfonyCache/PurgeSubscriber.php +++ b/src/SymfonyCache/PurgeSubscriber.php @@ -11,11 +11,9 @@ namespace FOS\HttpCache\SymfonyCache; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestMatcher; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\OptionsResolver\OptionsResolver; /** diff --git a/src/SymfonyCache/RefreshSubscriber.php b/src/SymfonyCache/RefreshSubscriber.php index f9608228..4161d584 100644 --- a/src/SymfonyCache/RefreshSubscriber.php +++ b/src/SymfonyCache/RefreshSubscriber.php @@ -11,11 +11,8 @@ namespace FOS\HttpCache\SymfonyCache; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestMatcher; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\OptionsResolver\OptionsResolver; /** diff --git a/src/Test/NginxTestCase.php b/src/Test/NginxTestCase.php index 2eb4023f..a7f2054b 100644 --- a/src/Test/NginxTestCase.php +++ b/src/Test/NginxTestCase.php @@ -61,7 +61,7 @@ protected function getConfigFile() { if (!defined('NGINX_FILE')) { throw new \Exception('Specify the NGINX' - . ' configuration file path in phpunit.xml or override getConfigFile()'); + .' configuration file path in phpunit.xml or override getConfigFile()'); } // NGINX needs an absolute path @@ -69,7 +69,7 @@ protected function getConfigFile() } /** - * Defaults to "nginx" + * Defaults to "nginx". * * @return string */ @@ -89,7 +89,7 @@ protected function getCachingProxyPort() } /** - * Get NGINX cache directory + * Get NGINX cache directory. */ protected function getCacheDir() { @@ -118,7 +118,7 @@ protected function getProxy() } /** - * Get proxy client + * Get proxy client. * * @param string $purgeLocation Optional purgeLocation * @@ -128,7 +128,7 @@ protected function getProxyClient($purgeLocation = '') { if (null === $this->proxyClient) { $this->proxyClient = new Nginx( - array('http://127.0.0.1:' . $this->getCachingProxyPort()), + array('http://127.0.0.1:'.$this->getCachingProxyPort()), $this->getHostName(), $purgeLocation ); diff --git a/src/Test/PHPUnit/AbstractCacheConstraint.php b/src/Test/PHPUnit/AbstractCacheConstraint.php index 61d027d4..09838ccf 100644 --- a/src/Test/PHPUnit/AbstractCacheConstraint.php +++ b/src/Test/PHPUnit/AbstractCacheConstraint.php @@ -12,14 +12,14 @@ namespace FOS\HttpCache\Test\PHPUnit; /** - * Abstract cache constraint + * Abstract cache constraint. */ abstract class AbstractCacheConstraint extends \PHPUnit_Framework_Constraint { protected $header = 'X-Cache'; /** - * Constructor + * Constructor. * * @param string $header Cache debug header; defaults to X-Cache-Debug */ @@ -33,7 +33,7 @@ public function __construct($header = null) } /** - * Get cache header value + * Get cache header value. * * @return string */ @@ -48,7 +48,7 @@ protected function matches($other) throw new \RuntimeException( sprintf( 'Response has no "%s" header. Configure your caching proxy ' - . 'to set the header with cache hit/miss status.', + .'to set the header with cache hit/miss status.', $this->header ) ); @@ -62,6 +62,6 @@ protected function matches($other) */ protected function failureDescription($other) { - return (string) $other . ' ' . $this->toString(); + return (string) $other.' '.$this->toString(); } } diff --git a/src/Test/Proxy/AbstractProxy.php b/src/Test/Proxy/AbstractProxy.php index 0d804a23..74de3821 100644 --- a/src/Test/Proxy/AbstractProxy.php +++ b/src/Test/Proxy/AbstractProxy.php @@ -21,7 +21,7 @@ abstract class AbstractProxy implements ProxyInterface protected $ip = '127.0.0.1'; /** - * Wait for caching proxy to be started up and reachable + * Wait for caching proxy to be started up and reachable. * * @param string $ip * @param int $port @@ -48,7 +48,7 @@ function () use ($ip, $port) { } /** - * Wait for caching proxy to be started up and reachable + * Wait for caching proxy to be started up and reachable. * * @param string $ip * @param int $port @@ -77,7 +77,7 @@ function () use ($ip, $port) { protected function wait($timeout, $callback) { - for ($i = 0; $i < $timeout; $i++) { + for ($i = 0; $i < $timeout; ++$i) { if ($callback()) { return true; } @@ -89,7 +89,7 @@ protected function wait($timeout, $callback) } /** - * Run a shell command + * Run a shell command. * * @param string $command * @param array $arguments @@ -109,7 +109,6 @@ protected function runCommand($command, array $arguments) } } - /** * @param int $port */ @@ -127,7 +126,7 @@ public function getPort() } /** - * Set Varnish binary (defaults to varnishd) + * Set Varnish binary (defaults to varnishd). * * @param string $binary */ @@ -137,7 +136,7 @@ public function setBinary($binary) } /** - * Get Varnish binary + * Get Varnish binary. * * @return string */ @@ -146,9 +145,8 @@ public function getBinary() return $this->binary; } - /** - * Set IP address (defaults to 127.0.0.1) + * Set IP address (defaults to 127.0.0.1). * * @param string $ip */ @@ -158,7 +156,7 @@ public function setIp($ip) } /** - * Get IP address + * Get IP address. * * @return string */ @@ -175,7 +173,7 @@ public function getIp() public function setConfigFile($configFile) { if (!file_exists($configFile)) { - throw new \InvalidArgumentException('Cannot find config file: ' . $configFile); + throw new \InvalidArgumentException('Cannot find config file: '.$configFile); } $this->configFile = $configFile; diff --git a/src/Test/Proxy/NginxProxy.php b/src/Test/Proxy/NginxProxy.php index 5192eb3b..1686504d 100644 --- a/src/Test/Proxy/NginxProxy.php +++ b/src/Test/Proxy/NginxProxy.php @@ -20,14 +20,14 @@ class NginxProxy extends Abstractproxy protected $cacheDir; /** - * Constructor + * Constructor. * * @param string $configFile Path to NGINX configuration file */ public function __construct($configFile) { $this->setConfigFile($configFile); - $this->setCacheDir(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'foshttpcache-nginx'); + $this->setCacheDir(sys_get_temp_dir().DIRECTORY_SEPARATOR.'foshttpcache-nginx'); } /** @@ -38,8 +38,8 @@ public function start() $this->runCommand( $this->getBinary(), array( - '-c', $this->getConfigFile() , - '-g', 'pid ' . $this->pid . ';' + '-c', $this->getConfigFile(), + '-g', 'pid '.$this->pid.';', ) ); diff --git a/src/Test/Proxy/ProxyInterface.php b/src/Test/Proxy/ProxyInterface.php index 4e20e59f..52e35d6a 100644 --- a/src/Test/Proxy/ProxyInterface.php +++ b/src/Test/Proxy/ProxyInterface.php @@ -12,22 +12,22 @@ namespace FOS\HttpCache\Test\Proxy; /** - * Controls a HTTP caching proxy server + * Controls a HTTP caching proxy server. */ interface ProxyInterface { /** - * Start the proxy server + * Start the proxy server. */ public function start(); /** - * Stop the proxy server + * Stop the proxy server. */ public function stop(); /** - * Clear all cached content from the proxy server + * Clear all cached content from the proxy server. */ public function clear(); } diff --git a/src/Test/Proxy/SymfonyProxy.php b/src/Test/Proxy/SymfonyProxy.php index ffc6c42f..4b861828 100644 --- a/src/Test/Proxy/SymfonyProxy.php +++ b/src/Test/Proxy/SymfonyProxy.php @@ -20,17 +20,17 @@ class SymfonyProxy implements ProxyInterface { /** - * Get Symfony cache directory + * Get Symfony cache directory. * * @return string */ public function getCacheDir() { - return defined('SYMFONY_CACHE_DIR') ? SYMFONY_CACHE_DIR : sys_get_temp_dir() . '/foshttpcache-symfony'; + return defined('SYMFONY_CACHE_DIR') ? SYMFONY_CACHE_DIR : sys_get_temp_dir().'/foshttpcache-symfony'; } /** - * Start the proxy server + * Start the proxy server. */ public function start() { @@ -38,7 +38,7 @@ public function start() } /** - * Stop the proxy server + * Stop the proxy server. */ public function stop() { @@ -46,14 +46,14 @@ public function stop() } /** - * Clear all cached content from the proxy server + * Clear all cached content from the proxy server. */ public function clear() { if (is_dir($this->getCacheDir())) { $path = realpath($this->getCacheDir()); if (!$this->getCacheDir() || '/' == $path) { - throw new \Exception('Invalid test setup, the cache dir is ' . $path); + throw new \Exception('Invalid test setup, the cache dir is '.$path); } if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { system('DEL /S '.$path); diff --git a/src/Test/Proxy/VarnishProxy.php b/src/Test/Proxy/VarnishProxy.php index 93e13468..b6544b4e 100644 --- a/src/Test/Proxy/VarnishProxy.php +++ b/src/Test/Proxy/VarnishProxy.php @@ -25,14 +25,14 @@ class VarnishProxy extends AbstractProxy protected $cacheDir; /** - * Constructor + * Constructor. * * @param string $configFile Path to VCL file */ public function __construct($configFile) { $this->setConfigFile($configFile); - $this->setCacheDir(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'foshttpcache-varnish'); + $this->setCacheDir(sys_get_temp_dir().DIRECTORY_SEPARATOR.'foshttpcache-varnish'); } /** @@ -43,12 +43,12 @@ public function start() $this->runCommand( $this->getBinary(), array( - '-a', $this->ip . ':' . $this->getPort(), - '-T', $this->ip . ':' . $this->getManagementPort(), + '-a', $this->ip.':'.$this->getPort(), + '-T', $this->ip.':'.$this->getManagementPort(), '-f', $this->getConfigFile(), '-n', $this->getCacheDir(), - '-p', 'vcl_dir=' . $this->getConfigDir(), - '-P', $this->pid + '-p', 'vcl_dir='.$this->getConfigDir(), + '-P', $this->pid, ) ); @@ -101,7 +101,7 @@ public function getConfigDir() } /** - * Set Varnish management port (defaults to 6182) + * Set Varnish management port (defaults to 6182). * * @param int $managementPort */ @@ -111,7 +111,7 @@ public function setManagementPort($managementPort) } /** - * Get Varnish management port + * Get Varnish management port. * * @return int */ @@ -121,7 +121,7 @@ public function getManagementPort() } /** - * Set Varnish cache directory + * Set Varnish cache directory. * * @param string $cacheDir */ @@ -131,7 +131,7 @@ public function setCacheDir($cacheDir) } /** - * Get Varnish cache directory + * Get Varnish cache directory. * * @return string */ diff --git a/src/Test/ProxyTestCase.php b/src/Test/ProxyTestCase.php index 073ed5a6..53706508 100644 --- a/src/Test/ProxyTestCase.php +++ b/src/Test/ProxyTestCase.php @@ -17,8 +17,7 @@ use Guzzle\Http\Message\Response; /** - * Abstract caching proxy test case - * + * Abstract caching proxy test case. */ abstract class ProxyTestCase extends \PHPUnit_Framework_TestCase { @@ -30,7 +29,7 @@ abstract class ProxyTestCase extends \PHPUnit_Framework_TestCase protected $httpClient; /** - * Assert a cache miss + * Assert a cache miss. * * @param Response $response * @param string $message Test failure message (optional) @@ -41,7 +40,7 @@ public function assertMiss(Response $response, $message = null) } /** - * Assert a cache hit + * Assert a cache hit. * * @param Response $response * @param string $message Test failure message (optional) @@ -62,7 +61,7 @@ public static function isCacheMiss() } /** - * Get HTTP response from your application + * Get HTTP response from your application. * * @param string $url * @param array $headers @@ -76,7 +75,7 @@ public function getResponse($url, array $headers = array(), $options = array()) } /** - * Get HTTP client for your application + * Get HTTP client for your application. * * @return Client */ @@ -84,7 +83,7 @@ public function getHttpClient() { if (null === $this->httpClient) { $this->httpClient = new Client( - 'http://' . $this->getHostName() . ':' . $this->getCachingProxyPort(), + 'http://'.$this->getHostName().':'.$this->getCachingProxyPort(), array('curl.options' => array(CURLOPT_FORBID_REUSE => true)) ); } @@ -93,7 +92,7 @@ public function getHttpClient() } /** - * Start the proxy server and reset any cached content + * Start the proxy server and reset any cached content. */ protected function setUp() { @@ -101,7 +100,7 @@ protected function setUp() } /** - * Stop the proxy server + * Stop the proxy server. */ protected function tearDown() { @@ -109,7 +108,7 @@ protected function tearDown() } /** - * Get the hostname where your application can be reached + * Get the hostname where your application can be reached. * * @throws \Exception * @@ -125,21 +124,21 @@ protected function getHostName() } /** - * Get proxy server + * Get proxy server. * * @return \FOS\HttpCache\Test\Proxy\ProxyInterface */ abstract protected function getProxy(); /** - * Get proxy client + * Get proxy client. * * @return \FOS\HttpCache\ProxyClient\ProxyClientInterface */ abstract protected function getProxyClient(); /** - * Get port that caching proxy listens on + * Get port that caching proxy listens on. * * @return int */ diff --git a/src/Test/SymfonyTestCase.php b/src/Test/SymfonyTestCase.php index 5141f555..cca29ad7 100644 --- a/src/Test/SymfonyTestCase.php +++ b/src/Test/SymfonyTestCase.php @@ -44,7 +44,7 @@ abstract class SymfonyTestCase extends ProxyTestCase protected $proxy; /** - * Get server port + * Get server port. * * @return int * @@ -72,7 +72,7 @@ protected function getProxy() } /** - * Get Symfony proxy client + * Get Symfony proxy client. * * We use a non-default method for PURGE because the built-in PHP webserver * does not allow arbitrary HTTP methods. @@ -84,8 +84,8 @@ protected function getProxyClient() { if (null === $this->proxyClient) { $this->proxyClient = new Symfony( - array('http://127.0.0.1:' . $this->getCachingProxyPort()), - $this->getHostName() . ':' . $this->getCachingProxyPort(), + array('http://127.0.0.1:'.$this->getCachingProxyPort()), + $this->getHostName().':'.$this->getCachingProxyPort(), null, array('purge_method' => 'NOTIFY') ); diff --git a/src/Test/VarnishTestCase.php b/src/Test/VarnishTestCase.php index 9297f577..21eabce3 100644 --- a/src/Test/VarnishTestCase.php +++ b/src/Test/VarnishTestCase.php @@ -67,7 +67,7 @@ protected function getConfigFile() } /** - * Get Varnish binary + * Get Varnish binary. * * @return string */ @@ -77,7 +77,7 @@ protected function getBinary() } /** - * Get Varnish port + * Get Varnish port. * * @return int */ @@ -87,7 +87,7 @@ protected function getCachingProxyPort() } /** - * Get Varnish management port + * Get Varnish management port. * * @return int */ @@ -97,7 +97,7 @@ protected function getVarnishMgmtPort() } /** - * Get Varnish cache directory + * Get Varnish cache directory. * * @return string */ @@ -107,7 +107,7 @@ protected function getCacheDir() } /** - * Defaults to 3 + * Defaults to 3. * * @return int */ @@ -144,7 +144,7 @@ protected function getProxy() } /** - * Get Varnish proxy client + * Get Varnish proxy client. * * @return Varnish */ @@ -152,8 +152,8 @@ protected function getProxyClient() { if (null === $this->proxyClient) { $this->proxyClient = new Varnish( - array('http://127.0.0.1:' . $this->getProxy()->getPort()), - $this->getHostName() . ':' . $this->getProxy()->getPort() + array('http://127.0.0.1:'.$this->getProxy()->getPort()), + $this->getHostName().':'.$this->getProxy()->getPort() ); } diff --git a/src/UserContext/ContextProviderInterface.php b/src/UserContext/ContextProviderInterface.php index c1c47507..e96818e8 100644 --- a/src/UserContext/ContextProviderInterface.php +++ b/src/UserContext/ContextProviderInterface.php @@ -12,7 +12,7 @@ namespace FOS\HttpCache\UserContext; /** - * Allow a class to update a user context + * Allow a class to update a user context. */ interface ContextProviderInterface { diff --git a/src/UserContext/HashGenerator.php b/src/UserContext/HashGenerator.php index 57ff02f3..97a0fc56 100644 --- a/src/UserContext/HashGenerator.php +++ b/src/UserContext/HashGenerator.php @@ -14,7 +14,7 @@ use FOS\HttpCache\Exception\InvalidArgumentException; /** - * Generate a hash for a UserContext by getting all the parameters needed across all registered services + * Generate a hash for a UserContext by getting all the parameters needed across all registered services. */ class HashGenerator { @@ -24,7 +24,7 @@ class HashGenerator private $providers = array(); /** - * Constructor + * Constructor. * * @param ContextProviderInterface[] $providers * @@ -42,7 +42,7 @@ public function __construct(array $providers) } /** - * Collect UserContext parameters and generate a hash from that + * Collect UserContext parameters and generate a hash from that. * * @return string The hash generated */ @@ -59,11 +59,11 @@ public function generateHash() // Sort by key (alphanumeric), as order should not make hash vary ksort($parameters); - return hash("sha256", serialize($parameters)); + return hash('sha256', serialize($parameters)); } /** - * Register a provider to be called for updating a UserContext before generating the Hash + * Register a provider to be called for updating a UserContext before generating the Hash. * * @param ContextProviderInterface $provider A context provider to be called to get context information about the current request. */ diff --git a/src/UserContext/UserContext.php b/src/UserContext/UserContext.php index 52da10aa..16ba9e2e 100644 --- a/src/UserContext/UserContext.php +++ b/src/UserContext/UserContext.php @@ -12,7 +12,7 @@ namespace FOS\HttpCache\UserContext; /** - * A UserContext is a set of parameters which allow to determinate different views for an url + * A UserContext is a set of parameters which allow to determinate different views for an url. * * For example a menu can be different if a user is authenticated or not, * in this case the UserContext should have a authenticated parameter set @@ -23,7 +23,7 @@ class UserContext implements \IteratorAggregate private $parameters = array(); /** - * Set a parameter for this context + * Set a parameter for this context. * * @param string $key Parameter identifier * @param mixed $value Parameter value (it should be serializable) @@ -34,7 +34,7 @@ public function addParameter($key, $value) } /** - * Set all the parameters of this context + * Set all the parameters of this context. * * @param array $parameters */ @@ -44,11 +44,11 @@ public function setParameters(array $parameters) } /** - * Determine whether a parameter exists + * Determine whether a parameter exists. * * @param string $key * - * @return boolean + * @return bool */ public function hasParameter($key) { @@ -56,7 +56,7 @@ public function hasParameter($key) } /** - * Return all parameters of this context + * Return all parameters of this context. * * @return array */ diff --git a/tests/Functional/Fixtures/Symfony/AppCache.php b/tests/Functional/Fixtures/Symfony/AppCache.php index 090fa872..6bc04dd4 100644 --- a/tests/Functional/Fixtures/Symfony/AppCache.php +++ b/tests/Functional/Fixtures/Symfony/AppCache.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace FOS\HttpCache\Tests\Functional\Fixtures\Symfony; use FOS\HttpCache\SymfonyCache\EventDispatchingHttpCache; diff --git a/tests/Functional/Fixtures/Symfony/AppKernel.php b/tests/Functional/Fixtures/Symfony/AppKernel.php index e518a286..6fa292e8 100644 --- a/tests/Functional/Fixtures/Symfony/AppKernel.php +++ b/tests/Functional/Fixtures/Symfony/AppKernel.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace FOS\HttpCache\Tests\Functional\Fixtures\Symfony; use Symfony\Component\HttpFoundation\Request; @@ -14,7 +23,7 @@ class AppKernel implements HttpKernelInterface /** * This simplistic kernel handles the request immediately inline. * - * {@inheritDoc} + * {@inheritdoc} */ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) { diff --git a/tests/Functional/Fixtures/web/symfony.php b/tests/Functional/Fixtures/web/symfony.php index 4a5c1c5b..9bc715de 100644 --- a/tests/Functional/Fixtures/web/symfony.php +++ b/tests/Functional/Fixtures/web/symfony.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use FOS\HttpCache\SymfonyCache\PurgeSubscriber; use FOS\HttpCache\SymfonyCache\RefreshSubscriber; use FOS\HttpCache\SymfonyCache\UserContextSubscriber; diff --git a/tests/Functional/Fixtures/web/user_context.php b/tests/Functional/Fixtures/web/user_context.php index c93c9d70..739a0b2e 100644 --- a/tests/Functional/Fixtures/web/user_context.php +++ b/tests/Functional/Fixtures/web/user_context.php @@ -13,20 +13,20 @@ if (isset($_GET['accept'])) { if ($_GET['accept'] != $_SERVER['HTTP_ACCEPT']) { - header('HTTP/1.1 500 Wrong accept header "' . $_SERVER['HTTP_ACCEPT'] . '", expected "' . $_GET['accept'] . '"'); + header('HTTP/1.1 500 Wrong accept header "'.$_SERVER['HTTP_ACCEPT'].'", expected "'.$_GET['accept'].'"'); exit; } } elseif (isset($_SERVER['HTTP_ACCEPT'])) { - header('HTTP/1.1 500 Expected no accept header ' . $_SERVER['HTTP_ACCEPT']); + header('HTTP/1.1 500 Expected no accept header '.$_SERVER['HTTP_ACCEPT']); exit; } if ('POST' == strtoupper($_SERVER['REQUEST_METHOD'])) { - echo "POST"; + echo 'POST'; exit; } -if (!isset($_COOKIE[0]) || ($_COOKIE[0] != "foo" && $_COOKIE[0] != "bar")) { +if (!isset($_COOKIE[0]) || ($_COOKIE[0] != 'foo' && $_COOKIE[0] != 'bar')) { header('HTTP/1.1 403'); exit; } @@ -34,10 +34,10 @@ header('Cache-Control: max-age=3600'); header('Vary: X-User-Context-Hash'); -if ($_COOKIE[0] == "foo") { +if ($_COOKIE[0] == 'foo') { header('X-HashTest: foo'); - echo "foo"; + echo 'foo'; } else { header('X-HashTest: bar'); - echo "bar"; + echo 'bar'; } diff --git a/tests/Functional/Fixtures/web/user_context_anon.php b/tests/Functional/Fixtures/web/user_context_anon.php index 21737596..f874950f 100644 --- a/tests/Functional/Fixtures/web/user_context_anon.php +++ b/tests/Functional/Fixtures/web/user_context_anon.php @@ -16,11 +16,11 @@ if (!isset($_COOKIE[0])) { header('X-HashTest: anonymous'); - echo "anonymous"; -} elseif ($_COOKIE[0] == "foo") { + echo 'anonymous'; +} elseif ($_COOKIE[0] == 'foo') { header('X-HashTest: foo'); - echo "foo"; + echo 'foo'; } else { header('X-HashTest: bar'); - echo "bar"; + echo 'bar'; } diff --git a/tests/Functional/NginxProxyClientTest.php b/tests/Functional/NginxProxyClientTest.php index a760e55a..1387a267 100644 --- a/tests/Functional/NginxProxyClientTest.php +++ b/tests/Functional/NginxProxyClientTest.php @@ -17,7 +17,7 @@ * @group webserver * @group nginx */ -class NginxTest extends NginxTestCase +class NginxProxyClientTest extends NginxTestCase { public function testPurgeSeparateLocationPath() { diff --git a/tests/Functional/SymfonyProxyClientTest.php b/tests/Functional/SymfonyProxyClientTest.php index d4561a20..2e798b8c 100644 --- a/tests/Functional/SymfonyProxyClientTest.php +++ b/tests/Functional/SymfonyProxyClientTest.php @@ -52,7 +52,7 @@ public function testPurgeContentType() public function testPurgeHost() { - $symfony = new Symfony(array('http://127.0.0.1:' . $this->getCachingProxyPort()), null, null, array('purge_method' => 'NOTIFY')); + $symfony = new Symfony(array('http://127.0.0.1:'.$this->getCachingProxyPort()), null, null, array('purge_method' => 'NOTIFY')); $this->getResponse('/symfony.php/cache'); diff --git a/tests/Functional/Varnish/UserContextCacheTest.php b/tests/Functional/Varnish/UserContextCacheTest.php index a7865e5e..267862ef 100644 --- a/tests/Functional/Varnish/UserContextCacheTest.php +++ b/tests/Functional/Varnish/UserContextCacheTest.php @@ -28,7 +28,7 @@ protected function getConfigFile() } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function assertContextCache($status) { diff --git a/tests/Functional/Varnish/UserContextFailureTest.php b/tests/Functional/Varnish/UserContextFailureTest.php index 085f7bde..40395b28 100644 --- a/tests/Functional/Varnish/UserContextFailureTest.php +++ b/tests/Functional/Varnish/UserContextFailureTest.php @@ -44,7 +44,7 @@ public function testUserContextNoExposeHash() array('cookies' => array('miam')) ); - $this->fail("Request should have failed with a 400 response.\n\n" . $response->getRawHeaders() . "\n" . $response->getBody(true)); + $this->fail("Request should have failed with a 400 response.\n\n".$response->getRawHeaders()."\n".$response->getBody(true)); } catch (ClientErrorResponseException $e) { $this->assertEquals(400, $e->getResponse()->getStatusCode()); $this->assertFalse($e->getResponse()->hasHeader('X-User-Context-Hash')); @@ -63,7 +63,7 @@ public function testUserContextNoForgedHash() array('cookies' => array('miam')) ); - $this->fail("Request should have failed with a 400 response.\n\n" . $response->getRawHeaders() . "\n" . $response->getBody(true)); + $this->fail("Request should have failed with a 400 response.\n\n".$response->getRawHeaders()."\n".$response->getBody(true)); } catch (ClientErrorResponseException $e) { $this->assertEquals(400, $e->getResponse()->getStatusCode()); } @@ -92,7 +92,7 @@ public function testHashRequestFailure() try { $response = $this->getResponse('/user_context.php', array(), array('cookies' => array('foo'))); - $this->fail("Request should have failed with a 500 response.\n\n" . $response->getRawHeaders() . "\n" . $response->getBody(true)); + $this->fail("Request should have failed with a 500 response.\n\n".$response->getRawHeaders()."\n".$response->getBody(true)); } catch (ServerErrorResponseException $e) { $this->assertEquals(503, $e->getResponse()->getStatusCode()); } diff --git a/tests/Functional/Varnish/UserContextNocacheTest.php b/tests/Functional/Varnish/UserContextNocacheTest.php index 5cfb1be3..77942ffe 100644 --- a/tests/Functional/Varnish/UserContextNocacheTest.php +++ b/tests/Functional/Varnish/UserContextNocacheTest.php @@ -28,7 +28,7 @@ protected function getConfigFile() } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function assertContextCache($status) { diff --git a/tests/Functional/Varnish/UserContextTestCase.php b/tests/Functional/Varnish/UserContextTestCase.php index 8f5d7e94..4097e83e 100644 --- a/tests/Functional/Varnish/UserContextTestCase.php +++ b/tests/Functional/Varnish/UserContextTestCase.php @@ -99,7 +99,6 @@ public function testAcceptHeader() array('cookies' => array('foo')) ); $this->assertEquals('foo', $response1->getBody(true)); - } public function testUserContextUnauthorized() diff --git a/tests/Functional/Varnish/VarnishProxyClientTest.php b/tests/Functional/Varnish/VarnishProxyClientTest.php index b6a80e2b..7328e634 100644 --- a/tests/Functional/Varnish/VarnishProxyClientTest.php +++ b/tests/Functional/Varnish/VarnishProxyClientTest.php @@ -104,7 +104,7 @@ public function testPurgeContentType() public function testPurgeHost() { - $varnish = new Varnish(array('http://127.0.0.1:' . $this->getProxy()->getPort())); + $varnish = new Varnish(array('http://127.0.0.1:'.$this->getProxy()->getPort())); $this->getResponse('/cache.php'); diff --git a/tests/Functional/WebServerListener.php b/tests/Functional/WebServerListener.php index dc9a5f9b..06ac077b 100644 --- a/tests/Functional/WebServerListener.php +++ b/tests/Functional/WebServerListener.php @@ -12,7 +12,7 @@ namespace FOS\HttpCache\Tests\Functional; /** - * A PHPUnit test listener that starts and stops the PHP built-in web server + * A PHPUnit test listener that starts and stops the PHP built-in web server. * * This listener is configured with a couple of constants from the phpunit.xml * file. To define constants in the phpunit file, use this syntax: @@ -27,7 +27,7 @@ class WebServerListener implements \PHPUnit_Framework_TestListener { /** - * PHP web server PID + * PHP web server PID. * * @var int */ @@ -35,7 +35,7 @@ class WebServerListener implements \PHPUnit_Framework_TestListener /** * Make sure the PHP built-in web server is running for tests with group - * 'webserver' + * 'webserver'. */ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) { @@ -52,24 +52,47 @@ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) $this->pid = $pid = $this->startPhpWebServer(); register_shutdown_function(function () use ($pid) { - exec('kill ' . $pid); + exec('kill '.$pid); }); } /** - * We don't need these + * We don't need these. */ - public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) {} - public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time) {} - public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time) {} - public function addIncompleteTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) {} - public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) {} - public function startTest(\PHPUnit_Framework_Test $test) {} - public function endTest(\PHPUnit_Framework_Test $test, $time) {} - public function addRiskyTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) {} + public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) + { + } + + public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time) + { + } + + public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time) + { + } + + public function addIncompleteTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) + { + } + + public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) + { + } + + public function startTest(\PHPUnit_Framework_Test $test) + { + } + + public function endTest(\PHPUnit_Framework_Test $test, $time) + { + } + + public function addRiskyTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) + { + } /** - * Get web server hostname + * Get web server hostname. * * @throws \Exception * @@ -85,7 +108,7 @@ protected function getHostName() } /** - * Get web server port + * Get web server port. * * @throws \Exception * @@ -101,7 +124,7 @@ protected function getPort() } /** - * Get web server port + * Get web server port. * * @throws \Exception * @@ -117,7 +140,7 @@ protected function getDocRoot() } /** - * Start PHP built-in web server + * Start PHP built-in web server. * * @return int PID */ @@ -137,7 +160,7 @@ protected function startPhpWebServer() } /** - * Wait for caching proxy to be started up and reachable + * Wait for caching proxy to be started up and reachable. * * @param string $ip * @param int $port @@ -147,7 +170,7 @@ protected function startPhpWebServer() */ protected function waitFor($ip, $port, $timeout) { - for ($i = 0; $i < $timeout; $i++) { + for ($i = 0; $i < $timeout; ++$i) { if (@fsockopen($ip, $port)) { return; } @@ -157,7 +180,7 @@ protected function waitFor($ip, $port, $timeout) $client = new \Guzzle\Http\Client(); $url = sprintf('http://%s:%d/cache.php', $this->getHostName(), $this->getPort()); - for (; $i < $timeout; $i++) { + for (; $i < $timeout; ++$i) { try { if ($client->get($url)->send()->isSuccessful()) { return; diff --git a/tests/Unit/CacheInvalidatorTest.php b/tests/Unit/CacheInvalidatorTest.php index 876e1c43..67037286 100644 --- a/tests/Unit/CacheInvalidatorTest.php +++ b/tests/Unit/CacheInvalidatorTest.php @@ -18,7 +18,6 @@ use FOS\HttpCache\Exception\ProxyUnreachableException; use FOS\HttpCache\Exception\UnsupportedProxyOperationException; use FOS\HttpCache\ProxyClient\Varnish; -use \Mockery; use Symfony\Component\EventDispatcher\EventDispatcher; class CacheInvalidatorTest extends \PHPUnit_Framework_TestCase @@ -185,7 +184,7 @@ public function testMethodException() public function testProxyClientExceptionsAreLogged() { $unreachableException = ProxyUnreachableException::proxyUnreachable('http://127.0.0.1', 'Couldn\'t connect to host'); - $responseException = ProxyResponseException::proxyResponse('http://127.0.0.1', 403, 'Forbidden'); + $responseException = ProxyResponseException::proxyResponse('http://127.0.0.1', 403, 'Forbidden'); $exceptions = new ExceptionCollection(); $exceptions->add($unreachableException)->add($responseException); @@ -202,7 +201,7 @@ public function testProxyClientExceptionsAreLogged() 'critical', 'Request to caching proxy at http://127.0.0.1 failed with message "Couldn\'t connect to host"', array( - 'exception' => $unreachableException + 'exception' => $unreachableException, ) ) ->shouldReceive('log')->once() diff --git a/tests/Unit/ProxyClient/AbstractProxyClientTest.php b/tests/Unit/ProxyClient/AbstractProxyClientTest.php index 8b356729..6d1bfe91 100644 --- a/tests/Unit/ProxyClient/AbstractProxyClientTest.php +++ b/tests/Unit/ProxyClient/AbstractProxyClientTest.php @@ -20,7 +20,7 @@ use Guzzle\Plugin\Mock\MockPlugin; use Guzzle\Http\Message\Response; use Guzzle\Http\Message\Request; -use \Mockery; +use Mockery; /** * Testing the base methods of the proxy client, using the Varnish client as concrete class. @@ -65,6 +65,7 @@ public function curlExceptionProvider() $curlException = new CurlException('curl'); $curlException->setRequest(new Request('GET', '/')); + return array( array($curlException, '\FOS\HttpCache\Exception\ProxyUnreachableException'), array($requestException, '\FOS\HttpCache\Exception\ProxyResponseException'), @@ -206,7 +207,7 @@ public function testFlushCountSuccess() ->with( \Mockery::on( function ($requests) use ($self) { - /** @type Request[] $requests */ + /* @type Request[] $requests */ $self->assertCount(4, $requests); foreach ($requests as $request) { $self->assertEquals('PURGE', $request->getMethod()); @@ -238,7 +239,7 @@ public function testEliminateDuplicates() ->with( \Mockery::on( function ($requests) use ($self) { - /** @type Request[] $requests */ + /* @type Request[] $requests */ $self->assertCount(4, $requests); foreach ($requests as $request) { $self->assertEquals('PURGE', $request->getMethod()); @@ -263,7 +264,6 @@ function ($requests) use ($self) { ); } - protected function setUp() { $this->mock = new MockPlugin(); diff --git a/tests/Unit/ProxyClient/SymfonyTest.php b/tests/Unit/ProxyClient/SymfonyTest.php index 2fe4d726..8313f65d 100644 --- a/tests/Unit/ProxyClient/SymfonyTest.php +++ b/tests/Unit/ProxyClient/SymfonyTest.php @@ -11,17 +11,11 @@ namespace FOS\HttpCache\Tests\Unit\ProxyClient; -use FOS\HttpCache\Exception\ExceptionCollection; use FOS\HttpCache\ProxyClient\Symfony; -use FOS\HttpCache\ProxyClient\Varnish; use Guzzle\Http\Client; -use Guzzle\Http\Exception\CurlException; -use Guzzle\Http\Exception\MultiTransferException; -use Guzzle\Http\Exception\RequestException; use Guzzle\Plugin\Mock\MockPlugin; use Guzzle\Http\Message\Response; use Guzzle\Http\Message\Request; -use \Mockery; class SymfonyTest extends \PHPUnit_Framework_TestCase { @@ -41,7 +35,7 @@ public function testPurge() ->with( \Mockery::on( function ($requests) use ($self) { - /** @type Request[] $requests */ + /* @type Request[] $requests */ $self->assertCount(4, $requests); foreach ($requests as $request) { $self->assertEquals('PURGE', $request->getMethod()); diff --git a/tests/Unit/ProxyClient/VarnishTest.php b/tests/Unit/ProxyClient/VarnishTest.php index 92c4def0..d1fa7783 100644 --- a/tests/Unit/ProxyClient/VarnishTest.php +++ b/tests/Unit/ProxyClient/VarnishTest.php @@ -11,16 +11,11 @@ namespace FOS\HttpCache\Tests\Unit\ProxyClient; -use FOS\HttpCache\Exception\ExceptionCollection; use FOS\HttpCache\ProxyClient\Varnish; use Guzzle\Http\Client; -use Guzzle\Http\Exception\CurlException; -use Guzzle\Http\Exception\MultiTransferException; -use Guzzle\Http\Exception\RequestException; use Guzzle\Plugin\Mock\MockPlugin; use Guzzle\Http\Message\Response; use Guzzle\Http\Message\Request; -use \Mockery; class VarnishTest extends \PHPUnit_Framework_TestCase { @@ -120,7 +115,7 @@ public function testPurge() ->with( \Mockery::on( function ($requests) use ($self) { - /** @type Request[] $requests */ + /* @type Request[] $requests */ $self->assertCount(4, $requests); foreach ($requests as $request) { $self->assertEquals('PURGE', $request->getMethod()); diff --git a/tests/Unit/SymfonyCache/EventDispatchingHttpCacheTest.php b/tests/Unit/SymfonyCache/EventDispatchingHttpCacheTest.php index 6660961a..690bd2c0 100644 --- a/tests/Unit/SymfonyCache/EventDispatchingHttpCacheTest.php +++ b/tests/Unit/SymfonyCache/EventDispatchingHttpCacheTest.php @@ -28,7 +28,7 @@ protected function getHttpCachePartialMock(array $mockedMethods = null) { $mock = $this ->getMockBuilder('\FOS\HttpCache\SymfonyCache\EventDispatchingHttpCache') - ->setMethods( $mockedMethods ) + ->setMethods($mockedMethods) ->disableOriginalConstructor() ->getMock() ; @@ -37,7 +37,7 @@ protected function getHttpCachePartialMock(array $mockedMethods = null) $options = array( 'debug' => false, 'default_ttl' => 0, - 'private_headers' => array( 'Authorization', 'Cookie' ), + 'private_headers' => array('Authorization', 'Cookie'), 'allow_reload' => false, 'allow_revalidate' => false, 'stale_while_revalidate' => 2, @@ -51,7 +51,7 @@ protected function getHttpCachePartialMock(array $mockedMethods = null) } else { $refOptions = $refHttpCache->getProperty('options'); $refOptions->setAccessible(true); - $refOptions->setValue($mock, $options ); + $refOptions->setValue($mock, $options); } return $mock; @@ -163,7 +163,7 @@ public static function getSubscribedEvents() { return array( Events::PRE_HANDLE => 'preHandle', - Events::PRE_INVALIDATE => 'preInvalidate' + Events::PRE_INVALIDATE => 'preInvalidate', ); } @@ -174,7 +174,7 @@ public function preHandle(CacheEvent $event) if ($this->handleResponse) { $event->setResponse($this->handleResponse); } - $this->handleHits++; + ++$this->handleHits; } public function preInvalidate(CacheEvent $event) @@ -184,6 +184,6 @@ public function preInvalidate(CacheEvent $event) if ($this->invalidateResponse) { $event->setResponse($this->invalidateResponse); } - $this->invalidateHits++; + ++$this->invalidateHits; } } diff --git a/tests/Unit/SymfonyCache/UserContextSubscriberTest.php b/tests/Unit/SymfonyCache/UserContextSubscriberTest.php index be50d502..e8618a8e 100644 --- a/tests/Unit/SymfonyCache/UserContextSubscriberTest.php +++ b/tests/Unit/SymfonyCache/UserContextSubscriberTest.php @@ -51,11 +51,11 @@ public function provideConfigOptions() 'user_hash_header' => 'test/header', 'user_hash_accept_header' => 'test accept', 'anonymous_hash' => 'test hash', - );; + ); return array( array(array(), $options), - array($custom, $custom + $options) + array($custom, $custom + $options), ); } @@ -127,7 +127,7 @@ public function testUserHashUserWithSession($arg, $options) $cookies = array( 'PHPSESSID' => $sessionId1, 'PHPSESSIDsdiuhsdf4535d4f' => $sessionId2, - 'foo' => 'bar' + 'foo' => 'bar', ); $cookieString = "PHPSESSID=$sessionId1; foo=bar; PHPSESSIDsdiuhsdf4535d4f=$sessionId2"; $request = Request::create('/foo', 'GET', array(), $cookies, array(), array('Cookie' => $cookieString)); @@ -148,7 +148,7 @@ public function testUserHashUserWithSession($arg, $options) $hashResponse = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Response') ->setMethods(array('prepare')) ->getMock(); - $hashResponse->headers->set($options['user_hash_header'], $expectedContextHash ); + $hashResponse->headers->set($options['user_hash_header'], $expectedContextHash); $that = $this; $this->kernel @@ -198,7 +198,7 @@ public function testUserHashUserWithAuthorizationHeader($arg, $options) $expectedContextHash = 'my_generated_hash'; $hashResponse = new Response(); - $hashResponse->headers->set($options['user_hash_header'], $expectedContextHash ); + $hashResponse->headers->set($options['user_hash_header'], $expectedContextHash); $that = $this; $this->kernel diff --git a/tests/Unit/Test/PHPUnit/AbstractCacheConstraintTest.php b/tests/Unit/Test/PHPUnit/AbstractCacheConstraintTest.php index 5dc5290b..50f8295d 100644 --- a/tests/Unit/Test/PHPUnit/AbstractCacheConstraintTest.php +++ b/tests/Unit/Test/PHPUnit/AbstractCacheConstraintTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace FOS\HttpCache\Tests\Unit\Test\PHPUnit; abstract class AbstractCacheConstraintTest extends \PHPUnit_Framework_TestCase diff --git a/tests/Unit/UserContext/UserContextTest.php b/tests/Unit/UserContext/UserContextTest.php index e90c91be..4d9c4246 100644 --- a/tests/Unit/UserContext/UserContextTest.php +++ b/tests/Unit/UserContext/UserContextTest.php @@ -34,7 +34,7 @@ public function testSetParameters() $userContext->addParameter('authenticated', true); $userContext->setParameters(array( 'roles' => array('ROLE_USER'), - 'foo' => 'bar' + 'foo' => 'bar', )); $this->assertFalse($userContext->hasParameter('authenticated')); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4445933d..24fcbce4 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -11,7 +11,7 @@ $file = __DIR__.'/../vendor/autoload.php'; if (!file_exists($file)) { - throw new RuntimeException("Install dependencies using composer to run the test suite."); + throw new RuntimeException('Install dependencies using composer to run the test suite.'); } if (!defined('VARNISH_FILE')) {