QueryBuilderTest.php 20.3 KB
Newer Older
1 2
<?php

3
class QueryBuilderTest extends TestCase {
4 5 6 7 8 9 10 11 12

	public function tearDown()
	{
		DB::collection('users')->truncate();
		DB::collection('items')->truncate();
	}

	public function testCollection()
	{
Jens Segers's avatar
Jens Segers committed
13
		$this->assertInstanceOf('Jenssegers\Mongodb\Query\Builder', DB::collection('users'));
14 15 16 17 18 19 20 21 22 23 24 25 26
	}

	public function testGet()
	{
		$users = DB::collection('users')->get();
		$this->assertEquals(0, count($users));

		DB::collection('users')->insert(array('name' => 'John Doe'));

		$users = DB::collection('users')->get();
		$this->assertEquals(1, count($users));
	}

Jens Segers's avatar
Jens Segers committed
27 28 29 30 31 32 33 34 35 36 37 38
	public function testNoDocument()
	{
		$items = DB::collection('items')->where('name', 'nothing')->get();
		$this->assertEquals(array(), $items);

		$item = DB::collection('items')->where('name', 'nothing')->first();
		$this->assertEquals(null, $item);

		$item = DB::collection('items')->where('_id', '51c33d8981fec6813e00000a')->first();
		$this->assertEquals(null, $item);
	}

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
	public function testInsert()
	{
		DB::collection('users')->insert(array(
			'tags' => array('tag1', 'tag2'),
			'name' => 'John Doe',
		));

		$users = DB::collection('users')->get();
		$this->assertEquals(1, count($users));

		$user = $users[0];
		$this->assertEquals('John Doe', $user['name']);
		$this->assertTrue(is_array($user['tags']));
	}

54
	public function testInsertGetId()
55 56
	{
		$id = DB::collection('users')->insertGetId(array('name' => 'John Doe'));
57
		$this->assertInstanceOf('MongoId', $id);
58 59 60 61 62 63 64
	}

	public function testBatchInsert()
	{
		DB::collection('users')->insert(array(
			array(
				'tags' => array('tag1', 'tag2'),
65
				'name' => 'Jane Doe',
66 67 68 69 70 71 72 73 74
			),
			array(
				'tags' => array('tag3'),
				'name' => 'John Doe',
			),
		));

		$users = DB::collection('users')->get();
		$this->assertEquals(2, count($users));
75
		$this->assertTrue(is_array($users[0]['tags']));
76 77 78 79 80 81 82 83 84 85
	}

	public function testFind()
	{
		$id = DB::collection('users')->insertGetId(array('name' => 'John Doe'));

		$user = DB::collection('users')->find($id);
		$this->assertEquals('John Doe', $user['name']);
	}

86 87 88 89 90 91
	public function testFindNull()
	{
		$user = DB::collection('users')->find(null);
		$this->assertEquals(null, $user);
	}

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
	public function testCount()
	{
		DB::collection('users')->insert(array(
			array('name' => 'Jane Doe'),
			array('name' => 'John Doe')
		));

		$this->assertEquals(2, DB::collection('users')->count());
	}

	public function testUpdate()
	{
		DB::collection('users')->insert(array(
			array('name' => 'Jane Doe', 'age' => 20),
			array('name' => 'John Doe', 'age' => 21)
		));

		DB::collection('users')->where('name', 'John Doe')->update(array('age' => 100));
		$users = DB::collection('users')->get();

112 113 114 115
		$john = DB::collection('users')->where('name', 'John Doe')->first();
		$jane = DB::collection('users')->where('name', 'Jane Doe')->first();
		$this->assertEquals(100, $john['age']);
		$this->assertEquals(20, $jane['age']);
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
	}

	public function testDelete()
	{
		DB::collection('users')->insert(array(
			array('name' => 'Jane Doe', 'age' => 20),
			array('name' => 'John Doe', 'age' => 25)
		));

		DB::collection('users')->where('age', '<', 10)->delete();
		$this->assertEquals(2, DB::collection('users')->count());

		DB::collection('users')->where('age', '<', 25)->delete();
		$this->assertEquals(1, DB::collection('users')->count());
	}

