Hi,
I've been spending a few hours trying to work out why my unit-tests
don't work, while if I run the same code on the website with the same
data works fine.
Well, here's the story:
- I've got 2 columns of type 'bigint' in one of my database tables,
on which I do comparison based lookups. Therefore they cannot be
varchars. They can't be ints, because they're too big and if I were
to turn them to ints, half of my data gets truncated.
- They work quite fine with my models and a find method like this
fetches the right results:
$data = $this -> find('first' , array('conditions' => array('number1
<=' => $number , 'number2 >=' => $number))) ;
- The problem arises when I'm testing using fixtures. Bake will setup
both of the two numbers as type 'integer' in the fields declaration.
Using $import in the fixture will have similar results.
public $fields = array(
'id' => array('type' => 'integer', 'null' => false, 'default' =>
NULL, 'key' => 'primary', 'collate' => NULL, 'comment' => ''),
'number1' => array('type' => 'integer', 'null' => false,
'default'
=> NULL, 'collate' => NULL, 'comment' => ''),
'number2' => array('type' => 'integer', 'null' => false,
'default'
=> NULL, 'collate' => NULL, 'comment' => ''),
... truncated ...
);
Now when I run my tests, the exact same find query, fetches only
records which fall within the boundary of int(11).
Playing around I ended up changing the Fixture definition to define
the two numbers as strings :
public $fields = array(
'id' => array('type' => 'integer', 'null' => false, 'default' =>
NULL, 'key' => 'primary', 'collate' => NULL, 'comment' => ''),
'number1' => array('type' => 'string', 'null' => false,
'default' =>
NULL, 'collate' => NULL, 'comment' => ''),
'number2' => array('type' => 'string', 'null' => false,
'default' =>
NULL, 'collate' => NULL, 'comment' => ''),
... truncated ...
);
and suddenly everything is honky dory.
My questions are :
1) why do I get an inconsistent behaviours between my application and
my tests ?
2) my current solution to get the tests working is bodge. What's the
best way to get this working across the app?
Cheers,
Shuku
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php