Skip to content

Provide test functionality in traits #218

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

Merged
merged 2 commits into from
Aug 10, 2015
Merged

Provide test functionality in traits #218

merged 2 commits into from
Aug 10, 2015

Conversation

ddeboer
Copy link
Member

@ddeboer ddeboer commented Jun 20, 2015

Fix #202.

Advantage: users no longer have to extend our test classes, so they are free to extend their own (or their framework’s). Optionally, they can continue to extend SymfonyTestCase/VarnishTestCase/NginxTest: these classes are there now purely for convenience, as they contain no logic but just collect the appropriate traits.

Disadvantage: we have some code duplication in the getters, e.g. getHostName(), getCachingProxyPort().

Todo (if accepted):

  • update docs on how to include traits

/**
* Provides a HTTP client for getting responses from your application
*/
trait AppClient
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this a good name? Perhaps just HttpClient or AppHttpClient or HttpAdapter? I think the name should show that this is not a client for your proxy, but a client to simulate requests to your application.

Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder if it makes sense that all of this is a trait. could we have something like a client provider instead?

*
* @var HttpClient
*/
protected $client;
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be private? what does it mean exactly when a trait has a private property, is it hidden from the class that uses the trait? and what if a class already has a non-private $client? then the user would need to remap the property?

from @stof in https://github.com/FriendsOfSymfony/FOSHttpCache/pull/224/files#r33294271

@dbu
Copy link
Contributor

dbu commented Jul 3, 2015

@ddeboer can you wrap this one up? make things private where possible and update the testing doc? otherwise looks good to me.

@ddeboer ddeboer force-pushed the test-traits branch 2 times, most recently from d32188f to f3c59e6 Compare July 4, 2015 22:57
@ddeboer
Copy link
Member Author

ddeboer commented Jul 4, 2015

Docs updated.

~~~~~~~~~~~~~~~~

Provides your tests with a ``getResponse`` method, which retrieves a URI from
your application through the HTTP cache::
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe "through a real HTTP call to go through the HTTP cache" to be more clear?

@ddeboer ddeboer force-pushed the test-traits branch 3 times, most recently from afc78e7 to 0ccd131 Compare July 6, 2015 18:51
@dbu
Copy link
Contributor

dbu commented Jul 29, 2015

this does not fix #213, right? can we wrap this one up and then work on 213?

@ddeboer
Copy link
Member Author

ddeboer commented Aug 1, 2015

Updated; now ready to merge.

Indeed, this PR enables users of the lib to test their own applications without having to extend our test classes by using our treats instead. It fixes #202 but does not fix #213, as that is about code duplication in the code that tests the lib itself.

}

The ``UNDETERMINED`` state should never happen. If it does, it means that your
HttpCache is not correctly set into debug mode.
Copy link
Contributor

Choose a reason for hiding this comment

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

HttpCache? also, should we make this into another subscriber that one can simply activate in app_test.php?

Copy link
Member Author

Choose a reason for hiding this comment

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

I’m not sure about this; we already had this in the docs and I just moved it. 👍 on a DebugSubscriber, but let’s do that in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

created #238 for that

*/
abstract class VarnishTestCase extends ProxyTestCase
abstract class VarnishTestCase
Copy link
Member

Choose a reason for hiding this comment

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

this is broken. It needs to extend from the PHPUnit_Framework_TestCase

Copy link
Contributor

Choose a reason for hiding this comment

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

it seems to not be needed, at least the travis tests did run through without. oh, or maybe phpunit now ignores classes called Test if they dont extend the phpunit TestCase class.

but anyways i added it back to avoid confusion.

Copy link
Member

Choose a reason for hiding this comment

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

well, if it does not extend the base testcase class, it won't run as it won't be a PHPUnit testcase.

https://travis-ci.org/FriendsOfSymfony/FOSHttpCache/jobs/74553567 was running 78 tests while https://travis-ci.org/FriendsOfSymfony/FOSHttpCache/jobs/74556258 ran 112 tests

Copy link
Contributor

@dbu dbu Aug 7, 2015 via email

Choose a reason for hiding this comment

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

Fix #202.

separate http client from trait

Make property and methods private

Add traits to docs

Reduce levels of inheritance
@dbu
Copy link
Contributor

dbu commented Aug 7, 2015

@ddeboer i rebased and did some cleanup

only open point from my side is #218 (comment) - but i think we should just clean up the text to make it better understandable. providing a trait can happen in a separate PR.

dbu added a commit that referenced this pull request Aug 10, 2015
Provide test functionality in traits
@dbu dbu merged commit 2ef29fe into master Aug 10, 2015
@dbu dbu deleted the test-traits branch August 10, 2015 06:17
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.

3 participants