|
3 | 3 | Testing Your Application
|
4 | 4 | ========================
|
5 | 5 |
|
6 |
| -This chapter describes how to test your application against a Varnish instance. |
| 6 | +This chapter describes how to test your application against you reverse proxy |
| 7 | +instance. |
7 | 8 |
|
8 |
| -VarnishTestCase |
9 |
| ---------------- |
| 9 | +The FOSHttpCache library provides base test case classes to help you write |
| 10 | +functional tests. This may be helpful to test the way your application sets |
| 11 | +caching headers and invalidates cached content. |
10 | 12 |
|
11 |
| -The FOSHttpCache library provides a base test case to help you write functional |
12 |
| -tests against a Varnish instance. This may be helpful to test the way your |
13 |
| -application sets caching headers and invalidates cached content. |
| 13 | +By having your test classes extend one of the testCase classes, you get: |
14 | 14 |
|
15 |
| -By having your test classes extend ``VarnishTestCase``, you get: |
16 |
| - |
17 |
| -* independent tests: all previously cached content is removed by restarting |
18 |
| - Varnish in the test setUp method |
19 |
| -* ``$this->varnish`` referring to an instance of this library’s Varnish client |
20 |
| - that is configured to talk to your Varnish server |
| 15 | +* independent tests: all previously cached content is removed in the tests |
| 16 | + ``setUp`` method. The way this is done depends on which reverse proxy you use; |
| 17 | +* an instance of this library’s client that is configured to talk to your |
| 18 | + reverse proxy server. See reverse proxy specific sections for details; |
21 | 19 | * convenience methods for executing HTTP requests to your application:
|
22 |
| - ``$this->getHttpClient()`` and ``$this->getResponse()`` |
| 20 | + ``$this->getHttpClient()`` and ``$this->getResponse()``; |
23 | 21 | * custom assertions ``assertHit`` and ``assertMiss`` for validating a cache hit/miss.
|
24 | 22 |
|
25 |
| -Configuration |
26 |
| -------------- |
27 |
| - |
28 |
| -By default, the ``VarnishTestCase`` starts and stops a Varnish server for you. |
29 |
| -All you have to do, is to refer the class to your Varnish configuration (VCL) |
30 |
| -file. The recommended way to configure the test case is by setting constants |
31 |
| -in your `phpunit.xml`. Alternatively, you can override the getter methods: |
32 |
| - |
33 |
| -======================= ========================= ============ ========================================== |
34 |
| -Constant Getter Default Description |
35 |
| -======================= ========================= ============ ========================================== |
36 |
| -``VARNISH_FILE`` ``getConfigFile()`` your Varnish configuration (VCL) file |
37 |
| -``VARNISH_BINARY`` ``getBinary()`` ``varnishd`` your Varnish binary |
38 |
| -``VARNISH_PORT`` ``getCachingProxyPort()`` ``6181`` port Varnish listens on |
39 |
| -``VARNISH_MGMT_PORT`` ``getVarnishMgmtPort()`` ``6182`` Varnish management port |
40 |
| -``WEB_SERVER_HOSTNAME`` ``getHostName()`` hostname your application can be reached at |
41 |
| -======================= ========================= ============ ========================================== |
| 23 | +The recommended way to configure the test case is by setting constants |
| 24 | +in your `phpunit.xml`. Alternatively, you can override the getter methods. |
42 | 25 |
|
43 | 26 | Setting Constants
|
44 | 27 | ~~~~~~~~~~~~~~~~~
|
@@ -67,13 +50,63 @@ You can override getters in your test class in the following way::
|
67 | 50 | }
|
68 | 51 | }
|
69 | 52 |
|
| 53 | +VarnishTestCase |
| 54 | +--------------- |
| 55 | + |
| 56 | +Configuration |
| 57 | +''''''''''''' |
| 58 | + |
| 59 | +By default, the ``VarnishTestCase`` starts and stops a Varnish server for you. |
| 60 | +All you have to do is to set your Varnish configuration (VCL) file. |
| 61 | + |
| 62 | +======================= ========================= ================================================== ============================================ |
| 63 | +Constant Getter Default Description |
| 64 | +======================= ========================= ================================================== ============================================ |
| 65 | +``VARNISH_FILE`` ``getConfigFile()`` your Varnish configuration (VCL) file |
| 66 | +``VARNISH_BINARY`` ``getBinary()`` ``varnishd`` your Varnish binary |
| 67 | +``VARNISH_PORT`` ``getCachingProxyPort()`` ``6181`` port Varnish listens on |
| 68 | +``VARNISH_MGMT_PORT`` ``getVarnishMgmtPort()`` ``6182`` Varnish management port |
| 69 | +``VARNISH_CACHE_DIR`` ``getCacheDir()`` ``sys_get_temp_dir()`` + ``/foshttpcache-varnish`` directory to use for cache |
| 70 | +``VARNISH_VERSION`` ``getVarnishVersion()`` ``3`` installed varnish application version |
| 71 | +``WEB_SERVER_HOSTNAME`` ``getHostName()`` hostname your application can be reached at |
| 72 | +======================= ========================= ================================================== ============================================ |
| 73 | + |
70 | 74 | Enable Assertions
|
71 |
| -~~~~~~~~~~~~~~~~~ |
| 75 | +''''''''''''''''' |
72 | 76 |
|
73 | 77 | For the `assertHit` and `assertMiss` assertions to work, you should add a
|
74 | 78 | :ref:`custom X-Debug header <varnish_debugging>` to responses served
|
75 | 79 | by your Varnish.
|
76 | 80 |
|
| 81 | +NginxTestCase |
| 82 | +------------- |
| 83 | + |
| 84 | +Configuration |
| 85 | +''''''''''''' |
| 86 | + |
| 87 | +By default, the ``NginxTestCase`` starts and stops NGINX server for you and deletes |
| 88 | +all cached contents. You have to set your NGINX configuration file. |
| 89 | + |
| 90 | +These are all the configurations you can change |
| 91 | + |
| 92 | +======================= ========================= ================================================ ========================================== |
| 93 | +Constant Getter Default Description |
| 94 | +======================= ========================= ================================================ ========================================== |
| 95 | +``NGINX_FILE`` ``getConfigFile()`` your NGINX configuration file |
| 96 | +``NGINX_BINARY`` ``getBinary()`` ``nginx`` your NGINX binary |
| 97 | +``NGINX_PORT`` ``getCachingProxyPort()`` ``8088`` port NGINX listens on |
| 98 | +``NGINX_CACHE_PATH`` ``getCacheDir()`` ``sys_get_temp_dir()`` + ``/foshttpcache-nginx`` directory to use for cache |
| 99 | + Must match `proxy_cache_path` directive in |
| 100 | + your configuration file. |
| 101 | +``WEB_SERVER_HOSTNAME`` ``getHostName()`` hostname your application can be reached at |
| 102 | +======================= ========================= ================================================ ========================================== |
| 103 | + |
| 104 | +Enable Assertions |
| 105 | +''''''''''''''''' |
| 106 | + |
| 107 | +For the `assertHit` and `assertMiss` assertions to work, you should add the HTTP |
| 108 | +header ``X-Cache`` to your responses |
| 109 | + |
77 | 110 | Usage
|
78 | 111 | -----
|
79 | 112 |
|
@@ -127,7 +160,6 @@ correctly::
|
127 | 160 | $this->assertMiss($this->getResponse($url));
|
128 | 161 | }
|
129 | 162 |
|
130 |
| - |
| 163 | +Tests for Nginx look the same but extend the NginxTestCase. |
131 | 164 | For more ideas, see this library’s functional tests in the
|
132 | 165 | :source:`tests/Functional/` directory.
|
133 |
| - |
|
0 commit comments