<?php
/**
 * BemmelhorTestFixture class
 *
 * PHP version 5
 *
 * @category TestSuite
 * @package  Bemmelhor
 * @version  1.4
 * @author   Fabricio S Costa <fabriciojf@gmail.com>
 * @author   Rachman Chavik <rchavik@gmail.com>
 * 
 * @link     http://www.bemmelhor.org
 */
class BemmelhorTestFixture extends CakeTestFixture {

/**
 * _fixSequence
 *
 * @param Postgres $db
 */
	protected function _fixSequence($db) {
		$sql = sprintf("
			SELECT setval(pg_get_serial_sequence('%s', 'id'), (SELECT MAX(id) FROM %s))",
			$this->table, $this->table);

		$db->execute($sql);
	}

/**
 * insert
 *
 * @param Object $db
 * @return array
 */
	public function insert($db) {
		$result = parent::insert($db);
		if ($result === true && $db instanceof Postgres) {
			$this->_fixSequence($db);
		}
		return $result;
	}

}