	public function testTruncate()
	{
		DB::collection('users')->insert(array('name' => 'John Doe'));
		DB::collection('users')->truncate();
		$this->assertEquals(0, DB::collection('users')->count());
	}

	public function testSubKey()
	{
		DB::collection('users')->insert(array(
			array(
				'name' => 'John Doe',
				'address' => array('country' => 'Belgium', 'city' => 'Ghent')
			),
			array(
				'name' => 'Jane Doe',
				'address' => array('country' => 'France', 'city' => 'Paris')
			)
		));

		$users = DB::collection('users')->where('address.country', 'Belgium')->get();
		$this->assertEquals(1, count($users));
		$this->assertEquals('John Doe', $users[0]['name']);
	}

	public function testInArray()
	{
		DB::collection('items')->insert(array(
			array(
				'tags' => array('tag1', 'tag2', 'tag3', 'tag4')
			),
			array(
				'tags' => array('tag2')
			)
		));

		$items = DB::collection('items')->where('tags', 'tag2')->get();
		$this->assertEquals(2, count($items));

		$items = DB::collection('items')->where('tags', 'tag1')->get();
		$this->assertEquals(1, count($items));
	}

	public function testRaw()
	{
		DB::collection('users')->insert(array(
			array('name' => 'Jane Doe', 'age' => 20),
			array('name' => 'John Doe', 'age' => 25)
		));

182 183
		$cursor = DB::collection('users')->raw(function($collection)
		{
184 185 186 187 188 189 190
			return $collection->find(array('age' => 20));
		});

		$this->assertInstanceOf('MongoCursor', $cursor);
		$this->assertEquals(1, $cursor->count());

		$collection = DB::collection('users')->raw();
191
		$this->assertInstanceOf('Jenssegers\Mongodb\Collection', $collection);
Jens Segers's avatar
Jens Segers committed
192

193
		$collection = User::raw();
194
		$this->assertInstanceOf('Jenssegers\Mongodb\Collection', $collection);
195

Jens Segers's avatar
Jens Segers committed
196 197 198
		$results = DB::collection('users')->whereRaw(array('age' => 20))->get();
		$this->assertEquals(1, count($results));
		$this->assertEquals('Jane Doe', $results[0]['name']);
199 200 201 202 203 204
	}

	public function testPush()
	{
		$id = DB::collection('users')->insertGetId(array(
			'name' => 'John Doe',
205 206
			'tags' => array(),
			'messages' => array(),
207 208 209
		));

		DB::collection('users')->where('_id', $id)->push('tags', 'tag1');
210

211 212 213 214 215 216 217 218 219 220
		$user = DB::collection('users')->find($id);
		$this->assertTrue(is_array($user['tags']));
		$this->assertEquals(1, count($user['tags']));
		$this->assertEquals('tag1', $user['tags'][0]);

		DB::collection('users')->where('_id', $id)->push('tags', 'tag2');
		$user = DB::collection('users')->find($id);
		$this->assertEquals(2, count($user['tags']));
		$this->assertEquals('tag2', $user['tags'][1]);

221 222 223 224 225 226 227 228 229 230
		// Add duplicate
		DB::collection('users')->where('_id', $id)->push('tags', 'tag2');
		$user = DB::collection('users')->find($id);
		$this->assertEquals(3, count($user['tags']));

		// Add unique
		DB::collection('users')->where('_id', $id)->push('tags', 'tag1', true);
		$user = DB::collection('users')->find($id);
		$this->assertEquals(3, count($user['tags']));

231 232
		$message = array('from' => 'Jane', 'body' => 'Hi John');
		DB::collection('users')->where('_id', $id)->push('messages', $message);
233
		$user = DB::collection('users')->find($id);
234
		$this->assertTrue(is_array($user['messages']));
235
		$this->assertEquals(1, count($user['messages']));
236
		$this->assertEquals($message, $user['messages'][0]);
237 238 239 240 241 242

		// Raw
		DB::collection('users')->where('_id', $id)->push(array('tags' => 'tag3', 'messages' => array('from' => 'Mark', 'body' => 'Hi John')));
		$user = DB::collection('users')->find($id);
		$this->assertEquals(4, count($user['tags']));
		$this->assertEquals(2, count($user['messages']));
243 244 245 246
	}

