Skip to content

Commit 2ef29fe

Browse files
committed
Merge pull request #218 from FriendsOfSymfony/test-traits
Provide test functionality in traits
2 parents 33db556 + faecba4 commit 2ef29fe

15 files changed

+954
-651
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
1212
* In ProxyTestCase, `getHttpClient()` has been replaced with `getHttpAdapter()`;
1313
added HTTP method parameter to `getResponse()`.
1414
* Changed default Varnish version to 4.
15+
* Added support and documentation for setting a custom TTL specifically for the
16+
caching proxy.
17+
* Refactored the proxy client test system into traits. Removed ProxyTestCase,
18+
use the traits `CacheAssertions` and `HttpCaller` instead.
1519

1620
1.4.0
1721
-----

doc/includes/symfony-process.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Requires Symfony’s Process component, so make sure to include that in your
2+
project:
3+
4+
.. code-block:: bash
5+
6+
$ composer require symfony/process

doc/proxy-clients.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Then pass that adapter to the caching proxy client::
6666
$proxyClient = new Varnish($servers, '/baseUrl', $adapter);
6767
// Varnish as example, but also possible for NGINX and Symfony
6868

69+
.. _varnish client:
70+
6971
Varnish Client
7072
~~~~~~~~~~~~~~
7173

doc/symfony-cache-configuration.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,34 @@ but you can customize that in the subscriber constructor::
196196

197197
The custom header is removed before sending the response to the client.
198198

199+
.. _symfony-cache x-debugging:
200+
201+
Debugging
202+
~~~~~~~~~
203+
204+
For the ``assertHit`` and ``assertMiss`` assertions to work, you need to add
205+
debug information in your AppCache. Create the cache kernel with the option
206+
``'debug' => true`` and add the following to your ``AppCache``::
207+
208+
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
209+
{
210+
$response = parent::handle($request, $type, $catch);
211+
212+
if ($response->headers->has('X-Symfony-Cache')) {
213+
if (false !== strpos($response->headers->get('X-Symfony-Cache'), 'miss')) {
214+
$state = 'MISS';
215+
} elseif (false !== strpos($response->headers->get('X-Symfony-Cache'), 'fresh')) {
216+
$state = 'HIT';
217+
} else {
218+
$state = 'UNDETERMINED';
219+
}
220+
$response->headers->set('X-Cache', $state);
221+
}
222+
223+
return $response;
224+
}
225+
226+
The ``UNDETERMINED`` state should never happen. If it does, it means that your
227+
HttpCache is not correctly set into debug mode.
228+
199229
.. _HttpCache: http://symfony.com/doc/current/book/http_cache.html#symfony-reverse-proxy

0 commit comments

Comments
 (0)