From eaf2fdcdce41d8456420cf70175b7fca0d266777 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 23 Jul 2007 23:20:26 +0000 Subject: [PATCH] tests for check constraints --- tests/Export/CheckConstraintTestCase.php | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/Export/CheckConstraintTestCase.php diff --git a/tests/Export/CheckConstraintTestCase.php b/tests/Export/CheckConstraintTestCase.php new file mode 100644 index 000000000..8c40ec7b1 --- /dev/null +++ b/tests/Export/CheckConstraintTestCase.php @@ -0,0 +1,65 @@ +. + */ + +/** + * Doctrine_Export_CheckConstraint_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_Export_CheckConstraint_TestCase extends Doctrine_UnitTestCase +{ + public function prepareData() + { } + public function prepareTables() + { } + + public function testCheckConstraints() + { + $e = $this->conn->export; + + $sql = $e->exportClassesSql(array('CheckConstraintTest')); + + $this->assertEqual($sql[0], 'CREATE TABLE check_constraint_test (id INTEGER PRIMARY KEY AUTOINCREMENT, price DECIMAL(2,2), discounted_price DECIMAL(2,2)), CHECK (price > 100), CHECK (price < 5000), CHECK (price > discounted_price))'); + + try { + $dbh = new PDO('sqlite::memory:'); + $dbh->exec($sql[0]); + $this->pass(); + } catch (PDOException $e) { + $this->fail(); + } + } +} +class CheckConstraintTest extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('price', 'decimal', 2, array('max' => 5000, 'min' => 100)); + $this->hasColumn('discounted_price', 'decimal', 2); + $this->check('price > discounted_price'); + } +}