diff --git a/generator/lib/model/ForeignKey.php b/generator/lib/model/ForeignKey.php index 3c8bd7377..beb85918d 100644 --- a/generator/lib/model/ForeignKey.php +++ b/generator/lib/model/ForeignKey.php @@ -283,6 +283,8 @@ public function setTable(Table $parent) /** * Get the parent Table of the foreign key + * + * @return Table */ public function getTable() { diff --git a/generator/lib/model/Table.php b/generator/lib/model/Table.php index a9ed2dc2e..96852fef0 100644 --- a/generator/lib/model/Table.php +++ b/generator/lib/model/Table.php @@ -1581,6 +1581,18 @@ public function getForeignKeys() return $this->foreignKeys; } + /** + * Removes a foreign key. + * + * @param ForeignKey $fk + */ + public function removeForeignKey(ForeignKey $fk){ + $idx = array_search($fk, $this->foreignKeys); + if ($idx !== false){ + unset($this->foreignKeys[$idx]); + } + } + /** * Returns a Collection of parameters relevant for the chosen * id generation method. @@ -1601,7 +1613,7 @@ public function getIndices() /** * Returns an Array containing all the UKs in the table - * @return array Unique[] + * @return Unique[] */ public function getUnices() { @@ -1878,7 +1890,7 @@ public function appendXml(DOMNode $node) * Returns the collection of Columns which make up the single primary * key for this table. * - * @return array Column[] A list of the primary key parts. + * @return Column[] A list of the primary key parts. */ public function getPrimaryKey() { diff --git a/generator/lib/model/diff/PropelTableDiff.php b/generator/lib/model/diff/PropelTableDiff.php index 4650887d4..078949dbb 100644 --- a/generator/lib/model/diff/PropelTableDiff.php +++ b/generator/lib/model/diff/PropelTableDiff.php @@ -114,7 +114,7 @@ public function removeAddedColumn($columnName) /** * Getter for the addedColumns property * - * @return array + * @return Column[] */ public function getAddedColumns() { @@ -534,7 +534,7 @@ public function addRemovedFk($fkName, ForeignKey $removedFk) */ public function removeRemovedFk($fkName) { - unset($this->removedFks[$columnName]); + unset($this->removedFks[$fkName]); } /** @@ -579,6 +579,96 @@ public function getModifiedFks() return $this->modifiedFks; } + + /** + * @return bool + */ + public function hasModifiedFks() + { + return !!$this->modifiedFks; + } + + /** + * @return bool + */ + public function hasModifiedIndices() + { + return !!$this->modifiedIndices; + } + + /** + * @return bool + */ + public function hasModifiedColumns() + { + return !!$this->modifiedColumns; + } + + /** + * @return bool + */ + public function hasRemovedFks() + { + return !!$this->modifiedColumns; + } + + /** + * @return bool + */ + public function hasRemovedIndices() + { + return !!$this->removedIndices; + } + + /** + * @return bool + */ + public function hasRenamedColumns() + { + return !!$this->renamedColumns; + } + + /** + * @return bool + */ + public function hasRemovedColumns() + { + return !!$this->removedColumns; + } + + /** + * @return bool + */ + public function hasAddedColumns() + { + return !!$this->addedColumns; + } + + /** + * @return bool + */ + public function hasAddedIndices() + { + return !!$this->addedIndices; + } + + /** + * @return bool + */ + public function hasAddedFks() + { + return !!$this->addedFks; + } + + /** + * @return bool + */ + public function hasAddedPkColumns() + { + return !!$this->addedPkColumns; + } + + /** * Get the reverse diff for this diff * diff --git a/generator/lib/platform/SqlitePlatform.php b/generator/lib/platform/SqlitePlatform.php index 139eff62e..b8dd35adb 100644 --- a/generator/lib/platform/SqlitePlatform.php +++ b/generator/lib/platform/SqlitePlatform.php @@ -20,6 +20,22 @@ class SqlitePlatform extends DefaultPlatform { + /** + * If we should generate FOREIGN KEY statements. + * This is since SQLite version 3.6.19 possible. + * + * @var bool + */ + private $foreignKeySupport = true; + + /** + * If we should alter the table through creating a temporarily crated table, + * moving all item to the new one and finally rename the temp table. + * + * @var bool + */ + private $tableAlteringWorkaround = true; + /** * Initializes db specific domain mapping. */ @@ -44,18 +60,171 @@ protected function initialize() */ public function getAutoIncrement() { - return "PRIMARY KEY"; + return "PRIMARY KEY AUTOINCREMENT"; } + /** + * {@inheritdoc} + */ public function getMaxColumnNameLength() { return 1024; } + + /** + * {@inheritdoc} + */ + public function setGeneratorConfig(GeneratorConfigInterface $generatorConfig) + { + if ($foreignKeySupport = $generatorConfig->getBuildProperty('sqliteForeignkey')) { + $this->foreignKeySupport = !!$foreignKeySupport; + } + if ($tableAlteringWorkaround = $generatorConfig->getBuildProperty('sqliteTableAlteringWorkaround')) { + $this->tableAlteringWorkaround = !!$tableAlteringWorkaround; + } + } + + /** + * {@inheritdoc} + */ + public function getModifyTableDDL(PropelTableDiff $tableDiff) + { + + $this->checkCompositePk($tableDiff->getToTable()); + + $changedNotEditableThroughDirectDDL = $this->tableAlteringWorkaround && (false + || $tableDiff->hasModifiedFks() + || $tableDiff->hasModifiedIndices() + || $tableDiff->hasModifiedColumns() + || $tableDiff->hasRenamedColumns() + + || $tableDiff->hasRemovedFks() + || $tableDiff->hasRemovedIndices() + || $tableDiff->hasRemovedColumns() + + || $tableDiff->hasAddedIndices() + || $tableDiff->hasAddedFks() + || $tableDiff->hasAddedPkColumns() + ); + + if ($this->tableAlteringWorkaround && !$changedNotEditableThroughDirectDDL && $tableDiff->hasAddedColumns()){ + + $addedCols = $tableDiff->getAddedColumns(); + foreach ($addedCols as $column){ + + $sqlChangeNotSupported = false + + //The column may not have a PRIMARY KEY or UNIQUE constraint. + || $column->isPrimaryKey() + || $column->isUnique() + + //The column may not have a default value of CURRENT_TIME, CURRENT_DATE, CURRENT_TIMESTAMP, + //or an expression in parentheses. + || false !== array_search( + $column->getDefaultValue(), array('CURRENT_TIME', 'CURRENT_DATE', 'CURRENT_TIMESTAMP')) + || substr(trim($column->getDefaultValue()), 0, 1) == '(' + + //If a NOT NULL constraint is specified, then the column must have a default value other than NULL. + || ($column->isNotNull() && $column->getDefaultValue() == 'NULL') + ; + + if ($sqlChangeNotSupported){ + $changedNotEditableThroughDirectDDL = true; + break; + } + + } + } + + if ($changedNotEditableThroughDirectDDL){ + return $this->getMigrationTableDDL($tableDiff); + } else { + return parent::getModifyTableDDL($tableDiff); + } + + } + + /** + * Creates a temporarily created table with the new schema, + * moves all items into it and drops the origin as well as renames the temp table to the origin then. + * + * @param PropelTableDiff $tableDiff + * @return string + */ + public function getMigrationTableDDL(PropelTableDiff $tableDiff){ + + $pattern = " +%s; +INSERT INTO %s (%s) + SELECT %s FROM %s; +DROP TABLE %s; +ALTER TABLE %s RENAME TO %s; +"; + + $originTable = $tableDiff->getFromTable(); + $newTable = $tableDiff->getToTable(); + + $originTableName = $originTable->getName(); + $tempTableName = $newTable->getCommonName().'__migration_temp'; + $newTable->setCommonName($tempTableName); + + $newTableFields = $this->getColumnListDDL($newTable->getColumns()); + $originTableFields = $this->getColumnListDDL($originTable->getColumns()); + + //todo check field diff + + + + $sql = sprintf($pattern, + $this->getAddTableDDL($newTable), + $this->quoteIdentifier($originTableName), + $newTableFields, + $originTableFields, + $this->quoteIdentifier($originTableName), + $this->quoteIdentifier($originTableName), + $this->quoteIdentifier($tempTableName), + $this->quoteIdentifier($originTableName) + ); + + if ($this->foreignKeySupport){ + $sql = sprintf(" +PRAGMA foreign_keys = OFF; +%s +PRAGMA foreign_keys = ON; +", + $sql); + } + + return $sql; + } + + /** + * {@inheritdoc} + */ + public function getAddTablesDDL(Database $database) + { + $ret = $this->getBeginDDL(); + foreach ($database->getTablesForSql() as $table) { + $ret .= $this->getCommentBlockDDL($table->getName()); + $ret .= $this->getDropTableDDL($table); + $ret .= $this->getAddTableDDL($table); + $ret .= $this->getAddIndicesDDL($table); + } + $ret .= $this->getEndDDL(); + + return $ret; + } + + /** + * {@inheritdoc} + */ public function getAddTableDDL(Table $table) { $tableDescription = $table->hasDescription() ? $this->getCommentLineDDL($table->getDescription()) : ''; + $this->checkCompositePk($table); + $lines = array(); foreach ($table->getColumns() as $column) { @@ -73,6 +242,12 @@ public function getAddTableDDL(Table $table) $lines[] = $this->getUniqueDDL($unique); } + foreach ($table->getForeignKeys() as $foreignKey) { + if ($line = $this->getForeignKeyDDL($foreignKey)){ + $lines[] = str_replace("\n", "\n ", $line); + } + } + $sep = ", "; @@ -90,26 +265,130 @@ public function getAddTableDDL(Table $table) ); } + /** + * Unfortunately, SQLite does not support composite pks where one is AUTOINCREMENT, + * so we have so flag both as NOT NULL and create a UNIQUE constraint. + * + * @param Table $table + */ + public function checkCompositePk(Table $table) + { + if (count($pks = $table->getPrimaryKey()) > 1 && $table->hasAutoIncrementPrimaryKey()){ + foreach ($pks as $pk){ + //no pk can be NULL, as usual + $pk->setNotNull(true); + //in SQLite the column with the AUTOINCREMENT MUST be a primary key, too. + if (!$pk->isAutoIncrement()){ + //for all other sub keys we remove it, since we create a UNIQUE constraint over all primary keys. + $pk->setPrimaryKey(false); + } + } + + //search if there is already a UNIQUE constraint over the primary keys + $pkUniqueExist = false; + foreach ($table->getUnices() as $unique){ + $allPk = false; + foreach ($unique->getColumns() as $columnName){ + $allPk &= $table->getColumn($columnName)->isPrimaryKey(); + } + if ($allPk){ + //there's already a unique constraint with the composite pk + $pkUniqueExist = true; + break; + } + } + + //there is none, let's create it + if (!$pkUniqueExist){ + $unique = new Unique(); + foreach ($pks as $pk){ + $unique->addColumn($pk); + } + $table->addUnique($unique); + } + } + + } + + + /** + * Returns the SQL for the primary key of a Table object + * @return string + */ + public function getPrimaryKeyDDL(Table $table) + { + + return parent::getPrimaryKeyDDL($table); + } + + /** + * {@inheritdoc} + */ + public function getRemoveColumnDDL(Column $column){ + //not supported + return ''; + } + + /** + * {@inheritdoc} + */ + public function getRenameColumnDDL($fromColumn, $toColumn) + { + //not supported + return ''; + } + + /** + * {@inheritdoc} + */ + public function getModifyColumnDDL(PropelColumnDiff $columnDiff){ + //not supported + return ''; + } + + /** + * {@inheritdoc} + */ + public function getModifyColumnsDDL($columnDiffs){ + //not supported + return ''; + } + + /** + * {@inheritdoc} + */ public function getDropPrimaryKeyDDL(Table $table) { - // FIXME: not supported by SQLite + //not supported return ''; } + /** + * {@inheritdoc} + */ public function getAddPrimaryKeyDDL(Table $table) { - // FIXME: not supported by SQLite + //not supported return ''; } + /** + * {@inheritdoc} + */ public function getAddForeignKeyDDL(ForeignKey $fk) { - // no need for an alter table to return comments - return $this->getForeignKeyDDL($fk); + //not supported + return ' +--- SQLite does not support altering foreign keys directly; this is just for reference +'; } + /** + * {@inheritdoc} + */ public function getDropForeignKeyDDL(ForeignKey $fk) { + //not supported return ''; } @@ -122,16 +401,29 @@ public function getDropTableDDL(Table $table) public function getForeignKeyDDL(ForeignKey $fk) { - $pattern = " --- SQLite does not support foreign keys; this is just for reference --- FOREIGN KEY (%s) REFERENCES %s (%s) -"; - return sprintf($pattern, + if ($fk->isSkipSql() || !$this->foreignKeySupport) { + return; + } + + $pattern = "FOREIGN KEY (%s) REFERENCES %s (%s)"; + + $script = sprintf($pattern, $this->getColumnListDDL($fk->getLocalColumns()), $fk->getForeignTableName(), $this->getColumnListDDL($fk->getForeignColumns()) ); + + if ($fk->hasOnUpdate()) { + $script .= " + ON UPDATE " . $fk->getOnUpdate(); + } + if ($fk->hasOnDelete()) { + $script .= " + ON DELETE " . $fk->getOnDelete(); + } + + return $script; } public function hasSize($sqlType) @@ -159,12 +451,4 @@ public function quoteIdentifier($text) { return $this->isIdentifierQuotingEnabled ? '[' . $text . ']' : $text; } - - /** - * @see Platform::supportsMigrations() - */ - public function supportsMigrations() - { - return false; - } } diff --git a/test/fixtures/bookstore/build.properties b/test/fixtures/bookstore/build.properties index b2ac9d3be..04436afe5 100644 --- a/test/fixtures/bookstore/build.properties +++ b/test/fixtures/bookstore/build.properties @@ -11,8 +11,8 @@ # you cannot refer to any properties set therein. propel.project = bookstore -propel.database = mysql -propel.database.url = mysql:dbname=test +#propel.database = sqlite +#propel.database.url = sqlite:/var/tmp/test2.db propel.mysql.tableType = InnoDB propel.disableIdentifierQuoting = true propel.schema.autoPrefix = true diff --git a/test/fixtures/bookstore/runtime-conf.xml b/test/fixtures/bookstore/runtime-conf.xml index f3fa856a8..430e9da32 100644 --- a/test/fixtures/bookstore/runtime-conf.xml +++ b/test/fixtures/bookstore/runtime-conf.xml @@ -11,40 +11,13 @@ - - mysql - - - DebugPDO - mysql:dbname=test - - root - - - - - - - - - - - - - utf8 - - - + + sqlite + + + DebugPDO + sqlite:/var/tmp/test2.db + diff --git a/test/testsuite/generator/behavior/aggregate_column/AggregateColumnBehaviorTest.php b/test/testsuite/generator/behavior/aggregate_column/AggregateColumnBehaviorTest.php index 62cbcb8f1..c296a0a1a 100644 --- a/test/testsuite/generator/behavior/aggregate_column/AggregateColumnBehaviorTest.php +++ b/test/testsuite/generator/behavior/aggregate_column/AggregateColumnBehaviorTest.php @@ -29,57 +29,59 @@ public function testParameters() public function testCompute() { - AggregateCommentQuery::create()->deleteAll($this->con); - AggregatePostQuery::create()->deleteAll($this->con); + $con = Propel::getConnection(AggregatePostPeer::DATABASE_NAME); + AggregateCommentQuery::create()->deleteAll(); + AggregatePostQuery::create()->deleteAll(); $post = new AggregatePost(); - $post->save($this->con); - $this->assertEquals(0, $post->computeNbComments($this->con), 'The compute method returns 0 for objects with no related objects'); + $post->save(); + $this->assertEquals(0, $post->computeNbComments($con), 'The compute method returns 0 for objects with no related objects'); $comment1 = new AggregateComment(); $comment1->setAggregatePost($post); - $comment1->save($this->con); - $this->assertEquals(1, $post->computeNbComments($this->con), 'The compute method computes the aggregate function on related objects'); + $comment1->save(); + $this->assertEquals(1, $post->computeNbComments($con), 'The compute method computes the aggregate function on related objects'); $comment2 = new AggregateComment(); $comment2->setAggregatePost($post); - $comment2->save($this->con); - $this->assertEquals(2, $post->computeNbComments($this->con), 'The compute method computes the aggregate function on related objects'); - $comment1->delete($this->con); - $this->assertEquals(1, $post->computeNbComments($this->con), 'The compute method computes the aggregate function on related objects'); + $comment2->save(); + $this->assertEquals(2, $post->computeNbComments($con), 'The compute method computes the aggregate function on related objects'); + $comment1->delete(); + $this->assertEquals(1, $post->computeNbComments($con), 'The compute method computes the aggregate function on related objects'); } public function testUpdate() { - AggregateCommentQuery::create()->deleteAll($this->con); - AggregatePostQuery::create()->deleteAll($this->con); + $con = Propel::getConnection(AggregatePostPeer::DATABASE_NAME); + AggregateCommentQuery::create()->deleteAll(); + AggregatePostQuery::create()->deleteAll(); $post = new AggregatePost(); - $post->save($this->con); + $post->save(); $comment = new TestableComment(); $comment->setAggregatePost($post); - $comment->save($this->con); + $comment->save($con); $this->assertNull($post->getNbComments()); - $post->updateNbComments($this->con); + $post->updateNbComments($con); $this->assertEquals(1, $post->getNbComments(), 'The update method updates the aggregate column'); - $comment->delete($this->con); + $comment->delete($con); $this->assertEquals(1, $post->getNbComments()); - $post->updateNbComments($this->con); + $post->updateNbComments($con); $this->assertEquals(0, $post->getNbComments(), 'The update method updates the aggregate column'); } public function testCreateRelated() { - AggregateCommentQuery::create()->deleteAll($this->con); - AggregatePostQuery::create()->deleteAll($this->con); + AggregateCommentQuery::create()->deleteAll(); + AggregatePostQuery::create()->deleteAll(); $post = new AggregatePost(); - $post->save($this->con); + $post->save(); $comment1 = new AggregateComment(); - $comment1->save($this->con); + $comment1->save(); $this->assertNull($post->getNbComments(), 'Adding a new foreign object does not update the aggregate column'); $comment2 = new AggregateComment(); $comment2->setAggregatePost($post); - $comment2->save($this->con); + $comment2->save(); $this->assertEquals(1, $post->getNbComments(), 'Adding a new related object updates the aggregate column'); $comment3 = new AggregateComment(); $comment3->setAggregatePost($post); - $comment3->save($this->con); + $comment3->save(); $this->assertEquals(2, $post->getNbComments(), 'Adding a new related object updates the aggregate column'); } @@ -88,7 +90,7 @@ public function testUpdateRelated() list($poll, $item1, $item2) = $this->populatePoll(); $this->assertEquals(19, $poll->getTotalScore()); $item1->setScore(10); - $item1->save($this->con); + $item1->save(); $this->assertEquals(17, $poll->getTotalScore(), 'Updating a related object updates the aggregate column'); } @@ -96,9 +98,9 @@ public function testDeleteRelated() { list($poll, $item1, $item2) = $this->populatePoll(); $this->assertEquals(19, $poll->getTotalScore()); - $item1->delete($this->con); + $item1->delete(); $this->assertEquals(7, $poll->getTotalScore(), 'Deleting a related object updates the aggregate column'); - $item2->delete($this->con); + $item2->delete(); $this->assertNull($poll->getTotalScore(), 'Deleting a related object updates the aggregate column'); } @@ -107,7 +109,7 @@ public function testUpdateRelatedWithQuery() list($poll, $item1, $item2) = $this->populatePoll(); $this->assertEquals(19, $poll->getTotalScore()); AggregateItemQuery::create() - ->update(array('Score' => 4), $this->con); + ->update(array('Score' => 4)); $this->assertEquals(8, $poll->getTotalScore(), 'Updating related objects with a query updates the aggregate column'); } @@ -117,7 +119,7 @@ public function testUpdateRelatedWithQueryUsingAlias() $this->assertEquals(19, $poll->getTotalScore()); AggregateItemQuery::create() ->setModelAlias('foo', true) - ->update(array('Score' => 4), $this->con); + ->update(array('Score' => 4)); $this->assertEquals(8, $poll->getTotalScore(), 'Updating related objects with a query using alias updates the aggregate column'); } @@ -126,7 +128,7 @@ public function testDeleteRelatedWithQuery() list($poll, $item1, $item2) = $this->populatePoll(); $this->assertEquals(19, $poll->getTotalScore()); AggregateItemQuery::create() - ->deleteAll($this->con); + ->deleteAll(); $this->assertNull($poll->getTotalScore(), 'Deleting related objects with a query updates the aggregate column'); } @@ -137,51 +139,51 @@ public function testDeleteRelatedWithQueryUsingAlias() AggregateItemQuery::create() ->setModelAlias('foo', true) ->filterById($item1->getId()) - ->delete($this->con); + ->delete(); $this->assertEquals(7, $poll->getTotalScore(), 'Deleting related objects with a query using alias updates the aggregate column'); } public function testRemoveRelation() { - AggregateCommentQuery::create()->deleteAll($this->con); - AggregatePostQuery::create()->deleteAll($this->con); + AggregateCommentQuery::create()->deleteAll(); + AggregatePostQuery::create()->deleteAll(); $post = new AggregatePost(); - $post->save($this->con); + $post->save(); $comment1 = new AggregateComment(); $comment1->setAggregatePost($post); - $comment1->save($this->con); + $comment1->save(); $comment2 = new AggregateComment(); $comment2->setAggregatePost($post); - $comment2->save($this->con); + $comment2->save(); $this->assertEquals(2, $post->getNbComments()); $comment2->setAggregatePost(null); - $comment2->save($this->con); + $comment2->save(); $this->assertEquals(1, $post->getNbComments(), 'Removing a relation changes the related object aggregate column'); } public function testReplaceRelation() { - AggregateCommentQuery::create()->deleteAll($this->con); - AggregatePostQuery::create()->deleteAll($this->con); + AggregateCommentQuery::create()->deleteAll(); + AggregatePostQuery::create()->deleteAll(); $post1 = new AggregatePost(); - $post1->save($this->con); + $post1->save(); $post2 = new AggregatePost(); - $post2->save($this->con); + $post2->save(); $comment = new AggregateComment(); $comment->setAggregatePost($post1); - $comment->save($this->con); + $comment->save(); $this->assertEquals(1, $post1->getNbComments()); $this->assertNull($post2->getNbComments()); $comment->setAggregatePost($post2); - $comment->save($this->con); + $comment->save(); $this->assertEquals(0, $post1->getNbComments(), 'Replacing a relation changes the related object aggregate column'); $this->assertEquals(1, $post2->getNbComments(), 'Replacing a relation changes the related object aggregate column'); } public function testAddMultipleComments() { - AggregateCommentQuery::create()->deleteAll($this->con); - AggregatePostQuery::create()->deleteAll($this->con); + AggregateCommentQuery::create()->deleteAll(); + AggregatePostQuery::create()->deleteAll(); $post1 = new AggregatePost(); @@ -196,15 +198,15 @@ public function testAddMultipleComments() $this->assertNull($post1->getNbComments(), 'The post start with null aggregate column'); - $post1->save($this->con); + $post1->save(); $this->assertEquals(3, $post1->getNbComments(), 'the post has 3 comments'); } public function testQueryCountOnUpdate() { - AggregateCommentQuery::create()->deleteAll($this->con); - AggregatePostQuery::create()->deleteAll($this->con); + AggregateCommentQuery::create()->deleteAll(); + AggregatePostQuery::create()->deleteAll(); $post1 = new TestablePost(); $comment = new AggregateComment(); @@ -213,7 +215,7 @@ public function testQueryCountOnUpdate() $comment2->setAggregatePost($post1); $comment3 = new AggregateComment(); $comment3->setAggregatePost($post1); - $post1->save($this->con); + $post1->save(); $this->assertEquals(3, $post1->getNbComments(), 'the post has 3 comments'); $this->assertEquals(2, $post1->countComputeCall, 'Only two call to count nbComment'); @@ -221,7 +223,7 @@ public function testQueryCountOnUpdate() $comment4 = new AggregateComment(); $comment4->setAggregatePost($post1); - $comment4->save($this->con); + $comment4->save(); $this->assertEquals(4, $post1->getNbComments(), 'the post has 4 comments'); $this->assertEquals(2, $post1->countComputeCall, 'Only two call to count nbComment'); @@ -230,13 +232,13 @@ public function testQueryCountOnUpdate() $comment5 = new AggregateComment(); $comment5->setAggregatePost($post1); - $post1->save($this->con); + $post1->save(); $this->assertEquals(5, $post1->getNbComments(), 'the post has 5 comments'); $this->assertEquals(2, $post1->countComputeCall, 'Only two call to count nbComment'); $post1->countComputeCall = 0; - $post1->save($this->con); + $post1->save(); $this->assertEquals(5, $post1->getNbComments(), 'the post has 5 comments'); $this->assertEquals(1, $post1->countComputeCall, 'Only one call to count nbComment'); @@ -244,18 +246,18 @@ public function testQueryCountOnUpdate() protected function populatePoll() { - AggregateItemQuery::create()->deleteAll($this->con); - AggregatePollQuery::create()->deleteAll($this->con); + AggregateItemQuery::create()->deleteAll(); + AggregatePollQuery::create()->deleteAll(); $poll = new AggregatePoll(); - $poll->save($this->con); + $poll->save(); $item1 = new AggregateItem(); $item1->setScore(12); $item1->setAggregatePoll($poll); - $item1->save($this->con); + $item1->save(); $item2 = new AggregateItem(); $item2->setScore(7); $item2->setAggregatePoll($poll); - $item2->save($this->con); + $item2->save(); return array($poll, $item1, $item2); } diff --git a/test/testsuite/generator/behavior/i18n/I18nBehaviorTest.php b/test/testsuite/generator/behavior/i18n/I18nBehaviorTest.php index 9b85db041..6b3991251 100644 --- a/test/testsuite/generator/behavior/i18n/I18nBehaviorTest.php +++ b/test/testsuite/generator/behavior/i18n/I18nBehaviorTest.php @@ -48,7 +48,9 @@ public function testModifyDatabaseOverridesDefaultLocale() ( [id] INTEGER NOT NULL, [locale] VARCHAR(5) DEFAULT 'fr_FR' NOT NULL, - PRIMARY KEY ([id],[locale]) + PRIMARY KEY ([id],[locale]), + FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id]) + ON DELETE CASCADE ); EOF; $this->assertContains($expected, $builder->getSQL()); @@ -82,7 +84,9 @@ public function testModifyDatabaseDoesNotOverrideTableLocale() ( [id] INTEGER NOT NULL, [locale] VARCHAR(5) DEFAULT 'pt_PT' NOT NULL, - PRIMARY KEY ([id],[locale]) + PRIMARY KEY ([id],[locale]), + FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id]) + ON DELETE CASCADE ); EOF; $this->assertContains($expected, $builder->getSQL()); @@ -113,7 +117,7 @@ public function schemaDataProvider() - + @@ -150,7 +154,7 @@ public function testModifyTableRelatesI18nTableToMainTable($schema) $builder = new PropelQuickBuilder(); $builder->setSchema($schema); $expected = <<assertContains($expected, $builder->getSQL()); } @@ -184,7 +188,9 @@ public function testModifyTableMovesI18nColumns($schema) [id] INTEGER NOT NULL, [locale] VARCHAR(5) DEFAULT 'en_US' NOT NULL, [bar] VARCHAR(100), - PRIMARY KEY ([id],[locale]) + PRIMARY KEY ([id],[locale]), + FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id]) + ON DELETE CASCADE ); EOF; $this->assertContains($expected, $builder->getSQL()); @@ -200,7 +206,7 @@ public function testModifyTableDoesNotMoveNonI18nColumns($schema) $expected = <<assertContains($expected, $builder->getSQL()); @@ -313,7 +321,9 @@ public function testModiFyTableUsesCustomLocaleColumnName() ( [id] INTEGER NOT NULL, [culture] VARCHAR(5) DEFAULT 'en_US' NOT NULL, - PRIMARY KEY ([id],[culture]) + PRIMARY KEY ([id],[culture]), + FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id]) + ON DELETE CASCADE ); EOF; $this->assertContains($expected, $builder->getSQL()); @@ -344,7 +354,9 @@ public function testModiFyTableUsesCustomLocaleDefault() ( [id] INTEGER NOT NULL, [locale] VARCHAR(5) DEFAULT 'fr_FR' NOT NULL, - PRIMARY KEY ([id],[locale]) + PRIMARY KEY ([id],[locale]), + FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id]) + ON DELETE CASCADE ); EOF; $this->assertContains($expected, $builder->getSQL()); @@ -395,7 +407,9 @@ public function testModifyTableUseCustomPkName() ( [custom_id] INTEGER NOT NULL, [locale] VARCHAR(5) DEFAULT 'fr_FR' NOT NULL, - PRIMARY KEY ([custom_id],[locale]) + PRIMARY KEY ([custom_id],[locale]), + FOREIGN KEY ([custom_id]) REFERENCES i18n_behavior_test_0 ([id]) + ON DELETE CASCADE ); EOF; $this->assertContains($expected, $builder->getSQL()); diff --git a/test/testsuite/generator/behavior/nestedset/NestedSetBehaviorObjectBuilderModifierTest.php b/test/testsuite/generator/behavior/nestedset/NestedSetBehaviorObjectBuilderModifierTest.php index 38431453a..c98a7a57b 100644 --- a/test/testsuite/generator/behavior/nestedset/NestedSetBehaviorObjectBuilderModifierTest.php +++ b/test/testsuite/generator/behavior/nestedset/NestedSetBehaviorObjectBuilderModifierTest.php @@ -290,10 +290,10 @@ public function testGetParent() $t3->setTitle('t3')->setLeftValue(3)->setRightValue(4)->setLevel(2)->save(); $t4 = new Table9(); $t4->setTitle('t4')->setLeftValue(5)->setRightValue(6)->setLevel(2)->save(); - $this->assertNull($t1->getParent($this->con), 'getParent() return null for root nodes'); - $this->assertEquals($t2->getParent($this->con), $t1, 'getParent() correctly retrieves parent for nodes'); - $this->assertEquals($t3->getParent($this->con), $t2, 'getParent() correctly retrieves parent for leafs'); - $this->assertEquals($t4->getParent($this->con), $t2, 'getParent() retrieves the same parent for two siblings'); + $this->assertNull($t1->getParent(), 'getParent() return null for root nodes'); + $this->assertEquals($t2->getParent(), $t1, 'getParent() correctly retrieves parent for nodes'); + $this->assertEquals($t3->getParent(), $t2, 'getParent() correctly retrieves parent for leafs'); + $this->assertEquals($t4->getParent(), $t2, 'getParent() retrieves the same parent for two siblings'); } public function testGetParentCache() @@ -308,7 +308,7 @@ public function testGetParentCache() | \ t6 t7 */ - $con = Propel::getConnection(); + $con = Propel::getConnection(Table1Peer::DATABASE_NAME); $count = $con->getQueryCount(); $parent = $t5->getParent($con); $parent = $t5->getParent($con); @@ -344,11 +344,11 @@ public function testGetPrevSibling() | \ t6 t7 */ - $this->assertNull($t1->getPrevSibling($this->con), 'getPrevSibling() returns null for root nodes'); - $this->assertNull($t2->getPrevSibling($this->con), 'getPrevSibling() returns null for first siblings'); - $this->assertEquals($t3->getPrevSibling($this->con), $t2, 'getPrevSibling() correctly retrieves prev sibling'); - $this->assertNull($t6->getPrevSibling($this->con), 'getPrevSibling() returns null for first siblings'); - $this->assertEquals($t7->getPrevSibling($this->con), $t6, 'getPrevSibling() correctly retrieves prev sibling'); + $this->assertNull($t1->getPrevSibling(), 'getPrevSibling() returns null for root nodes'); + $this->assertNull($t2->getPrevSibling(), 'getPrevSibling() returns null for first siblings'); + $this->assertEquals($t3->getPrevSibling(), $t2, 'getPrevSibling() correctly retrieves prev sibling'); + $this->assertNull($t6->getPrevSibling(), 'getPrevSibling() returns null for first siblings'); + $this->assertEquals($t7->getPrevSibling(), $t6, 'getPrevSibling() correctly retrieves prev sibling'); } public function testHasNextSibling() @@ -379,11 +379,11 @@ public function testGetNextSibling() | \ t6 t7 */ - $this->assertNull($t1->getNextSibling($this->con), 'getNextSibling() returns null for root nodes'); - $this->assertEquals($t2->getNextSibling($this->con), $t3, 'getNextSibling() correctly retrieves next sibling'); - $this->assertNull($t3->getNextSibling($this->con), 'getNextSibling() returns null for last siblings'); - $this->assertEquals($t6->getNextSibling($this->con), $t7, 'getNextSibling() correctly retrieves next sibling'); - $this->assertNull($t7->getNextSibling($this->con), 'getNextSibling() returns null for last siblings'); + $this->assertNull($t1->getNextSibling(), 'getNextSibling() returns null for root nodes'); + $this->assertEquals($t2->getNextSibling(), $t3, 'getNextSibling() correctly retrieves next sibling'); + $this->assertNull($t3->getNextSibling(), 'getNextSibling() returns null for last siblings'); + $this->assertEquals($t6->getNextSibling(), $t7, 'getNextSibling() correctly retrieves next sibling'); + $this->assertNull($t7->getNextSibling(), 'getNextSibling() returns null for last siblings'); } public function testAddNestedSetChildren() @@ -447,7 +447,7 @@ public function testGetChildren() public function testGetChildrenCache() { list($t1, $t2, $t3, $t4, $t5, $t6, $t7) = $this->initTree(); - $con = Propel::getConnection(); + $con = Propel::getConnection(Table1Peer::DATABASE_NAME); $count = $con->getQueryCount(); $children = $t3->getChildren(null, $con); $children = $t3->getChildren(null, $con); @@ -507,7 +507,7 @@ public function testCountChildrenCache() | \ t6 t7 */ - $con = Propel::getConnection(); + $con = Propel::getConnection(Table1Peer::DATABASE_NAME); $count = $con->getQueryCount(); $children = $t3->getChildren(null, $con); $nbChildren = $t3->countChildren(null, $con); diff --git a/test/testsuite/generator/behavior/nestedset/NestedSetBehaviorObjectBuilderModifierWithScopeTest.php b/test/testsuite/generator/behavior/nestedset/NestedSetBehaviorObjectBuilderModifierWithScopeTest.php index a2fc46e41..4f799308b 100644 --- a/test/testsuite/generator/behavior/nestedset/NestedSetBehaviorObjectBuilderModifierWithScopeTest.php +++ b/test/testsuite/generator/behavior/nestedset/NestedSetBehaviorObjectBuilderModifierWithScopeTest.php @@ -117,13 +117,13 @@ public function testGetParent() { $this->initTreeWithScope(); $t1 = $this->getByTitle('t1'); - $this->assertNull($t1->getParent($this->con), 'getParent() return null for root nodes'); + $this->assertNull($t1->getParent(), 'getParent() return null for root nodes'); $t2 = $this->getByTitle('t2'); - $this->assertEquals($t2->getParent($this->con), $t1, 'getParent() correctly retrieves parent for leafs'); + $this->assertEquals($t2->getParent(), $t1, 'getParent() correctly retrieves parent for leafs'); $t3 = $this->getByTitle('t3'); - $this->assertEquals($t3->getParent($this->con), $t1, 'getParent() correctly retrieves parent for nodes'); + $this->assertEquals($t3->getParent(), $t1, 'getParent() correctly retrieves parent for nodes'); $t4 = $this->getByTitle('t4'); - $this->assertEquals($t4->getParent($this->con), $t3, 'getParent() retrieves the same parent for nodes'); + $this->assertEquals($t4->getParent(), $t3, 'getParent() retrieves the same parent for nodes'); } public function testGetPrevSibling() @@ -143,11 +143,11 @@ public function testGetPrevSibling() | \ t9 t10 */ - $this->assertNull($t1->getPrevSibling($this->con), 'getPrevSibling() returns null for root nodes'); - $this->assertNull($t2->getPrevSibling($this->con), 'getPrevSibling() returns null for first siblings'); - $this->assertEquals($t3->getPrevSibling($this->con), $t2, 'getPrevSibling() correctly retrieves prev sibling'); - $this->assertNull($t6->getPrevSibling($this->con), 'getPrevSibling() returns null for first siblings'); - $this->assertEquals($t7->getPrevSibling($this->con), $t6, 'getPrevSibling() correctly retrieves prev sibling'); + $this->assertNull($t1->getPrevSibling(), 'getPrevSibling() returns null for root nodes'); + $this->assertNull($t2->getPrevSibling(), 'getPrevSibling() returns null for first siblings'); + $this->assertEquals($t3->getPrevSibling(), $t2, 'getPrevSibling() correctly retrieves prev sibling'); + $this->assertNull($t6->getPrevSibling(), 'getPrevSibling() returns null for first siblings'); + $this->assertEquals($t7->getPrevSibling(), $t6, 'getPrevSibling() correctly retrieves prev sibling'); } public function testGetNextSibling() @@ -167,11 +167,11 @@ public function testGetNextSibling() | \ t9 t10 */ - $this->assertNull($t1->getNextSibling($this->con), 'getNextSibling() returns null for root nodes'); - $this->assertEquals($t2->getNextSibling($this->con), $t3, 'getNextSibling() correctly retrieves next sibling'); - $this->assertNull($t3->getNextSibling($this->con), 'getNextSibling() returns null for last siblings'); - $this->assertEquals($t6->getNextSibling($this->con), $t7, 'getNextSibling() correctly retrieves next sibling'); - $this->assertNull($t7->getNextSibling($this->con), 'getNextSibling() returns null for last siblings'); + $this->assertNull($t1->getNextSibling(), 'getNextSibling() returns null for root nodes'); + $this->assertEquals($t2->getNextSibling(), $t3, 'getNextSibling() correctly retrieves next sibling'); + $this->assertNull($t3->getNextSibling(), 'getNextSibling() returns null for last siblings'); + $this->assertEquals($t6->getNextSibling(), $t7, 'getNextSibling() correctly retrieves next sibling'); + $this->assertNull($t7->getNextSibling(), 'getNextSibling() returns null for last siblings'); } public function testGetDescendants() diff --git a/test/testsuite/generator/behavior/versionable/VersionableBehaviorTest.php b/test/testsuite/generator/behavior/versionable/VersionableBehaviorTest.php index b47d20242..4999a8b68 100644 --- a/test/testsuite/generator/behavior/versionable/VersionableBehaviorTest.php +++ b/test/testsuite/generator/behavior/versionable/VersionableBehaviorTest.php @@ -53,7 +53,7 @@ public function testModifyTableAddsVersionColumn($schema) CREATE TABLE [versionable_behavior_test_0] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [bar] INTEGER, [version] INTEGER DEFAULT 0 ); @@ -85,7 +85,7 @@ public function testModifyTableAddsVersionColumnCustomName() CREATE TABLE [versionable_behavior_test_0] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [bar] INTEGER, [foo_ver] INTEGER DEFAULT 0 ); @@ -116,7 +116,7 @@ public function testModifyTableDoesNotAddVersionColumnIfExists() CREATE TABLE [versionable_behavior_test_0] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [bar] INTEGER, [version] BIGINT ); @@ -164,10 +164,11 @@ public function testModifyTableAddsVersionColumnForForeignKeysIfForeignTableIsVe CREATE TABLE [versionable_behavior_test_0] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [bar] INTEGER, [foreign_id] INTEGER, - [version] INTEGER DEFAULT 0 + [version] INTEGER DEFAULT 0, + FOREIGN KEY ([foreign_id]) REFERENCES versionable_behavior_test_1 ([id]) ); EOF; $this->assertContains($expected, $builder->getSQL()); @@ -186,11 +187,11 @@ public function testModifyTableAddsVersionColumnForForeignKeysIfForeignTableIsVe [foreign_id] INTEGER, [version] INTEGER DEFAULT 0 NOT NULL, [foreign_id_version] INTEGER DEFAULT 0, - PRIMARY KEY ([id],[version]) + PRIMARY KEY ([id],[version]), + FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id]) + ON DELETE CASCADE ); --- SQLite does not support foreign keys; this is just for reference --- FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id]) EOF; $this->assertContains($expected, $builder->getSQL()); } @@ -211,7 +212,7 @@ public function testModifyTableAddsVersionColumnForReferrersIfForeignTableIsVers CREATE TABLE [versionable_behavior_test_1] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [bar] INTEGER, [version] INTEGER DEFAULT 0 ); @@ -232,11 +233,11 @@ public function testModifyTableAddsVersionColumnForReferrersIfForeignTableIsVers [version] INTEGER DEFAULT 0 NOT NULL, [versionable_behavior_test_0_ids] MEDIUMTEXT, [versionable_behavior_test_0_versions] MEDIUMTEXT, - PRIMARY KEY ([id],[version]) + PRIMARY KEY ([id],[version]), + FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_1 ([id]) + ON DELETE CASCADE ); --- SQLite does not support foreign keys; this is just for reference --- FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_1 ([id]) EOF; $this->assertContains($expected, $builder->getSQL()); } @@ -260,11 +261,11 @@ public function testModifyTableAddsVersionTable($schema) [id] INTEGER NOT NULL, [bar] INTEGER, [version] INTEGER DEFAULT 0 NOT NULL, - PRIMARY KEY ([id],[version]) + PRIMARY KEY ([id],[version]), + FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id]) + ON DELETE CASCADE ); --- SQLite does not support foreign keys; this is just for reference --- FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id]) EOF; $this->assertContains($expected, $builder->getSQL()); } @@ -296,11 +297,11 @@ public function testModifyTableAddsVersionTableCustomName() [id] INTEGER NOT NULL, [bar] INTEGER, [version] INTEGER DEFAULT 0 NOT NULL, - PRIMARY KEY ([id],[version]) + PRIMARY KEY ([id],[version]), + FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id]) + ON DELETE CASCADE ); --- SQLite does not support foreign keys; this is just for reference --- FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id]) EOF; $this->assertContains($expected, $builder->getSQL()); } @@ -332,7 +333,7 @@ public function testModifyTableDoesNotAddVersionTableIfExists() CREATE TABLE [versionable_behavior_test_0] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [bar] INTEGER, [version] INTEGER DEFAULT 0 ); @@ -345,7 +346,7 @@ public function testModifyTableDoesNotAddVersionTableIfExists() CREATE TABLE [versionable_behavior_test_0_version] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [baz] INTEGER ); @@ -388,7 +389,7 @@ public function testModifyTableAddsLogColumns($schema) CREATE TABLE [versionable_behavior_test_0] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [bar] INTEGER, [version] INTEGER DEFAULT 0, [version_created_at] TIMESTAMP, @@ -421,11 +422,11 @@ public function testModifyTableAddsVersionTableLogColumns($schema) [version_created_at] TIMESTAMP, [version_created_by] VARCHAR(100), [version_comment] VARCHAR(255), - PRIMARY KEY ([id],[version]) + PRIMARY KEY ([id],[version]), + FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id]) + ON DELETE CASCADE ); --- SQLite does not support foreign keys; this is just for reference --- FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id]) EOF; $this->assertContains($expected, $builder->getSQL()); } @@ -455,11 +456,11 @@ public function testDatabaseLevelBehavior() [id] INTEGER NOT NULL, [bar] INTEGER, [version] INTEGER DEFAULT 0 NOT NULL, - PRIMARY KEY ([id],[version]) + PRIMARY KEY ([id],[version]), + FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id]) + ON DELETE CASCADE ); --- SQLite does not support foreign keys; this is just for reference --- FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id]) EOF; $this->assertContains($expected, $builder->getSQL()); } diff --git a/test/testsuite/generator/builder/om/GeneratedPeerDoSelectTest.php b/test/testsuite/generator/builder/om/GeneratedPeerDoSelectTest.php index e0c8b379a..f79ec10ac 100644 --- a/test/testsuite/generator/builder/om/GeneratedPeerDoSelectTest.php +++ b/test/testsuite/generator/builder/om/GeneratedPeerDoSelectTest.php @@ -145,11 +145,11 @@ public function testDoSelectJoin_NullFk() public function testDoSelectJoinOneToOne() { - $con = Propel::getConnection(); + $con = Propel::getConnection(BookPeer::DATABASE_NAME); $count = $con->getQueryCount(); Propel::disableInstancePooling(); $c = new Criteria(); - $accs = BookstoreEmployeeAccountPeer::doSelectJoinBookstoreEmployee($c); + $accs = BookstoreEmployeeAccountPeer::doSelectJoinBookstoreEmployee($c, $con); Propel::enableInstancePooling(); $this->assertEquals(1, $con->getQueryCount() - $count, 'doSelectJoin() makes only one query in a one-to-one relationship'); } diff --git a/test/testsuite/generator/builder/om/QueryBuilderTest.php b/test/testsuite/generator/builder/om/QueryBuilderTest.php index f40faadc1..ebe2f4316 100644 --- a/test/testsuite/generator/builder/om/QueryBuilderTest.php +++ b/test/testsuite/generator/builder/om/QueryBuilderTest.php @@ -139,7 +139,7 @@ public function testFindPkReturnsCorrectObjectForSimplePrimaryKey() $b = new Book(); $b->setTitle('bar'); $b->setIsbn('2342'); - $b->save($this->con); + $b->save(); $count = $this->con->getQueryCount(); BookPeer::clearInstancePool(); @@ -154,7 +154,7 @@ public function testFindPkUsesInstancePoolingForSimplePrimaryKey() $b = new Book(); $b->setTitle('foo'); $b->setIsbn('2342'); - $b->save($this->con); + $b->save(); $count = $this->con->getQueryCount(); $book = BookQuery::create()->findPk($b->getId(), $this->con); @@ -198,7 +198,7 @@ public function testFindPkSimpleAddsObjectToInstancePool() $b = new Book(); $b->setTitle('foo'); $b->setIsbn('2342'); - $b->save($this->con); + $b->save(); BookPeer::clearInstancePool(); BookQuery::create()->findPk($b->getId(), $this->con); @@ -214,7 +214,7 @@ public function testFindOneByIdAddsObjectToInstancePool() $b = new Book(); $b->setTitle('foo'); $b->setIsbn('2342'); - $b->save($this->con); + $b->save(); BookPeer::clearInstancePool(); BookQuery::create()->findOneById($b->getId(), $this->con); @@ -227,8 +227,10 @@ public function testFindOneByIdAddsObjectToInstancePool() public function testFindPkUsesFindPkComplexOnNonEmptyQueries() { - BookQuery::create('b')->findPk(123, $this->con); - $expected = 'SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM `book` WHERE book.id=123'; + BookQuery::create('b')->findPk(123); + $con = Propel::getConnection(BookPeer::DATABASE_NAME); + $q = $con instanceof DBMySQL ? '`' : ''; + $expected = "SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM {$q}book{$q} WHERE book.id=123"; $this->assertEquals($expected, $this->con->getLastExecutedQuery()); } @@ -237,7 +239,7 @@ public function testFindPkComplexAddsObjectToInstancePool() $b = new Book(); $b->setTitle('foo'); $b->setIsbn('2345'); - $b->save($this->con); + $b->save(); BookPeer::clearInstancePool(); BookQuery::create('b')->findPk($b->getId(), $this->con); @@ -658,22 +660,22 @@ public function testFilterByFkCompositeKey() public function testFilterByFkObjectCollection() { - BookstoreDataPopulator::depopulate($this->con); - BookstoreDataPopulator::populate($this->con); + BookstoreDataPopulator::depopulate(); + BookstoreDataPopulator::populate(); $authors = AuthorQuery::create() ->orderByFirstName() ->limit(2) - ->find($this->con); + ->find(); $books = BookQuery::create() ->filterByAuthor($authors) - ->find($this->con); + ->find(); $q1 = $this->con->getLastExecutedQuery(); $books = BookQuery::create() ->add(BookPeer::AUTHOR_ID, $authors->getPrimaryKeys(), Criteria::IN) - ->find($this->con); + ->find(); $q2 = $this->con->getLastExecutedQuery(); $this->assertEquals($q2, $q1, 'filterByFk() accepts a collection and results to an IN query'); @@ -720,18 +722,18 @@ public function testFilterByRelationNameCompositePk() $testLabel = RecordLabelQuery::create() ->limit(2) - ->find($this->con); + ->find(); $testRelease = ReleasePoolQuery::create() ->addJoin(ReleasePoolPeer::RECORD_LABEL_ID, RecordLabelPeer::ID) ->filterByRecordLabel($testLabel) - ->find($this->con); + ->find(); $q1 = $this->con->getLastExecutedQuery(); $releasePool = ReleasePoolQuery::create() ->addJoin(ReleasePoolPeer::RECORD_LABEL_ID, RecordLabelPeer::ID) ->add(ReleasePoolPeer::RECORD_LABEL_ID, $testLabel->toKeyValue('Id', 'Id'), Criteria::IN) - ->find($this->con); + ->find(); $q2 = $this->con->getLastExecutedQuery(); $this->assertEquals($q2, $q1, 'filterBy{RelationName}() only accepts arguments of type {RelationName} or PropelCollection'); @@ -758,23 +760,23 @@ public function testFilterByRefFkCompositeKey() public function testFilterByRefFkObjectCollection() { - BookstoreDataPopulator::depopulate($this->con); - BookstoreDataPopulator::populate($this->con); + BookstoreDataPopulator::depopulate(); + BookstoreDataPopulator::populate(); $books = BookQuery::create() ->orderByTitle() ->limit(2) - ->find($this->con); + ->find(); $authors = AuthorQuery::create() ->filterByBook($books) - ->find($this->con); + ->find(); $q1 = $this->con->getLastExecutedQuery(); $authors = AuthorQuery::create() ->addJoin(AuthorPeer::ID, BookPeer::AUTHOR_ID, Criteria::LEFT_JOIN) ->add(BookPeer::ID, $books->getPrimaryKeys(), Criteria::IN) - ->find($this->con); + ->find(); $q2 = $this->con->getLastExecutedQuery(); $this->assertEquals($q2, $q1, 'filterByRefFk() accepts a collection and results to an IN query in the joined table'); diff --git a/test/testsuite/generator/platform/PlatformTestProvider.php b/test/testsuite/generator/platform/PlatformTestProvider.php index f6485956c..b0b381b1e 100644 --- a/test/testsuite/generator/platform/PlatformTestProvider.php +++ b/test/testsuite/generator/platform/PlatformTestProvider.php @@ -181,10 +181,10 @@ public function providerForTestGetUniqueDDL() { $table = new Table('foo'); $column1 = new Column('bar1'); - $column1->getDomain()->copy(new Domain('FOOTYPE')); + $column1->getDomain()->copy(new Domain('INTEGER')); $table->addColumn($column1); $column2 = new Column('bar2'); - $column2->getDomain()->copy(new Domain('BARTYPE')); + $column2->getDomain()->copy(new Domain('INTEGER')); $table->addColumn($column2); $index = new Unique('babar'); $index->addColumn($column1); @@ -200,10 +200,10 @@ public function providerForTestGetIndicesDDL() { $table = new Table('foo'); $column1 = new Column('bar1'); - $column1->getDomain()->copy(new Domain('FOOTYPE')); + $column1->getDomain()->copy(new Domain('INTEGER')); $table->addColumn($column1); $column2 = new Column('bar2'); - $column2->getDomain()->copy(new Domain('BARTYPE')); + $column2->getDomain()->copy(new Domain('INTEGER')); $table->addColumn($column2); $index1 = new Index('babar'); $index1->addColumn($column1); @@ -222,10 +222,10 @@ public function providerForTestGetIndexDDL() { $table = new Table('foo'); $column1 = new Column('bar1'); - $column1->getDomain()->copy(new Domain('FOOTYPE')); + $column1->getDomain()->copy(new Domain('INTEGER')); $table->addColumn($column1); $column2 = new Column('bar2'); - $column2->getDomain()->copy(new Domain('BARTYPE')); + $column2->getDomain()->copy(new Domain('INTEGER')); $table->addColumn($column2); $index = new Index('babar'); $index->addColumn($column1); @@ -253,11 +253,11 @@ public function providerForTestGetForeignKeyDDL() { $table1 = new Table('foo'); $column1 = new Column('bar_id'); - $column1->getDomain()->copy(new Domain('FOOTYPE')); + $column1->getDomain()->copy(new Domain('INTEGER')); $table1->addColumn($column1); $table2 = new Table('bar'); $column2 = new Column('id'); - $column2->getDomain()->copy(new Domain('BARTYPE')); + $column2->getDomain()->copy(new Domain('INTEGER')); $table2->addColumn($column2); $fk = new ForeignKey('foo_bar_FK'); $fk->setForeignTableCommonName('bar'); @@ -286,11 +286,11 @@ public function providerForTestGetForeignKeysDDL() $table1 = new Table('foo'); $column1 = new Column('bar_id'); - $column1->getDomain()->copy(new Domain('FOOTYPE')); + $column1->getDomain()->copy(new Domain('INTEGER')); $table1->addColumn($column1); $table2 = new Table('bar'); $column2 = new Column('id'); - $column2->getDomain()->copy(new Domain('BARTYPE')); + $column2->getDomain()->copy(new Domain('INTEGER')); $table2->addColumn($column2); $fk = new ForeignKey('foo_bar_FK'); @@ -300,11 +300,11 @@ public function providerForTestGetForeignKeysDDL() $table1->addForeignKey($fk); $column3 = new Column('baz_id'); - $column3->getDomain()->copy(new Domain('BAZTYPE')); + $column3->getDomain()->copy(new Domain('INTEGER')); $table1->addColumn($column3); $table3 = new Table('baz'); $column4 = new Column('id'); - $column4->getDomain()->copy(new Domain('BAZTYPE')); + $column4->getDomain()->copy(new Domain('INTEGER')); $table3->addColumn($column4); $fk = new ForeignKey('foo_baz_FK'); diff --git a/test/testsuite/generator/platform/SqlitePlatformTest.php b/test/testsuite/generator/platform/SqlitePlatformTest.php index 3c59cb974..3bb802734 100644 --- a/test/testsuite/generator/platform/SqlitePlatformTest.php +++ b/test/testsuite/generator/platform/SqlitePlatformTest.php @@ -20,7 +20,7 @@ class SqlitePlatformTest extends PlatformTestProvider /** * Get the Platform object for this class * - * @return Platform + * @return DefaultPlatform */ protected function getPlatform() { @@ -75,16 +75,14 @@ public function testGetAddTablesDDL($schema) CREATE TABLE [book] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [title] VARCHAR(255) NOT NULL, - [author_id] INTEGER + [author_id] INTEGER, + FOREIGN KEY ([author_id]) REFERENCES author ([id]) ); CREATE INDEX [book_I_1] ON [book] ([title]); --- SQLite does not support foreign keys; this is just for reference --- FOREIGN KEY ([author_id]) REFERENCES author ([id]) - ----------------------------------------------------------------------- -- author ----------------------------------------------------------------------- @@ -93,7 +91,7 @@ public function testGetAddTablesDDL($schema) CREATE TABLE [author] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [first_name] VARCHAR(100), [last_name] VARCHAR(100) ); @@ -122,7 +120,7 @@ public function testGetAddTableDDLSimplePK($schema) -- This is foo table CREATE TABLE [foo] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [bar] VARCHAR(255) NOT NULL ); "; @@ -174,7 +172,7 @@ public function testGetAddTableDDLUniqueIndex($schema) $expected = " CREATE TABLE [foo] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [bar] INTEGER, UNIQUE ([bar]) ); @@ -273,7 +271,7 @@ public function testAddIndicesDDL($table) CREATE INDEX [foo_index] ON [foo] ([bar1]); "; - $this->assertEquals($expected, $this->getPLatform()->getAddIndicesDDL($table)); + $this->assertEquals($expected, $this->getPlatform()->getAddIndicesDDL($table)); } /** @@ -284,7 +282,7 @@ public function testAddIndexDDL($index) $expected = " CREATE INDEX [babar] ON [foo] ([bar1],[bar2]); "; - $this->assertEquals($expected, $this->getPLatform()->getAddIndexDDL($index)); + $this->assertEquals($expected, $this->getPlatform()->getAddIndexDDL($index)); } /** @@ -295,7 +293,7 @@ public function testDropIndexDDL($index) $expected = " DROP INDEX [babar]; "; - $this->assertEquals($expected, $this->getPLatform()->getDropIndexDDL($index)); + $this->assertEquals($expected, $this->getPlatform()->getDropIndexDDL($index)); } /** @@ -304,7 +302,7 @@ public function testDropIndexDDL($index) public function testGetIndexDDL($index) { $expected = 'INDEX [babar] ([bar1],[bar2])'; - $this->assertEquals($expected, $this->getPLatform()->getIndexDDL($index)); + $this->assertEquals($expected, $this->getPlatform()->getIndexDDL($index)); } /** @@ -322,13 +320,11 @@ public function testGetUniqueDDL($index) public function testGetAddForeignKeysDDL($table) { $expected = " --- SQLite does not support foreign keys; this is just for reference --- FOREIGN KEY ([bar_id]) REFERENCES bar ([id]) +--- SQLite does not support altering foreign keys directly; this is just for reference --- SQLite does not support foreign keys; this is just for reference --- FOREIGN KEY ([baz_id]) REFERENCES baz ([id]) +--- SQLite does not support altering foreign keys directly; this is just for reference "; - $this->assertEquals($expected, $this->getPLatform()->getAddForeignKeysDDL($table)); + $this->assertEquals($expected, $this->getPlatform()->getAddForeignKeysDDL($table)); } /** @@ -337,10 +333,9 @@ public function testGetAddForeignKeysDDL($table) public function testGetAddForeignKeyDDL($fk) { $expected = " --- SQLite does not support foreign keys; this is just for reference --- FOREIGN KEY ([bar_id]) REFERENCES bar ([id]) +--- SQLite does not support altering foreign keys directly; this is just for reference "; - $this->assertEquals($expected, $this->getPLatform()->getAddForeignKeyDDL($fk)); + $this->assertEquals($expected, $this->getPlatform()->getAddForeignKeyDDL($fk)); } /** @@ -349,7 +344,7 @@ public function testGetAddForeignKeyDDL($fk) public function testGetDropForeignKeyDDL($fk) { $expected = ''; - $this->assertEquals($expected, $this->getPLatform()->getDropForeignKeyDDL($fk)); + $this->assertEquals($expected, $this->getPlatform()->getDropForeignKeyDDL($fk)); } /** @@ -357,11 +352,9 @@ public function testGetDropForeignKeyDDL($fk) */ public function testGetForeignKeyDDL($fk) { - $expected = " --- SQLite does not support foreign keys; this is just for reference --- FOREIGN KEY ([bar_id]) REFERENCES bar ([id]) -"; - $this->assertEquals($expected, $this->getPLatform()->getForeignKeyDDL($fk)); + $expected = "FOREIGN KEY ([bar_id]) REFERENCES bar ([id]) + ON DELETE CASCADE"; + $this->assertEquals($expected, $this->getPlatform()->getForeignKeyDDL($fk)); } public function testGetCommentBlockDDL() @@ -371,7 +364,7 @@ public function testGetCommentBlockDDL() -- foo bar ----------------------------------------------------------------------- "; - $this->assertEquals($expected, $this->getPLatform()->getCommentBlockDDL('foo bar')); + $this->assertEquals($expected, $this->getPlatform()->getCommentBlockDDL('foo bar')); } } diff --git a/test/testsuite/generator/util/PropelQuickBuilderTest.php b/test/testsuite/generator/util/PropelQuickBuilderTest.php index f31f8e5a4..e2c514c01 100644 --- a/test/testsuite/generator/util/PropelQuickBuilderTest.php +++ b/test/testsuite/generator/util/PropelQuickBuilderTest.php @@ -69,7 +69,7 @@ public function testGetSQL($builder) CREATE TABLE [quick_build_foo_1] ( - [id] INTEGER NOT NULL PRIMARY KEY, + [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [bar] INTEGER ); diff --git a/test/testsuite/runtime/collection/PropelOnDemandCollectionTest.php b/test/testsuite/runtime/collection/PropelOnDemandCollectionTest.php index 3ffbf8e25..0a3842329 100644 --- a/test/testsuite/runtime/collection/PropelOnDemandCollectionTest.php +++ b/test/testsuite/runtime/collection/PropelOnDemandCollectionTest.php @@ -22,7 +22,7 @@ class PropelOnDemandCollectionTest extends BookstoreEmptyTestBase protected function setUp() { parent::setUp(); - BookstoreDataPopulator::populate($this->con); + BookstoreDataPopulator::populate(); Propel::disableInstancePooling(); $this->books = PropelQuery::from('Book')->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find(); }