Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Created May 29, 2013 21:34
Show Gist options
  • Select an option

  • Save JeffreyWay/5674014 to your computer and use it in GitHub Desktop.

Select an option

Save JeffreyWay/5674014 to your computer and use it in GitHub Desktop.
<?php
class User extends Eloquent {
public function getOldest()
{
return $this->orderBy('age', 'desc')->first();
}
}
@mdespuits

Copy link
Copy Markdown

2

When dealing with databases and queries, ALWAYS use integration. Yes, you could use a mock expectation that the method was called, and yes, you can have faith that Eloquent will query properly, but with databases, unless you are dealing with real data, you cannot always be absolutely sure that you did it right. What if you typo-d the method or the parameters in the production and test code? Your tests would pass, but you would have a nasty 🐛.

Mocks are much more useful for asserting that interfaces around external APIs are called properly from your own abstraction, not for testing that the ORM runs the right query and the database returns the right values.

@vladan-zoricic

Copy link
Copy Markdown

Some combination of 2 and 3.

@JulienItard

Copy link
Copy Markdown

2

@jlambe

jlambe commented May 30, 2013

Copy link
Copy Markdown

2 because we're dealing with datas from the database. Otherwise 3 if you intend to test a method that format a given data.

@lnguyen0901

Copy link
Copy Markdown

2 and 3

@hasokeric

Copy link
Copy Markdown

2

@torkiljohnsen

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment