You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Patrick Barnes <mr...@gmail.com> on 2010/04/19 08:16:40 UTC
Couchdb and PHPUnit
Has anyone on the list (or elsewhere) written code for phpunit to make
setting up /tearing down couchdb test databases for unit testing easier?
Cheers,
-Patrick
Re: Couchdb and PHPUnit
Posted by Sam Bisbee <sb...@computervip.com>.
On Tue, Apr 20, 2010 at 09:18:36AM +1000, Patrick Barnes wrote:
> That does seem to be the way to go about implementing such a system.
> I will see how I go, and will publish the results if I end up with
> something that seems reusable.
It's probably worth noting that by interfacing with the database you
technically aren't unit testing - it's closer to integration testing. Unit
tests are supposed to test discrete units, and shouldn't rely on (for example)
a database connection.
Yes, this is a bit purist, and no, mocking a database is not always realistic
when time constraints are involved. I know that I didn't want to mock CouchDB
when writing unit tests for Sag (would've been its own project):
http://github.com/ravidgemole/sag/tree/master/tests/.
If anyone is up for mocking CouchDB, then I'm all ears - has this been done in
any other languages yet?
Cheers,
--
Sam Bisbee
Re: Couchdb and PHPUnit
Posted by Patrick Barnes <mr...@gmail.com>.
That does seem to be the way to go about implementing such a system. I
will see how I go, and will publish the results if I end up with
something that seems reusable.
-Patrick
On 19/04/2010 6:00 PM, Thomas Nunninger wrote:
> Hi,
>
> Am Montag, 19. April 2010 09:44:22 schrieb Patrick Barnes:
>> Partly - I was wondering also if there was something similar to the
>> functionality phpunit has for initialising database contents from XML
>> files, etc.
>
> Why don't you use setUpBeforeClass() and tearDownAfterClass()? In my CouchDB
> related test cases I have something like this:
>
> public static function setUpBeforeClass()
> {
> $couchDb = new myCouchDb( self::getCouchDbUri() );
> $dbName = 'some_test_database';
>
> try
> {
> $couchDb->createDatabase( $dbName );
> }
> catch ( Exception $e )
> {
> $couchDb->deleteDatabase( $dbName );
> $couchDb->createDatabase( $dbName );
> }
> }
>
> public static function tearDownAfterClass()
> {
> $couchDb = new myCouchDb( self::getCouchDbUri() );
> $dbName = 'some_test_database';
> $couchDb->deleteDatabase( $dbName );
> }
>
> HTH
>
> Thomas
>
>>
>> On 19/04/2010 5:15 PM, David Coallier wrote:
>>> On 19 April 2010 07:16, Patrick Barnes<mr...@gmail.com> wrote:
>>>> Has anyone on the list (or elsewhere) written code for phpunit to make
>>>> setting up /tearing down couchdb test databases for unit testing easier?
>>>
>>> I have setup couchdb to be used in unit tests and from the look of
>>> your question all you'd have to do is setup the base class that would
>>> have a setUp and that would create an instance to the CouchDB
>>> databases you have.
>>>
>>> abstract class TestBaseCouch extends PHPUnit_Framework_TestCase
>>> {
>>> protected $couch;
>>>
>>> public function setUp()
>>> {
>>> $this->couch = new Couch();
>>> }
>>>
>>> public function tearDown()
>>> {
>>> unset($this->config);
>>> }
>>> }
>>>
>>> class TestyouWantTestCase extends TestBaseCouch
>>> {
>>> /**
>>> * @expectedException Couch_Exception
>>> */
>>> public function testExceptionFromCouchClient()
>>> {
>>> $this->couch->doSomething();
>>> }
>>> }
>>>
>>>
>>> Is that what you mean?
>
>
>
Re: Couchdb and PHPUnit
Posted by Thomas Nunninger <th...@nunninger.info>.
Hi,
Am Montag, 19. April 2010 09:44:22 schrieb Patrick Barnes:
> Partly - I was wondering also if there was something similar to the
> functionality phpunit has for initialising database contents from XML
> files, etc.
Why don't you use setUpBeforeClass() and tearDownAfterClass()? In my CouchDB
related test cases I have something like this:
public static function setUpBeforeClass()
{
$couchDb = new myCouchDb( self::getCouchDbUri() );
$dbName = 'some_test_database';
try
{
$couchDb->createDatabase( $dbName );
}
catch ( Exception $e )
{
$couchDb->deleteDatabase( $dbName );
$couchDb->createDatabase( $dbName );
}
}
public static function tearDownAfterClass()
{
$couchDb = new myCouchDb( self::getCouchDbUri() );
$dbName = 'some_test_database';
$couchDb->deleteDatabase( $dbName );
}
HTH
Thomas
>
> On 19/04/2010 5:15 PM, David Coallier wrote:
> > On 19 April 2010 07:16, Patrick Barnes<mr...@gmail.com> wrote:
> >> Has anyone on the list (or elsewhere) written code for phpunit to make
> >> setting up /tearing down couchdb test databases for unit testing easier?
> >
> > I have setup couchdb to be used in unit tests and from the look of
> > your question all you'd have to do is setup the base class that would
> > have a setUp and that would create an instance to the CouchDB
> > databases you have.
> >
> > abstract class TestBaseCouch extends PHPUnit_Framework_TestCase
> > {
> > protected $couch;
> >
> > public function setUp()
> > {
> > $this->couch = new Couch();
> > }
> >
> > public function tearDown()
> > {
> > unset($this->config);
> > }
> > }
> >
> > class TestyouWantTestCase extends TestBaseCouch
> > {
> > /**
> > * @expectedException Couch_Exception
> > */
> > public function testExceptionFromCouchClient()
> > {
> > $this->couch->doSomething();
> > }
> > }
> >
> >
> > Is that what you mean?
--
Thomas Nunninger
Steinhalde 108
79117 Freiburg
Tel.: +49 761 1201850
Mobil: +49 163 7115153
http://nunninger.info
USt-IdNr: DE259832548
Re: Couchdb and PHPUnit
Posted by David Coallier <da...@gmail.com>.
On 19 April 2010 08:44, Patrick Barnes <mr...@gmail.com> wrote:
> Partly - I was wondering also if there was something similar to the
> functionality phpunit has for initialising database contents from XML files,
> etc.
>
<snip>
Hmm right sorry, I don't know. I'd say look at Object Freezer
(http://www.phpunit.de/manual/current/en/organizing-tests.html)
--
David Coallier
Re: Couchdb and PHPUnit
Posted by Patrick Barnes <mr...@gmail.com>.
Partly - I was wondering also if there was something similar to the
functionality phpunit has for initialising database contents from XML
files, etc.
On 19/04/2010 5:15 PM, David Coallier wrote:
> On 19 April 2010 07:16, Patrick Barnes<mr...@gmail.com> wrote:
>> Has anyone on the list (or elsewhere) written code for phpunit to make
>> setting up /tearing down couchdb test databases for unit testing easier?
>>
>
> I have setup couchdb to be used in unit tests and from the look of
> your question all you'd have to do is setup the base class that would
> have a setUp and that would create an instance to the CouchDB
> databases you have.
>
> abstract class TestBaseCouch extends PHPUnit_Framework_TestCase
> {
> protected $couch;
>
> public function setUp()
> {
> $this->couch = new Couch();
> }
>
> public function tearDown()
> {
> unset($this->config);
> }
> }
>
> class TestyouWantTestCase extends TestBaseCouch
> {
> /**
> * @expectedException Couch_Exception
> */
> public function testExceptionFromCouchClient()
> {
> $this->couch->doSomething();
> }
> }
>
>
> Is that what you mean?
>
Re: Couchdb and PHPUnit
Posted by David Coallier <da...@gmail.com>.
On 19 April 2010 07:16, Patrick Barnes <mr...@gmail.com> wrote:
> Has anyone on the list (or elsewhere) written code for phpunit to make
> setting up /tearing down couchdb test databases for unit testing easier?
>
I have setup couchdb to be used in unit tests and from the look of
your question all you'd have to do is setup the base class that would
have a setUp and that would create an instance to the CouchDB
databases you have.
abstract class TestBaseCouch extends PHPUnit_Framework_TestCase
{
protected $couch;
public function setUp()
{
$this->couch = new Couch();
}
public function tearDown()
{
unset($this->config);
}
}
class TestyouWantTestCase extends TestBaseCouch
{
/**
* @expectedException Couch_Exception
*/
public function testExceptionFromCouchClient()
{
$this->couch->doSomething();
}
}
Is that what you mean?
--
David Coallier