(Hey everybody. I'm just looking through my old posts here in the
CakePHP user group and try to give useful answers for those I managed
to answer myself in the meantime, hoping somebody else will find it
useful, too. So please don't blame me for maybe posting the same
answer to different questions (they often result in the same answer),
I don't want to spam, I just want to help. Redundant information can't
be wrong, I guess, and somebody googling for something might find only
one of the many posts. So here we go again...)

I managed to work out a solution for this, and I released it as a
library so everyone can use it. I've written in my blog about it.

- Why web tests using the development database are a bad thing:
http://josh.ch/wordpress/?p=8
- Finally: use fixtures with your CakePHP web tests!:
http://josh.ch/wordpress/?p=71

I hope somebody else will find this useful. :-) Please leave a message
if you try it... I'm happy to optimize it further.

On Fri, Sep 17, 2010 at 11:52 AM, Joshua Muheim <psybea...@gmail.com> wrote:
> Your link looks very interesting. I will take a look at it. Thanks!
>
> On Thu, Sep 16, 2010 at 10:10 PM, euromark <dereurom...@googlemail.com> wrote:
>> there are many solutions for one database.php for all environments
>>
>> this is one possibility:
>> http://www.dereuromark.de/2010/08/17/development-vs-productive-setup/
>>
>> no matter where it is, it will select the appropriate setting
>>
>> for your test cases you need to modiy the constructor though
>> i use the same config as default, but with another prefix
>> maybe you should set up a new database for it (if you want)
>>
>>
>> On 16 Sep., 10:35, Joshua Muheim <psybea...@gmail.com> wrote:
>>> Thanks, Nick.
>>>
>>> > You're welcome.  What you're running into is a limitation of the
>>> > Testing Framework CakePHP 1.x decided to use -- SimpleTest.  CakePHP
>>> > 2.0 will be using the PHP defacto standard PHPUnit as their testing
>>> > framework from now on.
>>>
>>> Will PHPUnit allow web testing, too?
>>>
>>> > PHPUnit is more in line of what a similar RoR test framework will give
>>> > you.  RoR is a great framework, I actually came to CakePHP from a
>>> > heavy Ruby on Rails background.   I have my personal gripes with RoR,
>>> > but that's nothing new, nothing is perfect.  However the issue with
>>> > webtesting will persist through even in Ruby on Rails.  This is
>>> > because the idea of web testing testing your app from point to point
>>> > (from a browser), fixture's don't really make sense in that scope.
>>>
>>> Yes it does make sense IMO. E.g. when testing CRUD of a model that
>>> depends on other model data (e.g. one has to be able to pick a
>>> "Publisher" from a selection list to create a new "Book") this makes
>>> perfect sense instead of first creating all the needed model data in
>>> the first place (which is what I'm doing at the moment in my CakePHP
>>> web tests).
>>>
>>> > Sure you can do things like seed data and rake is a great tool for
>>> > doing just that but you'd be doing the same thing you'd be doing to
>>> > get it working in CakePHP.... spoofing your app to run on a test
>>> > database rather than production based on some request.
>>>
>>> Yes, but the difference is that RoR has already implemented this (IMO
>>> *very* self-evident feature) whereas CakePHP doesn't.
>>>
>>> > WebTesting in RubyOnRails is often done with Selenium (http://
>>> > seleniumhq.org/).  You can install a really cool Firefox plugin that
>>> > will actually write your testcase for you as you click, edit forms,
>>> > etc...  With PHPUnit (CakePHP 2.0) You'll be able to do the same thing
>>> > with their Selenium extention (http://www.phpunit.de/manual/3.1/en/
>>> > selenium.html)
>>>
>>> I have worked with Selenium IDE already. It's cool, but what does this
>>> have to do with the actual topic here? :-)
>>>
>>> > I'm not trying to discourage you from picking up Ruby on Rails, just
>>> > stating your "problem" will persist regardless as the issue is
>>> > conceptual more than actual.
>>>
>>> I just don't get why this is such a big thing? Give me two things in 
>>> CakePHP:
>>> - Fixtures in web tests
>>> - A test-DB in web tests
>>> ...and I am happy. This can't be a big deal, can it?
>>>
>>> Thanks for another very informative reply,
>>> Josh
>>>
>>>
>>>
>>> > Hope that helps,
>>> > Nick
>>>
>>> > On Sep 16, 12:57 am, Joshua Muheim <psybea...@gmail.com> wrote:
>>> >> WOW, thank you so much for your very informative answer, Nick! I
>>> >> nearly gave up all hope already.
>>>
>>> >> I absolutely agree with everything you write. I just don't understand
>>> >> why the CakePHP developers don't seem to see it "our" way? Why didn't
>>> >> they tweak SimpleTest so it fits our need with the separate
>>> >> staging-database? I really am no very experienced PHP programmer, and
>>> >> I guess it would take me quite a long time to do the modifications you
>>> >> suggested... and it would be quite buggy, too.
>>>
>>> >> Well, in a few days I will have a talk to my boss and I will suggest
>>> >> him to switch from CakePHP to Ruby On Rails... RoR just seems a whole
>>> >> lot better to me, although I didn't work with it for two years or so
>>> >> now... CakePHP misses so many useful nice-to-haves and even some big
>>> >> must-haves.
>>>
>>> >> Again, thank you for your great answer, Nick!
>>>
>>> >> On Wed, Sep 15, 2010 at 6:06 PM, nurvzy <nur...@gmail.com> wrote:
>>> >> > Fixtures in WebTestCase?
>>>
>>> >> >http://book.cakephp.org/view/1219/Web-testing-Testing-views#About-Cak...
>>>
>>> >> > Short answer: Nope.
>>>
>>> >> > Long answer: Eventhough you can't use fixtures, you can still make
>>> >> > your app use a secondary database instead of your production one.
>>> >> > This is not a CakePHP solution, rather than a manipulation of
>>> >> > SimpleTest.  The idea of a web test case is to test your app as a
>>> >> > whole.  It basically simulates a browser that you can make calls on
>>> >> > your app, submit forms, click links, etc...  The idea is to test the
>>> >> > app in a real browser and as such it uses the real database as your
>>> >> > app doesn't know any better.... unless you make your app smarter.
>>>
>>> >> > I highly suggest you read through the documentation at SimpleTest as
>>> >> > well as poke your head into the actual source.  By doing so you'll
>>> >> > notice you can directly access the browser being used by the
>>> >> > WebTestCase with getBrowser(). With that, if you look into what you
>>> >> > can do on the browser (http://simpletest.sourceforge.net/en/
>>> >> > browser_documentation.html) you can add additional headers to each
>>> >> > request.   Your app then can look at the request before doing
>>> >> > anything, if your specified test header is present, switch the default
>>> >> > database constructor to use a test database instead of your production
>>> >> > one and you're free to run as many webtests as you please.
>>>
>>> >> > What I do, and most of the companies/clients I've worked for, is have
>>> >> > three environments, development, staging, and production.  Each have
>>> >> > their own separate database they connect to and are maintained through
>>> >> > various migrations/source control.  Staging is for all purposes
>>> >> > identical to production, except for the fact it's connected to a
>>> >> > different non-live database (and is usually closed to the public).  As
>>> >> > such it is safe to run web tests on staging as it doesn't affect the
>>> >> > live database.  The idea being, if there is a problem you'll discover
>>> >> > it first on the staging site before it gets pushed over to your
>>> >> > production site.
>>>
>>> >> > Hope that helps,
>>> >> > Nick
>>>
>>> >> > On Sep 14, 3:43 am, psybear83 <psybea...@gmail.com> wrote:
>>> >> >> Dear CakePHP community
>>>
>>> >> >> I'm asking this question (or related ones) for quite a short while
>>> >> >> now, and I still didn't get a clear answer. So I ask one more single
>>> >> >> time:
>>>
>>> >> >> Is there a way to use fixtures with web tests (CakeWebTestCase, not
>>> >> >> CakeTestCase!), or not?
>>>
>>> >> >> I'd like to create useful web tests that test my application like a
>>> >> >> bunch of real users would, andit would be really, really useful to
>>> >> >> have fixtures available for these tests like one has with unit tests.
>>> >> >> But I didn't find an article or something like that yet... maybe I was
>>> >> >> just blind (I really hope this is the case).
>>>
>>> >> >> Thanks a lot for help
>>> >> >> Josh
>>>
>>> >> > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp 
>>> >> > others with their CakePHP related questions.
>>>
>>> >> > You received this message because you are subscribed to the Google 
>>> >> > Groups "CakePHP" group.
>>> >> > To post to this group, send email to cake-php@googlegroups.com
>>> >> > To unsubscribe from this group, send email to
>>> >> > cake-php+unsubscr...@googlegroups.com For more options, visit this 
>>> >> > group athttp://groups.google.com/group/cake-php?hl=en
>>>
>>> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
>>> > with their CakePHP related questions.
>>>
>>> > You received this message because you are subscribed to the Google Groups 
>>> > "CakePHP" group.
>>> > To post to this group, send email to cake-php@googlegroups.com
>>> > To unsubscribe from this group, send email to
>>> > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
>>> > athttp://groups.google.com/group/cake-php?hl=en
>>
>> Check out the new CakePHP Questions site http://cakeqs.org and help others 
>> with their CakePHP related questions.
>>
>> You received this message because you are subscribed to the Google Groups 
>> "CakePHP" group.
>> To post to this group, send email to cake-php@googlegroups.com
>> To unsubscribe from this group, send email to
>> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
>> http://groups.google.com/group/cake-php?hl=en
>>
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to