	public function testPull()
	{
247 248
		$message1 = array('from' => 'Jane', 'body' => 'Hi John');
		$message2 = array('from' => 'Mark', 'body' => 'Hi John');
249

250 251
		$id = DB::collection('users')->insertGetId(array(
			'name' => 'John Doe',
252
			'tags' => array('tag1', 'tag2', 'tag3', 'tag4'),
253
			'messages' => array($message1, $message2)
254 255 256
		));

		DB::collection('users')->where('_id', $id)->pull('tags', 'tag3');
257

258 259 260 261 262
		$user = DB::collection('users')->find($id);
		$this->assertTrue(is_array($user['tags']));
		$this->assertEquals(3, count($user['tags']));
		$this->assertEquals('tag4', $user['tags'][2]);

263
		DB::collection('users')->where('_id', $id)->pull('messages', $message1);
264

265
		$user = DB::collection('users')->find($id);
266
		$this->assertTrue(is_array($user['messages']));
267 268 269 270 271 272
		$this->assertEquals(1, count($user['messages']));

		// Raw
		DB::collection('users')->where('_id', $id)->pull(array('tags' => 'tag2', 'messages' => $message2));
		$user = DB::collection('users')->find($id);
		$this->assertEquals(2, count($user['tags']));
273
		$this->assertEquals(0, count($user['messages']));
274 275 276 277 278
	}

	public function testDistinct()
	{
		DB::collection('items')->insert(array(
Jens Segers's avatar
Jens Segers committed
279 280 281 282
			array('name' => 'knife', 'type' => 'sharp',),
			array('name' => 'fork',  'type' => 'sharp'),
			array('name' => 'spoon', 'type' => 'round'),
			array('name' => 'spoon', 'type' => 'round')
283 284
		));

285 286 287
		$items = DB::collection('items')->distinct('name')->get(); sort($items);
		$this->assertEquals(3, count($items));
		$this->assertEquals(array('fork', 'knife', 'spoon'), $items);
288

289 290 291
		$types = DB::collection('items')->distinct('type')->get(); sort($types);
		$this->assertEquals(2, count($types));
		$this->assertEquals(array('round', 'sharp'), $types);
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
	}

	public function testCustomId()
	{
		DB::collection('items')->insert(array(
			array('_id' => 'knife', 'type' => 'sharp', 'amount' => 34),
			array('_id' => 'fork',  'type' => 'sharp', 'amount' => 20),
			array('_id' => 'spoon', 'type' => 'round', 'amount' => 3)
		));

		$item = DB::collection('items')->find('knife');
		$this->assertEquals('knife', $item['_id']);

		$item = DB::collection('items')->where('_id', 'fork')->first();
		$this->assertEquals('fork', $item['_id']);
Jens Segers's avatar
Jens Segers committed
307 308 309 310 311 312 313 314

		DB::collection('users')->insert(array(
			array('_id' => 1, 'name' => 'Jane Doe'),
			array('_id' => 2, 'name' => 'John Doe')
		));

		$item = DB::collection('users')->find(1);
		$this->assertEquals(1, $item['_id']);
315 316 317 318 319 320 321 322 323 324 325
	}

	public function testTake()
	{
		DB::collection('items')->insert(array(
			array('name' => 'knife', 'type' => 'sharp', 'amount' => 34),
			array('name' => 'fork',  'type' => 'sharp', 'amount' => 20),
			array('name' => 'spoon', 'type' => 'round', 'amount' => 3),
			array('name' => 'spoon', 'type' => 'round', 'amount' => 14)
		));

326
		$items = DB::collection('items')->orderBy('name')->take(2)->get();
327
		$this->assertEquals(2, count($items));
328
		$this->assertEquals('fork', $items[0]['name']);
329 330 331 332 333 334 335 336 337 338 339
	}

