getName()

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

getName()

Post by kpraman »

getName() returns method Name without '()'. I tried to use

Code: Select all

$methName=$passedTest->getName();
$methName="$methName()";
i cannot use $val=$new->$methName;


How to get the full method name?
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: getName()

Post by jmut »

kpraman wrote:getName() returns method Name without '()'. I tried to use

Code: Select all

$methName=$passedTest->getName();
$methName="$methName()";
i cannot use $val=$new->$methName;


How to get the full method name?
What exactly are you trying to achive?

You call methods based on strings like this

Code: Select all

$methodName = 'get';
$object->$methodName();
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

is getName() a JUnit feature? I never know what exactly you're referring to. Most of us use simpletest.

EDIT | I meant PHPUnit, not JUnit
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

i am trying to get customized output, like...

Method Name:$methodName

ExpectedRes:$expectedRes

ActualRes:$actualRes

for this, i am trying to edit TestResults file in PHPUnit.

Code: Select all

<?php
function toString() {
 $result = '';
         
        foreach ($this->_passedTests as $passedTest) {
            $result .= sprintf(
			
"Method Name:\nExpected Values:\nActual Values:\nTestCase %s->%s() passed\n",
              get_class($passedTest),
              $passedTest->getName()
			  
            );
		  sprintf("$passedTest->getName()\n");
        }

        foreach ($this->_failures as $failedTest) {
            $result .= $failedTest->toString();
        }

        return $result;
    }

?>

Code: Select all

<?php

class MembersTest extends PHPUnit_TestCase {

public function testing_insertData()
{
$newinsertdata=new Members;
		
$newinsertdata->AddMember('1','testFname','testLname','testAddress','testCity','testState','123456','India','1234567','test@testmail.com','1234567890','true','members');
$memberid_insertd=mysql_insert_id();
$resExpectedInsertd=array((string)$memberid_insertd,'1','testFname','testLname','testAddress','testCity','testState','123456','India','1234567','test@testmail.com','1234567890','true');
$query=mysql_query("SELECT * FROM members WHERE memberId=$memberid_insertd");$resActualInsertd=mysql_fetch_row($query);

$this->assertEquals($resExpectedInsertd,$resActualInsertd, "COULD NOT INSERT DATA.");
			
return $resExpectedInsertd;
			
}

}

?>

How do i access the value of $resExpectedInsertd using $passedTest.




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

Post by kpraman »

This works

Code: Select all

$method=$passedTest->testing_insertData();
This does not work

Code: Select all

$method=$passedTest->getName();
$method="$method()";
$val=$passedTest->$method;
echo $val;
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

i solved it,

Code: Select all

$method=$passedTest->getName(); 
$method="$method()"; 
$val=$passedTest->$method; 
echo $val;

working code

Code: Select all

$method=$passedTest->getName(); 
$method="$method"; 
$val=$passedTest->$method();
Post Reply