views:

180

answers:

2

Hi,

I'm fairly new to Zend and am having some difficulties with creating my unit tests. I've stripped it down to a minimal test class that still replicates the problem in the hope that it is something daft that I'm doing:

class UserRegistrationsTest extends PHPUnit_Framework_TestCase 
{

protected $db;

public function __construct($name = NULL) { parent::__construct ( $name );

$this->db = Zend_Db::factory('Pdo_Mysql', array( 'host' => '127.0.0.1', 'username' => 'root', 'password' => 'xxxxxxxx', 'dbname' => 'testingdb' ));

Zend_Db_Table_Abstract::setDefaultAdapter($this->db); }

public function testName() { $users = new Users(); $select = $users->select()->where('regCode = ?', 'deadbeef'); $row = $users->fetchRow($select); }

}

So this is the simplified test. I have a db set up (which is connects to correctly) that has data inside it. There is a record with regCode set to 'deadbeef' and it also has fields for email, regDate and affiliate:

CREATE TABLE  testingdb.users (
         regCode varchar(16) NOT NULL,
         email varchar(150) NOT NULL,
         regDate datetime NOT NULL,
         affiliate int(10) unsigned DEFAULT NULL,
         PRIMARY KEY (regCode))

I have a class called Users.php that is as simple as it gets:

class Users extends Zend_Db_Table_Abstract {

protected $_name = 'users';

}

My problem is that I can insert into the database fine, but any queries return odd results. The fetchRow above generates the correct SQL but the returned row is garbage - it returns a row containing regCode, email, no regDate column at all, then the affiliate is there but the collumn is called 'users' instead of 'affiliate'.

I've tried it on other tables and none work - some even return the database name as a column header as well as the table name as a column.

One thing to note is that if I'm not running this in a test it works fine. The exact same code and db in the proper app work great, but running as a phpUnit Test and it gets all screwy :-(

Any advice appreciated

Cheers, Bryn

A: 

Do you have any other table or even another database with a table that has a regCode field? You could be using the wrong adapter, that would explain why your query still executes. Prerequisite for your test environment would be at least to have the exact same structure as your production environment (tables + fields). If they differ, some queries may execute well, some others may not.

JP
That is what is odd - in the test I've made sure to get the adapter specifically in the constructor to ensure it is the right one. If I put a breakpoint on the fetchRow and step past it it is grabbing the correct information; just not all of the row. The collumn name still comes through wrong. I get back a Zend_Db_Table_Row currently (whilst fixing it) and in the variables window $row::_data lists the incorrect info but $row::_table::_cols has the correct collumn names. The db adapter is correct also.
davbryn
A: 

This was an old Zend bug that is fixed now

davbryn