Skip to content
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

Merged
merged 2 commits into from
Aug 10, 2014
Merged

Add ProxyTestCase #122

merged 2 commits into from
Aug 10, 2014

Conversation

ddeboer
Copy link
Member

@ddeboer ddeboer commented Aug 3, 2014

This depends on FriendsOfSymfony/FOSHttpCache#103.

It adds:

  • ProxyTestCase for functional cache tests in Symfony2 bundles
  • A @clearCache annotation that will clear the configured proxy before each test case starts. This is automatic in the lib’s AbstractProxyClientTestCase, 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 config for starting the proxy server in tests:
fos_http_cache:
    proxy_server:
        varnish:
            binary: /usr/sbin/varnishd
            port: 8080
            config_file: /etc/varnish/default.vcl

Some problems:

  • The 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’s WebTestCase here for ProxyTestCase to have access to the container and be useful in a Symfony app.

</call>
<call method="setPort">
<argument>%fos_http_cache.proxy_server.varnish.port%</argument>
</call>
Copy link
Member Author

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.

@dbu
Copy link
Contributor

dbu commented Aug 4, 2014

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>
Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member Author

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: ~

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@ddeboer ddeboer changed the title Add ProxyTestCase [WIP] Add ProxyTestCase Aug 4, 2014
@@ -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>
Copy link
Contributor

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 ;-)

Copy link
Member Author

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?

Copy link
Contributor

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 :-)

@dbu
Copy link
Contributor

dbu commented Aug 6, 2014

i restarted the build now that the PR on the component is merged.

once this is merged, its time for RC1 i would say.

@dbu dbu mentioned this pull request Aug 6, 2014
6 tasks
@ddeboer
Copy link
Member Author

ddeboer commented Aug 6, 2014

Yep, RC here we come. I hope to have this ready later today.

@ddeboer
Copy link
Member Author

ddeboer commented Aug 6, 2014

@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')
Copy link
Contributor

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')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dbu
Copy link
Contributor

dbu commented Aug 6, 2014

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
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

@ddeboer
Copy link
Member Author

ddeboer commented Aug 7, 2014

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()
Copy link
Contributor

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.

@ddeboer
Copy link
Member Author

ddeboer commented Aug 7, 2014

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.

@dbu
Copy link
Contributor

dbu commented Aug 7, 2014

ups, i got confused, sorry. should we call this getTestClient and have a line in the phpdoc explaining what it is for?

@ddeboer
Copy link
Member Author

ddeboer commented Aug 7, 2014

Should we then rename getClient() in the library to getTestClient(), too? (To enforce consistency here is one of the reasons I prefer an interface.)

@dbu
Copy link
Contributor

dbu commented Aug 8, 2014

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?

@ddeboer
Copy link
Member Author

ddeboer commented Aug 8, 2014

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).

@stof
Copy link
Member

stof commented Aug 8, 2014

@ddeboer maybe it should be named getHttpClient then ?

@ddeboer
Copy link
Member Author

ddeboer commented Aug 8, 2014

@stof Makes sense: getHttpClient or getTestHttpClient distinguishes it more clearly from Symfony's built-in test client.

@dbu
Copy link
Contributor

dbu commented Aug 8, 2014

+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.

@stof
Copy link
Member

stof commented Aug 8, 2014

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)

@ddeboer
Copy link
Member Author

ddeboer commented Aug 8, 2014

Okay, renamed to getHttpClient() and made the methods protected. Please have a last look and then I’ll squash and merge.

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove leading whitespace

@dbu
Copy link
Contributor

dbu commented Aug 9, 2014

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
@ddeboer
Copy link
Member Author

ddeboer commented Aug 9, 2014

Fixed the cosmetics.

We can have the interface for the custom assertions, but if we want to include getResponse() and getHttpClient() we have to make them public (again)? So it’s a trade-off between consistency and reduced duplication and having a better API. Which do you prefer?

@ddeboer ddeboer changed the title [WIP] Add ProxyTestCase Add ProxyTestCase Aug 10, 2014
ddeboer added a commit that referenced this pull request Aug 10, 2014
@ddeboer ddeboer merged commit 9c6c5d4 into master Aug 10, 2014
@ddeboer ddeboer deleted the testcase branch August 10, 2014 14:58
@dbu
Copy link
Contributor

dbu commented Aug 11, 2014

great! ready for RC now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants