Public feed #725586

Stuff

public text v1 · immutable
Raw Edit
·published 2007-10-04 15:19 UTC
rendered paste body
/** CODE REVIEW comment 
*Line 234 -- same comment - replace with a sql select
*Instead of doing this ->Track strangeness, select the data you need in the constructor
**/

/** this examples both passes the test but we are concern which should we use **/

/** FIRST Option **/

/**artistid() in Class **/

function artistid() {

(object)$query = $this->_db->query("SELECT artistid FROM tracks WHERE trackid = '%d'", 
array($this->trackid) ) or die (mysql_error());
//$artistId = array();

$result = mysql_fetch_assoc($query);

foreach($result as $key => $val){
	
	$this->$key = $val;
}

return $this;


/**Test **/


function testArtistId() {
	
(object)$db = new Db( DBUSER, DBPASS, DEFAULT_DB );
 	(int)$id = mysql_insert_id(); 
 
 	// find the id of the track we inserted..
 	(object)$res = mysql_query("SELECT trackid FROM tracks ORDER BY trackid ") or print mysql_error();
 	
	 (array)$tid_array = mysql_fetch_assoc($res);

 	 (int)$tid = $tid_array['trackid'];

	 (object)$track = new Track($db, $tid);
	 
	 $this->assertIsA($track, 'Track');
	
	 $arId = $track->artistid();
	
	 $this->AssertEqual($arId->artistid, 1);
	
}

/** Result **/

Administrator@mtj-mq9v68rwtjt /cygdrive/c/wamp/www/SERVERCOPY/www/t/class_t
track
$ php track_unit_tests.phpt
TrackUnitTester
OK
Test cases run: 1/1, Passes: 109, Failures: 0, Exceptions: 0

Administrator@mtj-mq9v68rwtjt /cygdrive/c/wamp/www/SERVERCOPY/www/t/class_t
track


/* ============== */

/**Second Option

/**artistid() in Class **/

function artistid() {

(object)$query = $this->_db->query("SELECT artistid FROM tracks WHERE trackid = '%d'", 
array($this->trackid) ) or die (mysql_error());
$artistId = array();
while($result = mysql_fetch_assoc($query)) {

$artistId[] = $result;

	
}	


return $artistId;

}


/**Test **/
function testArtistId() {
	
(object)$db = new Db( DBUSER, DBPASS, DEFAULT_DB );
 	(int)$id = mysql_insert_id(); 
 
 	// find the id of the track we inserted..
 	(object)$res = mysql_query("SELECT trackid FROM tracks ORDER BY trackid ") or print mysql_error();
 	
	 (array)$tid_array = mysql_fetch_assoc($res);

 	 (int)$tid = $tid_array['trackid'];

	 (object)$track = new Track($db, $tid);
	 
	 $this->assertIsA($track, 'Track');
	
	 $arId = $track->artistid();
         
       $this->AssertEqual($arId[0][artistid], 1);

}