	public function testSkip()
	{
		DB::collection('items')->insert(array(
			array('name' => 'knife', 'type' => 'sharp', 'amount' => 34),
			array('name' => 'fork',  'type' => 'sharp', 'amount' => 20),
			array('name' => 'spoon', 'type' => 'round', 'amount' => 3),
			array('name' => 'spoon', 'type' => 'round', 'amount' => 14)
		));

340
		$items = DB::collection('items')->orderBy('name')->skip(2)->get();
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
		$this->assertEquals(2, count($items));
		$this->assertEquals('spoon', $items[0]['name']);
	}

	public function testPluck()
	{
		DB::collection('users')->insert(array(
			array('name' => 'Jane Doe', 'age' => 20),
			array('name' => 'John Doe', 'age' => 25)
		));

		$age = DB::collection('users')->where('name', 'John Doe')->pluck('age');
		$this->assertEquals(25, $age);
	}

	public function testList()
	{
		DB::collection('items')->insert(array(
			array('name' => 'knife', 'type' => 'sharp', 'amount' => 34),
			array('name' => 'fork',  'type' => 'sharp', 'amount' => 20),
			array('name' => 'spoon', 'type' => 'round', 'amount' => 3),
			array('name' => 'spoon', 'type' => 'round', 'amount' => 14)
		));

		$list = DB::collection('items')->lists('name');
366
		sort($list);
367
		$this->assertEquals(4, count($list));
368
		$this->assertEquals(array('fork', 'knife', 'spoon', 'spoon'), $list);
369 370

		$list = DB::collection('items')->lists('type', 'name');
371
		$this->assertEquals(3, count($list));
372 373 374
		$this->assertEquals(array('knife' => 'sharp', 'fork' => 'sharp', 'spoon' => 'round'), $list);
	}

375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
	public function testAggregate()
	{
		DB::collection('items')->insert(array(
			array('name' => 'knife', 'type' => 'sharp', 'amount' => 34),
			array('name' => 'fork',  'type' => 'sharp', 'amount' => 20),
			array('name' => 'spoon', 'type' => 'round', 'amount' => 3),
			array('name' => 'spoon', 'type' => 'round', 'amount' => 14)
		));

		$this->assertEquals(71, DB::collection('items')->sum('amount'));
		$this->assertEquals(4, DB::collection('items')->count('amount'));
		$this->assertEquals(3, DB::collection('items')->min('amount'));
		$this->assertEquals(34, DB::collection('items')->max('amount'));
		$this->assertEquals(17.75, DB::collection('items')->avg('amount'));

		$this->assertEquals(2, DB::collection('items')->where('name', 'spoon')->count('amount'));
		$this->assertEquals(14, DB::collection('items')->where('name', 'spoon')->max('amount'));
	}

	public function testSubdocumentAggregate()
	{
		DB::collection('items')->insert(array(
			array('name' => 'knife', 'amount' => array('hidden' => 10, 'found' => 3)),
			array('name' => 'fork',  'amount' => array('hidden' => 35, 'found' => 12)),
			array('name' => 'spoon', 'amount' => array('hidden' => 14, 'found' => 21)),
			array('name' => 'spoon', 'amount' => array('hidden' => 6, 'found' => 4))
		));

		$this->assertEquals(65, DB::collection('items')->sum('amount.hidden'));
		$this->assertEquals(4, DB::collection('items')->count('amount.hidden'));
		$this->assertEquals(6, DB::collection('items')->min('amount.hidden'));
		$this->assertEquals(35, DB::collection('items')->max('amount.hidden'));
		$this->assertEquals(16.25, DB::collection('items')->avg('amount.hidden'));
	}

410 411 412 413 414 415 416 417 418 419 420
	public function testUpsert()
	{
		DB::collection('items')->where('name', 'knife')
							   ->update(
							   		array('amount' => 1),
							   		array('upsert' => true)
							   	);

		$this->assertEquals(1, DB::collection('items')->count());
	}

Jens Segers's avatar
Jens Segers committed
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
	public function testUnset()
	{
		$id1 = DB::collection('users')->insertGetId(array('name' => 'John Doe', 'note1' => 'ABC', 'note2' => 'DEF'));
		$id2 = DB::collection('users')->insertGetId(array('name' => 'Jane Doe', 'note1' => 'ABC', 'note2' => 'DEF'));

		DB::collection('users')->where('name', 'John Doe')->unset('note1');

		$user1 = DB::collection('users')->find($id1);
		$user2 = DB::collection('users')->find($id2);

		$this->assertFalse(isset($user1['note1']));
		$this->assertTrue(isset($user1['note2']));
		$this->assertTrue(isset($user2['note1']));
		$this->assertTrue(isset($user2['note2']));

		DB::collection('users')->where('name', 'Jane Doe')->unset(array('note1', 'note2'));

		$user2 = DB::collection('users')->find($id2);
		$this->assertFalse(isset($user2['note1']));
		$this->assertFalse(isset($user2['note2']));
	}

443 444
	public function testUpdateSubdocument()
	{
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
		$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"))),
460 461
		));

