[Solved]How to hide data value?

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

[Solved]How to hide data value?

Post by kpraman »

Code: Select all

<?php



      public function testing_insertData()
          {
	        $new=new MemberTypes;
                $new->AddOrUpdateMemberType('manager','Head of    the','true','','membertype');
                echo $memid=mysql_insert_id();
	$resExpected=array((string)$memid,'manager','Head of the','true');
		   
	$query=mysql_query("SELECT * FROM membertype WHERE membertypeid=$memid");
                $resActual=mysql_fetch_row($query);
	$this->assertEquals($resExpected,$resActual, "COULD NOT INSERT DATA.");
          }
	
	
		 
       public function testing_insertNotable()
           {
                 $new=new MemberTypes;
                 $new->AddOrUpdateMemberType('manager','Head of the','true','','');
                 echo $memid=mysql_insert_id();
                 $query=mysql_query("SELECT * FROM membertype WHERE membertypeid=$memid");
                 $resActual=mysql_fetch_row($query);
	 $this->assertEquals(0,sizeof($this->resActual), "COULD NOT INSERT DATA.");
           
            }



?>
The value of the first method's $memid gets assigned to second method's $memid. I do not want to change $memid name. How to restrict this?
Last edited by kpraman on Tue Oct 31, 2006 3:15 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I have no idea what you're asking. Please explain.
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

what i meant is,


methods should be public, the variables inside it should private. I should be able to give same variable name and they should not be overwritten by their previous values.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

If I understand your question the Static varable declaration may be of use...

Code: Select all

function test($dummy=null)
{
  static $test='';

  if ($dummy !== null) {
      $test=$dummy;
  }

  return $test;
}

echo test('Hello'); // returns 'Hello'
echo test(); // returns 'Hello'
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

My guess is that you're looking at it the wrong way. $memid is being assigned the value of mysqli_insert_id(). Assuming you have not created a new record, mysqli_insert_id() will continue providing the primary key of the last insert over, and over, and over again until you make a new insert.

Your AddOrUpdateMemberType function might be coopted here - have it return mysqli_insert_id() or false depending on whether something is added, or just updated (no new id). Otherwise the Id test is a bit defunct since its not strictly a test of the class and cannot tell which operation (Insert/Update) has taken place.

From there you can test both scenarios, with a false id indicating an update. In an update scenario, verify by selecting based non-id data. Even better, since the id should be a primary key, make $memid a private class property of your test class. Set it on the initial insert, then re-use it for subsequent updates/verification selects...
Post Reply