chriskite / phactory

A Database Factory for PHP Unit Tests
http://phactory.org
MIT License
140 stars 39 forks source link

More configurations for get #8

Open cgarvisacmg opened 13 years ago

cgarvisacmg commented 13 years ago

It would be nice to pass conditions to the get.

Like if I wanted to get the latest created user:

Phactory::get('user', array('name' => 'testuser'), array(
    'order' => 'id DESC', 
    'limit' => 1,
);
jimbojsb commented 13 years ago

Phactory is always accepting pull requests :)

Nevertheless, I agree, this sounds like a good idea in general. I'd be interested to hear the case where it's necessary.

jblotus commented 13 years ago

How many records are you testing at once to need that type of ordering/limiting? Usually on a unit test level, you wont have too many records to pull up and you should be truncating records and resetting Phactory per test.

Not that I disagree with the idea of adding conditions.

cgarvis commented 13 years ago

I have a table that is kind of a log. It contains information that a customer service rep can see to know what the system has done on behalf of the customer. In my unit testing I've had code inserting multiple comments. What I would like to be able to do is pull the last comment. We have the ability to pull the first one but not the last. That is why having the ability to set the order and limit for the Phactory::get() would be useful.

jblotus commented 13 years ago

are you using Phactory to insert the comments? If so you can specify an id and reference that in your get();

Phactory::create('comment', array('id' => 12345, 'data' => 'some comments'));

Phactory::get('comment', array('id' => 12345));
cgarvis commented 13 years ago

When I use Phactory to create records, I do this. But this case is when the code creates those records. I have no way of knowing the id.

jblotus commented 13 years ago

Understood. Maybe a patch would be in order.