462 463
		$user = DB::collection('users')->where('birthday', new MongoDate(strtotime("1980-01-01 00:00:00")))->first();
		$this->assertEquals('John Doe', $user['name']);
464

465 466 467
		$user = DB::collection('users')->where('birthday', '=', new DateTime("1980-01-01 00:00:00"))->first();
		$this->assertEquals('John Doe', $user['name']);

468 469
		$start = new MongoDate(strtotime("1981-01-01 00:00:00"));
		$stop = new MongoDate(strtotime("1982-01-01 00:00:00"));
470

471 472
		$users = DB::collection('users')->whereBetween('birthday', array($start, $stop))->get();
		$this->assertEquals(2, count($users));
473 474
	}

475 476 477 478 479 480 481 482 483 484
	public function testOperators()
	{
		DB::collection('users')->insert(array(
			array('name' => 'John Doe', 'age' => 30),
			array('name' => 'Jane Doe'),
			array('name' => 'Robert Roe', 'age' => 'thirty-one'),
		));

		$results = DB::collection('users')->where('age', 'exists', true)->get();
		$this->assertEquals(2, count($results));
485 486 487
		$resultsNames = array($results[0]['name'], $results[1]['name']);
		$this->assertContains('John Doe', $resultsNames);
		$this->assertContains('Robert Roe', $resultsNames);
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522

		$results = DB::collection('users')->where('age', 'exists', false)->get();
		$this->assertEquals(1, count($results));
		$this->assertEquals('Jane Doe', $results[0]['name']);

		$results = DB::collection('users')->where('age', 'type', 2)->get();
		$this->assertEquals(1, count($results));
		$this->assertEquals('Robert Roe', $results[0]['name']);

		$results = DB::collection('users')->where('age', 'mod', array(15, 0))->get();
		$this->assertEquals(1, count($results));
		$this->assertEquals('John Doe', $results[0]['name']);

		$results = DB::collection('users')->where('age', 'mod', array(29, 1))->get();
		$this->assertEquals(1, count($results));
		$this->assertEquals('John Doe', $results[0]['name']);

		$results = DB::collection('users')->where('age', 'mod', array(14, 0))->get();
		$this->assertEquals(0, count($results));

		DB::collection('items')->insert(array(
			array('name' => 'fork',  'tags' => array('sharp', 'pointy')),
			array('name' => 'spork', 'tags' => array('sharp', 'pointy', 'round', 'bowl')),
			array('name' => 'spoon', 'tags' => array('round', 'bowl')),
		));

		$results = DB::collection('items')->where('tags', 'all', array('sharp', 'pointy'))->get();
		$this->assertEquals(2, count($results));

		$results = DB::collection('items')->where('tags', 'all', array('sharp', 'round'))->get();
		$this->assertEquals(1, count($results));

		$results = DB::collection('items')->where('tags', 'size', 2)->get();
		$this->assertEquals(2, count($results));

523 524 525
		$results = DB::collection('items')->where('tags', '$size', 2)->get();
		$this->assertEquals(2, count($results));

526 527 528 529 530
		$results = DB::collection('items')->where('tags', 'size', 3)->get();
		$this->assertEquals(0, count($results));

		$results = DB::collection('items')->where('tags', 'size', 4)->get();
		$this->assertEquals(1, count($results));
Jens Segers's avatar
Jens Segers committed
531 532 533 534

		$regex = new MongoRegex("/.*doe/i");
		$results = DB::collection('users')->where('name', 'regex', $regex)->get();
		$this->assertEquals(2, count($results));
535

536 537 538 539
		$regex = new MongoRegex("/.*doe/i");
		$results = DB::collection('users')->where('name', 'regexp', $regex)->get();
		$this->assertEquals(2, count($results));

540 541
		$results = DB::collection('users')->where('name', 'REGEX', $regex)->get();
		$this->assertEquals(2, count($results));
Jens Segers's avatar
Jens Segers committed
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562

		DB::collection('users')->insert(array(
			array(
				'name' => 'John Doe',
				'addresses' => array(
					array('city' => 'Ghent'),
					array('city' => 'Paris')
				)
			),
			array(
				'name' => 'Jane Doe',
				'addresses' => array(
					array('city' => 'Brussels'),
					array('city' => 'Paris')
				)
			)
		));

		$users = DB::collection('users')->where('addresses', 'elemMatch', array('city' => 'Brussels'))->get();
		$this->assertEquals(1, count($users));
		$this->assertEquals('Jane Doe', $users[0]['name']);
563 564
	}

