PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Jun 21, 2018 10:31 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Assert clarity
PostPosted: Fri Jul 29, 2005 8:59 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Aug 16, 2002 8:57 am
Posts: 1834
Location: Watertown, MA
I have a few test cases where I feel the assertions lack clarity.

I'm checking for the existence of certain keys in a dictionary. It is aleady guarenteed that if the key exists its value is non-false; and that the dictionairy will return false if the key doesn't exist.

I've currently coded these assertions as
Syntax: [ Download ] [ Hide ]
$this->assertTrue($this->pb->getQuery("Key Name"));

However, an "assertNotFalse" would probably indicate the intention better. Of course there is no such assertion and I don't think it would really be worth adding it via a local subclass of UnitTestCase. Perhaps

Syntax: [ Download ] [ Hide ]
assertNotEqual(false,$this->pb->getQuery("Key Name"));

It just feels a little funny to use notEquals with false (or true) as one of expected values....


I could write it as
Syntax: [ Download ] [ Hide ]
$this->assertTrue(in_array("Key Name",$this->pb->getKeys()))

but that would be adding the geyKeys() purely to support easier testing -- there isn't a use-case demand for getKeys yet.

I guess the other option would be to use assertEquals with the actual returned value. However the returned values are slightly brittled and will likely have a fair bit of tweaking at the whitespace level that would be hard to properly right a regexp for.


Any other thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 9:10 pm 
Offline
DevNet Master

Joined: Tue Jan 20, 2004 12:11 am
Posts: 4897
Location: Leuven, Belgium
Syntax: [ Download ] [ Hide ]
// assertNotFalse

$this->assertTrue($this->pb->getQuery("Key Name") !== false);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 9:30 pm 
Offline
DevNet Master

Joined: Thu Jan 30, 2003 9:26 pm
Posts: 2893
Location: Glasgow, Scotland
Maybe:

Syntax: [ Download ] [ Hide ]
$this->assertTrue(is_string(...));


Last edited by McGruff on Fri Aug 05, 2005 9:19 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 9:37 pm 
Offline
DevNet Master

Joined: Thu Jan 30, 2003 9:26 pm
Posts: 2893
Location: Glasgow, Scotland
Actually maybe this expresses the constraint better:

Syntax: [ Download ] [ Hide ]
$this->assertTrue(is_string(...) and str_len(...) > 0);


I'm assuming that all you're really interested in here is that you should get a string back (an sql query, going by your recent posts). On the principle that you don't want to add any unecessary constraints to possible implementations, it doesn't really matter whether the method returns false, null, or an empty string '' if the key doesn't exist.


Last edited by McGruff on Fri Aug 05, 2005 9:19 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 9:38 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Aug 16, 2002 8:57 am
Posts: 1834
Location: Watertown, MA
McGruff wrote:
Maybe:

Syntax: [ Download ] [ Hide ]
$this->assertTrue(is_string(...));


I like it. Thanks.


Ooh, new version even better!

Assert changed to:
Syntax: [ Download ] [ Hide ]
$phrase=$this->pb->getQuery($aPhraseLabel);

      $this->assertTrue(is_string($phrase) && strlen($phrase)>0);


I wish I had a good way to compare the actual string to the expected string, but as one of the primary reasons for moving the SQL out to a PhraseBook was to allow a DBA-type person to do tuning at both the DB and query level. The PhraseBook is marked up with sql comments, etc, so its directly edittable/useable in SQL authoring tools and I expect the
linebreaks/indentation of multiline queries to fluctuate freely along with join orders/aliases.

I think they way I'll test the embeded SQL is against a test DB. As long as the named query retreives the right Result Set, its working properly, etc.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 9:58 pm 
Offline
DevNet Master

Joined: Thu Jan 30, 2003 9:26 pm
Posts: 2893
Location: Glasgow, Scotland
nielsene wrote:
I think they way I'll test the embeded SQL is against a test DB.


Yes: I'd do the same. Running the query past a database is the real test.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group