Commit 93e53ec9 authored by Jens Segers's avatar Jens Segers

Adding date tests for issue #51

parent 802e6c32
......@@ -309,4 +309,18 @@ class ModelTest extends PHPUnit_Framework_TestCase {
$this->assertFalse(isset($user2->note2));
}
public function testDates()
{
$user1 = User::create(array('name' => 'John Doe', 'birthday' => new DateTime('1980/1/1')));
$user2 = User::create(array('name' => 'Jane Doe', 'birthday' => new DateTime('1981/1/1')));
$this->assertInstanceOf('DateTime', $user1->birthday);
// Re-fetch to be sure
$user1 = User::find($user1->_id);
$user2 = User::find($user2->_id);
$this->assertInstanceOf('DateTime', $user1->birthday);
}
}
......@@ -415,16 +415,31 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
public function testUpdateSubdocument()
{
DB::collection('users')->insertGetId(array(
'name' => 'John Doe',
'address' => array('country' => 'Belgium')
$id = DB::collection('users')->insertGetId(array('name' => 'John Doe', 'address' => array('country' => 'Belgium')));
DB::collection('users')->where('_id', $id)->update(array('address.country' => 'England'));
$check = DB::collection('users')->find($id);
$this->assertEquals('England', $check['address']['country']);
}
public function testDates()
{
DB::collection('users')->insert(array(
array('name' => 'John Doe', 'birthday' => new MongoDate(strtotime("1980-01-01 00:00:00"))),
array('name' => 'Jane Doe', 'birthday' => new MongoDate(strtotime("1981-01-01 00:00:00"))),
array('name' => 'Robert Roe', 'birthday' => new MongoDate(strtotime("1982-01-01 00:00:00"))),
array('name' => 'Mark Moe', 'birthday' => new MongoDate(strtotime("1983-01-01 00:00:00"))),
));
DB::collection('users')->where('name', 'John Doe')->update(array('address.country' => 'England'));
$user = DB::collection('users')->where('birthday', new MongoDate(strtotime("1980-01-01 00:00:00")))->first();
$this->assertEquals('John Doe', $user['name']);
$check = DB::collection('users')->where('name', 'John Doe')->first();
$start = new MongoDate(strtotime("1981-01-01 00:00:00"));
$stop = new MongoDate(strtotime("1982-01-01 00:00:00"));
$this->assertEquals('England', $check['address']['country']);
$users = DB::collection('users')->whereBetween('birthday', array($start, $stop))->get();
$this->assertEquals(2, count($users));
}
}
......@@ -9,6 +9,8 @@ class User extends Eloquent implements UserInterface, RemindableInterface {
protected $collection = 'users';
protected $dates = array('birthday');
protected static $unguarded = true;
public function books()
......@@ -56,4 +58,4 @@ class User extends Eloquent implements UserInterface, RemindableInterface {
return $this->email;
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment