-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add ProxyTestCase #122
Add ProxyTestCase #122
Conversation
</call> | ||
<call method="setPort"> | ||
<argument>%fos_http_cache.proxy_server.varnish.port%</argument> | ||
</call> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other setters may need to be added here, depending on the config that we allow.
cool idea! i guess we just have to live with a bit of duplication. this will need some documentation and we might add one or two integration tests using this test case to the bundle so that the test infrastructure is tested and people can find an example. |
<argument type="collection"> | ||
<argument key="%fos_http_cache.proxy_process.curlopt_forbid_reuse%">true</argument> | ||
</argument> | ||
</service> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add the test client under proxy_server
instead, or reorganise our service names in another way? Now we have proxy_client
, proxy_server
, and proxy.test_client
. I imagine this will get confusing for people. 😉
And perhaps this test client could be combined with the custom guzzle_client
for the proxy client, after all: they are constructed the same way. What if we always construct a guzzle_client
, custom or not, and use that as the test client, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we need the same client for tests as for the application. could be wrong for some projects.
for the naming, i would prefer to say fos_http_cache.test.proxy_server.varnish
. its not meant to control the "real" varnish through php, and we should not even suggest that this could be a good idea. then it would be test.proxy_server
and test.proxy_server.client
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s keep the clients separate, then.
I now have fos_http_cache.proxy.test_client.varnish
, but I like your suggestion of prefixing with test
instead. This yields the following config.yml
, which makes it really clear that this is for testing purposes only:
fos_http_cache:
test:
proxy_server:
varnish: ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -6,6 +6,9 @@ | |||
|
|||
<parameters> | |||
<parameter key="fos_http_cache.proxy_client.varnish.class">FOS\HttpCache\ProxyClient\Varnish</parameter> | |||
<parameter key="fos_http_cache.proxy_client.varnish.test_client.class">Guzzle\Http\Client</parameter> | |||
<parameter key="fos_http_cache.proxy_server.varnish.class">FOS\HttpCache\Test\Proxy\VarnishProxy</parameter> | |||
<parameter key="fos_http_cache.proxy_process.curlopt_forbid_reuse" type="constant">CURLOPT_FORBID_REUSE</parameter> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just inline that? (this is a real question, not rhetorical ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that doesn't seem to work with PHP constants. Or do you know a way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, seems so. okay, learned something :-)
i restarted the build now that the PR on the component is merged. once this is merged, its time for RC1 i would say. |
Yep, RC here we come. I hope to have this ready later today. |
@dbu Have a look, especially at the config structure and docs. If you agree, I’ll write some config tests so we can merge this. |
->defaultValue('X-Cache') | ||
->info('HTTP cache hit/miss header') | ||
->end() | ||
->arrayNode('proxy_server') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
->info('Configure how the caching proxy instance should be started for your tests')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
cool, i think this is good. added some notes, and the tests are failing - apart from that lets squash and merge. |
|
||
**type**: ``string`` **required** | ||
|
||
Path to a VCL file. For example Varnish configurations, see |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we only have one for the whole project? or can we also test with specific vcl files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one. Do you think having more would make sense? I think we only need to offer testing against a production-like Varnish setup, so only one VCL (with possible includes). I know that we test against multiple VCLs in the library (especially user context), but there it makes sense: we’re testing the library’s compatibility with different kinds of VCLs. This kind of testing should not be done by users of the bundle, in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, good point. i agree.
Squashed. Have a look and merge when happy. Scrutinizer score dropped quite a bit, but I propose to merge this first and then go over all issues one more time (configuration near-duplication being the hardest, I guess). Would by nice to tag this RC soonish, as I’m using this in a project now. 😄 |
* | ||
* @return \Guzzle\Http\Client | ||
*/ | ||
public function getClient() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getClient and getProxyClient are the same. i would vote for the explicit getProxyClient. and a protected method, its not supposed to be called from outside.
They return different services. Do you mean we should drop the test client and only use proxy client? I think we decided to keep the test client separate. |
ups, i got confused, sorry. should we call this getTestClient and have a line in the phpdoc explaining what it is for? |
Should we then rename |
that would make sense. getClient is so generic, it does not mean much. sorry, i am confused again: what does getClient return? a symfony web client to talk to the test varnish server? or a httpcache proxy client to talk to the test varnish server? if the later, what is the difference to the normal proxy client? |
Heh this confusion perhaps calls for more extensive docs on this feature. :) getClient()/getTestClient() returns a Guzzle HTTP client that has base_url (as configured under proxy_client) as it's endpoint. You can use this to test calls (mostly GET/HEAD) to the backend application through a live proxy. getProxyClient() returns an instance of our Varnish or Nginx ProxyClient classes (which are wrapped by the CacheManager). These can be used to do manual purge, ban etc., though I think you shouldn't want to do this in application tests (of course, in our lib, we do). |
@ddeboer maybe it should be named |
@stof Makes sense: getHttpClient or getTestHttpClient distinguishes it more clearly from Symfony's built-in test client. |
+1 for getHttpClient. we are in a test, so getTestHttpClient is kind of overloaded, but getHttpClient sounds descriptive. and say waht you wrote in your comment in the phpdoc for those unsure what it is. |
agreed with @dbu. Thus, this http client is not specific to tests. It is a real HTTP client (you can use it to load wikipedia if you want) |
Okay, renamed to |
application. Used for invalidation with paths. | ||
The hostname (or base URL) where users access your web application. The base | ||
URL may contain a path. If you access your web application on a port other than | ||
80, include that port: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove leading whitespace
cool. i only found cosmetics. feel free to squash and merge. as you made the methods procteded: do you drop FriendsOfSymfony/FOSHttpCache#113? i would be ok to keep it in, in the end. the common doc and ensured consistency has convinced me its worth it ;-) |
Add documentation Fix config and add docs Fix undefined index Fix config key name Fix test Fix fetching container
Rename to getHttpClient() * Rename getClient() to getHttpClient() * Make convenience methods protected * Remove getProxyClient() method from ProxyTestCase * Prefix base_url with "http://" so we can use it safely for the HTTP client * Update docs Improve type hints Remove leading whitespace
Fixed the cosmetics. We can have the interface for the custom assertions, but if we want to include |
great! ready for RC now? |
This depends on FriendsOfSymfony/FOSHttpCache#103.
It adds:
@clearCache
annotation that will clear the configured proxy before each test case starts. This is automatic in the lib’sAbstractProxyClientTestCase
, but my experience with Symfony apps is that usually only one or two different test classes are extended, so doing stuff automatically can really be a pain then. It’s better to add some functionality behind a PHPUnit annotation that users can decide when they want the behaviour.Some problems:
ProxyTestCase
is similar in some ways to the lib’s testcase. However, we cannot easily re-use that (except with traits) because we need to extend Symfony’sWebTestCase
here forProxyTestCase
to have access to the container and be useful in a Symfony app.