Jump to content

class test issue


purencool

Recommended Posts

I have an issue that with some testing on an Access  class with a method getControlAccess it should only return true or false but as soon as I place a string of any sort

into the return my tests always returns true. Any help to point out if it is the way I am testing or the way I have written the method would be great. In the example

below it would return true.

 

 

In one class I have this method

class Access{
public function getControlAccess(){

	return   'I am stuffed';
}
}

 

In the second class I have this

class AccessTests extends Access{
public function controlAccessTest(){
	$return = "<ul>";
	  
	if ($this->getControlAccess() == TRUE){

		$return .= "<li>getControlAcess should be true and is returning:<b> ". $this->getControlAccess() ."</b></li>";

	} elseif ($this->getControlAccess() == FALSE){

		$return .= "<li>getControlAcess should be false and is returning:<b> ". $this->getControlAccess() ."<b></li>";
	} else {

		$return .= "<li>getControlAcess is really stuffed:<b>". $this->getControlAccess() ."<b></li>";
	}

	$return .= "</ul>";
	return $return;
}

public function setAccessTest($set){
	return $set;
}

}

Link to comment
Share on other sites

No, use this

 

<?php 

$varA = TRUE;
$varB = 'somestring';

if( $varA == TRUE )
echo '$varA == TRUE<br>';
if( $varB == TRUE )
echo '$varB == TRUE<br>';
if( $varA === TRUE )
echo '$varA === TRUE<br>';
if( $varB === TRUE )
echo '$varB === TRUE';

?>

 

Output

$varA == TRUE
$varB == TRUE
$varA === TRUE

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.