From 2efddca0e22cd0701cdf87bf0d6d0e0682b131cc Mon Sep 17 00:00:00 2001 From: zYne Date: Wed, 10 Jan 2007 20:36:40 +0000 Subject: [PATCH] added sequence test case --- tests/SequenceTestCase.php | 81 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/SequenceTestCase.php diff --git a/tests/SequenceTestCase.php b/tests/SequenceTestCase.php new file mode 100644 index 000000000..03b3a4111 --- /dev/null +++ b/tests/SequenceTestCase.php @@ -0,0 +1,81 @@ +. + */ + +/** + * Doctrine_Sequence_TestCase + * + * @package Doctrine + * @author Konsta Vesterinen + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Sequence_TestCase extends Doctrine_UnitTestCase +{ + public function prepareData() + { + } + public function prepareTables() + { + } + public function testSequencesAreSupportedForRecords() + { + $this->profiler = new Doctrine_Db_Profiler(); + + $this->dbh->setListener($this->profiler); + + $r = new CustomSequenceRecord; + $r->name = 'custom seq'; + $r->save(); + + // the last profiled event is transaction commit + $this->assertEqual($this->profiler->pop()->getType(), Doctrine_Db_Event::COMMIT); + // query execution + $this->assertEqual($this->profiler->pop()->getQuery(), 'INSERT INTO custom_sequence_record (name, id) VALUES (?, ?)'); + // query prepare + $this->assertEqual($this->profiler->pop()->getQuery(), 'INSERT INTO custom_sequence_record (name, id) VALUES (?, ?)'); + + // sequence generation (first fails) + $this->assertEqual($this->profiler->pop()->getQuery(), 'INSERT INTO custom_seq_seq (id) VALUES (1)'); + $this->assertEqual($this->profiler->pop()->getQuery(), 'CREATE TABLE custom_seq_seq (id INTEGER PRIMARY KEY DEFAULT 0 NOT NULL)'); + $this->assertEqual($this->profiler->pop()->getQuery(), 'INSERT INTO custom_seq_seq (id) VALUES (NULL)'); + + // transaction begin + $this->assertEqual($this->profiler->pop()->getType(), Doctrine_Db_Event::BEGIN); + $this->assertEqual($this->profiler->pop()->getQuery(), 'CREATE TABLE custom_sequence_record (id INTEGER, name VARCHAR(2147483647))'); + } +} +class CustomSequenceRecord extends Doctrine_Record { + public function setTableDefinition() + { + $this->hasColumn('id', 'integer', null, array('primary', 'sequence' => 'custom_seq')); + $this->hasColumn('name', 'string'); + } +} +class SequenceRecord extends Doctrine_Record { + public function setTableDefinition() + { + $this->hasColumn('id', 'integer', null, array('primary', 'sequence')); + $this->hasColumn('name', 'string'); + } +}