Code Duplication    Length = 44-44 lines in 2 locations

tests/model/SQLQueryTest.php 2 locations

@@ 430-473 (lines=44) @@
427
		$this->assertEquals(array('Chimp', 'Brown'), $parameters);
428
	}
429
430
	public function testSelectFirst() {
431
		// Test first from sequence
432
		$query = new SQLQuery();
433
		$query->setFrom('"SQLQueryTest_DO"');
434
		$query->setOrderBy('"Name"');
435
		$result = $query->firstRow()->execute();
436
437
		$records = array();
438
		foreach($result as $row) {
439
			$records[] = $row;
440
		}
441
442
		$this->assertCount(1, $records);
443
		$this->assertEquals('Object 1', $records[0]['Name']);
444
445
		// Test first from empty sequence
446
		$query = new SQLQuery();
447
		$query->setFrom('"SQLQueryTest_DO"');
448
		$query->setOrderBy('"Name"');
449
		$query->setWhere(array('"Name"' => 'Nonexistent Object'));
450
		$result = $query->firstRow()->execute();
451
452
		$records = array();
453
		foreach($result as $row) {
454
			$records[] = $row;
455
		}
456
457
		$this->assertCount(0, $records);
458
459
		// Test that given the last item, the 'first' in this list matches the last
460
		$query = new SQLQuery();
461
		$query->setFrom('"SQLQueryTest_DO"');
462
		$query->setOrderBy('"Name"');
463
		$query->setLimit(1, 1);
464
		$result = $query->firstRow()->execute();
465
466
		$records = array();
467
		foreach($result as $row) {
468
			$records[] = $row;
469
		}
470
471
		$this->assertCount(1, $records);
472
		$this->assertEquals('Object 2', $records[0]['Name']);
473
	}
474
475
	public function testSelectLast() {
476
		// Test last in sequence
@@ 475-518 (lines=44) @@
472
		$this->assertEquals('Object 2', $records[0]['Name']);
473
	}
474
475
	public function testSelectLast() {
476
		// Test last in sequence
477
		$query = new SQLQuery();
478
		$query->setFrom('"SQLQueryTest_DO"');
479
		$query->setOrderBy('"Name"');
480
		$result = $query->lastRow()->execute();
481
482
		$records = array();
483
		foreach($result as $row) {
484
			$records[] = $row;
485
		}
486
487
		$this->assertCount(1, $records);
488
		$this->assertEquals('Object 2', $records[0]['Name']);
489
490
		// Test last from empty sequence
491
		$query = new SQLQuery();
492
		$query->setFrom('"SQLQueryTest_DO"');
493
		$query->setOrderBy('"Name"');
494
		$query->setWhere(array("\"Name\" = 'Nonexistent Object'"));
495
		$result = $query->lastRow()->execute();
496
497
		$records = array();
498
		foreach($result as $row) {
499
			$records[] = $row;
500
		}
501
502
		$this->assertCount(0, $records);
503
504
		// Test that given the first item, the 'last' in this list matches the first
505
		$query = new SQLQuery();
506
		$query->setFrom('"SQLQueryTest_DO"');
507
		$query->setOrderBy('"Name"');
508
		$query->setLimit(1);
509
		$result = $query->lastRow()->execute();
510
511
		$records = array();
512
		foreach($result as $row) {
513
			$records[] = $row;
514
		}
515
516
		$this->assertCount(1, $records);
517
		$this->assertEquals('Object 1', $records[0]['Name']);
518
	}
519
520
	/**
521
	 * Tests aggregate() function