565 566 567 568 569
	public function testIncrement()
	{
		DB::collection('users')->insert(array(
			array('name' => 'John Doe', 'age' => 30, 'note' => 'adult'),
			array('name' => 'Jane Doe', 'age' => 10, 'note' => 'minor'),
570
			array('name' => 'Robert Roe', 'age' => null),
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
			array('name' => 'Mark Moe'),
		));

		$user = DB::collection('users')->where('name', 'John Doe')->first();
		$this->assertEquals(30, $user['age']);

		DB::collection('users')->where('name', 'John Doe')->increment('age');
		$user = DB::collection('users')->where('name', 'John Doe')->first();
		$this->assertEquals(31, $user['age']);

		DB::collection('users')->where('name', 'John Doe')->decrement('age');
		$user = DB::collection('users')->where('name', 'John Doe')->first();
		$this->assertEquals(30, $user['age']);

		DB::collection('users')->where('name', 'John Doe')->increment('age', 5);
		$user = DB::collection('users')->where('name', 'John Doe')->first();
		$this->assertEquals(35, $user['age']);

		DB::collection('users')->where('name', 'John Doe')->decrement('age', 5);
		$user = DB::collection('users')->where('name', 'John Doe')->first();
		$this->assertEquals(30, $user['age']);

		DB::collection('users')->where('name', 'Jane Doe')->increment('age', 10, array('note' => 'adult'));
		$user = DB::collection('users')->where('name', 'Jane Doe')->first();
		$this->assertEquals(20, $user['age']);
		$this->assertEquals('adult', $user['note']);

		DB::collection('users')->where('name', 'John Doe')->decrement('age', 20, array('note' => 'minor'));
		$user = DB::collection('users')->where('name', 'John Doe')->first();
		$this->assertEquals(10, $user['age']);
		$this->assertEquals('minor', $user['note']);

		DB::collection('users')->increment('age');
		$user = DB::collection('users')->where('name', 'John Doe')->first();
		$this->assertEquals(11, $user['age']);
		$user = DB::collection('users')->where('name', 'Jane Doe')->first();
		$this->assertEquals(21, $user['age']);
608 609
		$user = DB::collection('users')->where('name', 'Robert Roe')->first();
		$this->assertEquals(null, $user['age']);
610
		$user = DB::collection('users')->where('name', 'Mark Moe')->first();
611
		$this->assertEquals(1, $user['age']);
612 613
	}

614
}