From 5bb404fb0128d3c18ca8329fa35a54e27657b54f Mon Sep 17 00:00:00 2001 From: Dmytro Dymarchuk Date: Thu, 31 Mar 2022 00:30:52 +0300 Subject: [PATCH] Finish strict param refactoring (#1849) * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues * TE-10483: Fixed remaining issues --- .../Builder/Om/AbstractOMBuilder.php | 11 ++ .../Generator/Builder/Om/ObjectBuilder.php | 6 +- .../Generator/Builder/Om/TableMapBuilder.php | 8 +- .../Generator/Manager/MigrationManager.php | 4 +- src/Propel/Generator/Model/Behavior.php | 18 +++ src/Propel/Generator/Model/Column.php | 14 +- src/Propel/Generator/Model/Database.php | 2 +- .../Generator/Model/ScopedMappingModel.php | 22 +++ src/Propel/Generator/Model/Table.php | 55 +++++-- .../Runtime/ActiveQuery/BaseModelCriteria.php | 36 +++++ src/Propel/Runtime/ActiveQuery/Join.php | 18 +++ .../ActiveRecord/ActiveRecordInterface.php | 8 + .../AbstractFormatterWithHydration.php | 143 ++++++++++++++++++ .../Runtime/Formatter/ArrayFormatter.php | 99 +----------- src/Propel/Runtime/Map/ColumnMap.php | 14 +- src/Propel/Runtime/Map/RelationMap.php | 22 +-- src/Propel/Runtime/Map/TableMap.php | 82 ++++++++-- src/Propel/Runtime/Util/PropelModelPager.php | 6 +- tests/Propel/Tests/FieldnameRelatedTest.php | 10 +- ...nableBehaviorObjectBuilderModifierTest.php | 2 + .../Om/GeneratedObjectWithFixturesTest.php | 2 +- .../Generator/Config/GeneratorConfigTest.php | 8 +- .../Config/QuickGeneratorConfigTest.php | 8 +- .../Tests/Generator/Model/BehaviorTest.php | 2 +- .../Tests/Generator/Model/ColumnTest.php | 88 +++++------ .../Tests/Generator/Model/DatabaseTest.php | 2 +- .../Model/Diff/ColumnComparatorTest.php | 52 +++---- .../Diff/PropelTableColumnComparatorTest.php | 36 ++--- .../Diff/PropelTableIndexComparatorTest.php | 24 +-- .../PropelTablePkColumnComparatorTest.php | 28 ++-- .../Generator/Model/Diff/TableDiffTest.php | 10 +- .../Tests/Generator/Model/TableTest.php | 68 ++++----- .../Platform/DefaultPlatformTest.php | 6 +- .../PlatformMigrationTestProvider.php | 4 +- .../Tests/Runtime/ActiveRecordConvertTest.php | 22 +-- .../Collection/ArrayCollectionTest.php | 2 +- .../Collection/ObjectCollectionTest.php | 2 +- .../Tests/Runtime/Map/ColumnMapTest.php | 25 ++- .../Tests/Runtime/Map/RelationMapTest.php | 18 ++- .../Propel/Tests/Runtime/Map/TableMapTest.php | 4 +- 40 files changed, 646 insertions(+), 345 deletions(-) create mode 100644 src/Propel/Runtime/Formatter/AbstractFormatterWithHydration.php diff --git a/src/Propel/Generator/Builder/Om/AbstractOMBuilder.php b/src/Propel/Generator/Builder/Om/AbstractOMBuilder.php index 95ae46568c..c926dd1fb6 100644 --- a/src/Propel/Generator/Builder/Om/AbstractOMBuilder.php +++ b/src/Propel/Generator/Builder/Om/AbstractOMBuilder.php @@ -248,6 +248,17 @@ public function getNamespace(): ?string return $this->getTable()->getNamespace(); } + /** + * Returns the user-defined namespace for this table, + * or the database namespace otherwise. + * + * @return string + */ + public function getNamespaceOrFail(): string + { + return $this->getTable()->getNamespaceOrFail(); + } + /** * This declares the class use and returns the correct name to use (short classname, Alias, or FQCN) * diff --git a/src/Propel/Generator/Builder/Om/ObjectBuilder.php b/src/Propel/Generator/Builder/Om/ObjectBuilder.php index adf6a7f188..5ad48165da 100644 --- a/src/Propel/Generator/Builder/Om/ObjectBuilder.php +++ b/src/Propel/Generator/Builder/Om/ObjectBuilder.php @@ -3000,12 +3000,12 @@ protected function addToArray(string &$script): void } $script .= " * - * @return array|string An associative array containing the field names (as keys) and field values + * @return array An associative array containing the field names (as keys) and field values */ - public function toArray(string \$keyType = TableMap::$defaultKeyType, bool \$includeLazyLoadColumns = true, array \$alreadyDumpedObjects = []" . ($hasFks ? ', bool $includeForeignObjects = false' : '') . ") + public function toArray(string \$keyType = TableMap::$defaultKeyType, bool \$includeLazyLoadColumns = true, array \$alreadyDumpedObjects = []" . ($hasFks ? ', bool $includeForeignObjects = false' : '') . "): array { if (isset(\$alreadyDumpedObjects['$objectClassName'][\$this->hashCode()])) { - return '*RECURSION*'; + return ['*RECURSION*']; } \$alreadyDumpedObjects['$objectClassName'][\$this->hashCode()] = true; \$keys = " . $this->getTableMapClassName() . "::getFieldNames(\$keyType); diff --git a/src/Propel/Generator/Builder/Om/TableMapBuilder.php b/src/Propel/Generator/Builder/Om/TableMapBuilder.php index 438f3be386..9eacda7ded 100644 --- a/src/Propel/Generator/Builder/Om/TableMapBuilder.php +++ b/src/Propel/Generator/Builder/Om/TableMapBuilder.php @@ -1025,21 +1025,21 @@ protected function addGetOMClassInheritance(string &$script): void * objects that inherit from the default. * * @param array \$row ConnectionInterface result row. - * @param int \$colnum Column to examine for OM class information (first is 0). + * @param int \$colNum Column to examine for OM class information (first is 0). * @param bool \$withPrefix Whether to return the path with the class name * @throws \Propel\Runtime\Exception\PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. * * @return string The OM class */ - public static function getOMClass(array \$row, int \$colnum, bool \$withPrefix = true): string + public static function getOMClass(array \$row, int \$colNum, bool \$withPrefix = true): string { try { "; if ($col->isEnumeratedClasses()) { $script .= " \$omClass = null; - \$classKey = \$row[\$colnum + " . ($col->getPosition() - 1) . "]; + \$classKey = \$row[\$colNum + " . ($col->getPosition() - 1) . "]; switch (\$classKey) { "; @@ -1064,7 +1064,7 @@ public static function getOMClass(array \$row, int \$colnum, bool \$withPrefix = "; } else { /* if not enumerated */ $script .= " - \$omClass = \$row[\$colnum + " . ($col->getPosition() - 1) . "]; + \$omClass = \$row[\$colNum + " . ($col->getPosition() - 1) . "]; \$omClass = preg_replace('#\.#', '\\\\', '.'.\$omClass); "; } diff --git a/src/Propel/Generator/Manager/MigrationManager.php b/src/Propel/Generator/Manager/MigrationManager.php index eb3a2880d3..b9689cdeed 100644 --- a/src/Propel/Generator/Manager/MigrationManager.php +++ b/src/Propel/Generator/Manager/MigrationManager.php @@ -325,9 +325,9 @@ public function getAlreadyExecutedMigrationTimestamps(): array } /** - * @return int + * @return int|null */ - public function getFirstUpMigrationTimestamp(): int + public function getFirstUpMigrationTimestamp(): ?int { $validTimestamps = $this->getValidMigrationTimestamps(); diff --git a/src/Propel/Generator/Model/Behavior.php b/src/Propel/Generator/Model/Behavior.php index 12d4e0e646..62a43db6a8 100644 --- a/src/Propel/Generator/Model/Behavior.php +++ b/src/Propel/Generator/Model/Behavior.php @@ -172,6 +172,24 @@ public function getTable(): ?Table return $this->table; } + /** + * Returns the table this behavior is applied to + * + * @throws \Propel\Generator\Exception\LogicException + * + * @return \Propel\Generator\Model\Table + */ + public function getTableOrFail(): Table + { + $table = $this->getTable(); + + if ($table === null) { + throw new LogicException('Table is not defined.'); + } + + return $table; + } + /** * Sets the database this behavior is applied to * diff --git a/src/Propel/Generator/Model/Column.php b/src/Propel/Generator/Model/Column.php index fbdfe3dd77..bb2c6e5679 100644 --- a/src/Propel/Generator/Model/Column.php +++ b/src/Propel/Generator/Model/Column.php @@ -51,7 +51,7 @@ class Column extends MappingModel ]; /** - * @var string|null + * @var string */ private $name; @@ -225,15 +225,13 @@ class Column extends MappingModel /** * Creates a new column and set the name. * - * @param string|null $name The column's name + * @param string $name The column's name * @param string|null $type The column's type * @param string|int|null $size The column's size */ - public function __construct(?string $name = null, ?string $type = null, $size = null) + public function __construct(string $name, ?string $type = null, $size = null) { - if ($name !== null) { - $this->setName($name); - } + $this->setName($name); if ($type !== null) { $this->setType($type); @@ -469,9 +467,9 @@ public function getFullyQualifiedName(): string /** * Returns the column name. * - * @return string|null + * @return string */ - public function getName(): ?string + public function getName(): string { return $this->name; } diff --git a/src/Propel/Generator/Model/Database.php b/src/Propel/Generator/Model/Database.php index 040f079910..26fa2b52fb 100644 --- a/src/Propel/Generator/Model/Database.php +++ b/src/Propel/Generator/Model/Database.php @@ -573,7 +573,7 @@ public function removeTable(Table $table): void public function addTable($table): Table { if (!$table instanceof Table) { - $tbl = new Table(); + $tbl = new Table($table['name']); $tbl->setDatabase($this); $tbl->loadMapping($table); diff --git a/src/Propel/Generator/Model/ScopedMappingModel.php b/src/Propel/Generator/Model/ScopedMappingModel.php index d5ae005eec..10f5b2079f 100644 --- a/src/Propel/Generator/Model/ScopedMappingModel.php +++ b/src/Propel/Generator/Model/ScopedMappingModel.php @@ -8,6 +8,8 @@ namespace Propel\Generator\Model; +use Propel\Generator\Exception\LogicException; + /** * Data about an element with a name and optional namespace, schema and package * attributes. @@ -89,6 +91,26 @@ public function getNamespace(bool $getAbsoluteNamespace = false): ?string return $this->namespace; } + /** + * Returns the namespace. + * + * @param bool $getAbsoluteNamespace + * + * @throws \Propel\Generator\Exception\LogicException + * + * @return string + */ + public function getNamespaceOrFail(bool $getAbsoluteNamespace = false): string + { + $namespace = $this->getNamespace($getAbsoluteNamespace); + + if ($namespace === null) { + throw new LogicException('Namespace is not defined.'); + } + + return $namespace; + } + /** * Sets the namespace. * diff --git a/src/Propel/Generator/Model/Table.php b/src/Propel/Generator/Model/Table.php index 7ebdb9cab7..1f7da5e766 100644 --- a/src/Propel/Generator/Model/Table.php +++ b/src/Propel/Generator/Model/Table.php @@ -12,6 +12,7 @@ use Propel\Generator\Exception\BuildException; use Propel\Generator\Exception\EngineException; use Propel\Generator\Exception\InvalidArgumentException; +use Propel\Generator\Exception\LogicException; use Propel\Generator\Platform\MysqlPlatform; use Propel\Generator\Platform\PlatformInterface; use Propel\Runtime\Exception\RuntimeException; @@ -233,15 +234,13 @@ class Table extends ScopedMappingModel implements IdMethod /** * Constructs a table object with a name * - * @param string|null $name table name + * @param string $name table name */ - public function __construct(?string $name = null) + public function __construct(string $name) { parent::__construct(); - if ($name !== null) { - $this->setCommonName($name); - } + $this->setCommonName($name); $this->idMethod = IdMethod::NO_ID_METHOD; $this->defaultAccessorVisibility = static::VISIBILITY_PUBLIC; @@ -254,9 +253,9 @@ public function __construct(?string $name = null) * * If autoPrefix is set. Otherwise get the common name. * - * @return string|null + * @return string */ - private function getStdSeparatedName(): ?string + private function getStdSeparatedName(): string { if ($this->schema && $this->getBuildProperty('generator.schema.autoPrefix')) { return $this->schema . NameGeneratorInterface::STD_SEPARATOR_CHAR . $this->getCommonName(); @@ -661,7 +660,7 @@ public function addColumn($col): Column return $col; } - $column = new Column(); + $column = new Column($col['name']); $column->setTable($this); $column->loadMapping($col); @@ -1335,9 +1334,9 @@ public function getCamelCaseName(): string /** * Returns the common name (without schema name), but with table prefix if defined. * - * @return string|null + * @return string */ - public function getCommonName(): ?string + public function getCommonName(): string { return $this->commonName; } @@ -1931,6 +1930,24 @@ public function getDatabase(): ?Database return $this->database; } + /** + * Get the database that contains this table. + * + * @throws \Propel\Generator\Exception\LogicException + * + * @return \Propel\Generator\Model\Database + */ + public function getDatabaseOrFail(): Database + { + $database = $this->getDatabase(); + + if ($database === null) { + throw new LogicException('Database is not defined.'); + } + + return $database; + } + /** * Returns the Database platform. * @@ -2090,6 +2107,24 @@ public function getAutoIncrementPrimaryKey(): ?Column return null; } + /** + * Returns the auto incremented primary key. + * + * @throws \Propel\Generator\Exception\LogicException + * + * @return \Propel\Generator\Model\Column + */ + public function getAutoIncrementPrimaryKeyOrFail(): Column + { + $column = $this->getAutoIncrementPrimaryKey(); + + if ($column === null) { + throw new LogicException('Autoincrement primary key is not defined.'); + } + + return $column; + } + /** * Returns whether there is a cross reference status for this foreign * key. diff --git a/src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php b/src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php index 1a592ab9ec..829fb42fc7 100644 --- a/src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php +++ b/src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php @@ -160,6 +160,24 @@ public function getModelName(): ?string return $this->modelName; } + /** + * Returns the name of the class for this model criteria + * + * @throws \Propel\Runtime\Exception\LogicException + * + * @return string + */ + public function getModelNameOrFail(): string + { + $modelName = $this->getModelName(); + + if ($modelName === null) { + throw new LogicException('Model name is not defined.'); + } + + return $modelName; + } + /** * Sets the model name. * This also sets `this->modelTableMapName` and `this->tableMap`. @@ -272,6 +290,24 @@ public function getTableMap(): ?TableMap return $this->tableMap; } + /** + * Returns the TableMap object for this Criteria + * + * @throws \Propel\Runtime\Exception\LogicException + * + * @return \Propel\Runtime\Map\TableMap + */ + public function getTableMapOrFail(): TableMap + { + $tableMap = $this->getTableMap(); + + if ($tableMap === null) { + throw new LogicException('Table map is not defined.'); + } + + return $tableMap; + } + /** * Returns the name of the table as used in the query. * diff --git a/src/Propel/Runtime/ActiveQuery/Join.php b/src/Propel/Runtime/ActiveQuery/Join.php index 455be4e703..e38091764a 100644 --- a/src/Propel/Runtime/ActiveQuery/Join.php +++ b/src/Propel/Runtime/ActiveQuery/Join.php @@ -711,6 +711,24 @@ public function getJoinCondition(): ?AbstractCriterion return $this->joinCondition; } + /** + * Get the custom join condition, if previously set + * + * @throws \Propel\Runtime\Exception\LogicException + * + * @return \Propel\Runtime\ActiveQuery\Criterion\AbstractCriterion + */ + public function getJoinConditionOrFail(): AbstractCriterion + { + $joinCondition = $this->getJoinCondition(); + + if ($joinCondition === null) { + throw new LogicException('Join condition is not defined.'); + } + + return $joinCondition; + } + /** * Set the custom join condition Criterion based on the conditions of this join * diff --git a/src/Propel/Runtime/ActiveRecord/ActiveRecordInterface.php b/src/Propel/Runtime/ActiveRecord/ActiveRecordInterface.php index 7cc5cfa6f2..0d358475a4 100644 --- a/src/Propel/Runtime/ActiveRecord/ActiveRecordInterface.php +++ b/src/Propel/Runtime/ActiveRecord/ActiveRecordInterface.php @@ -12,7 +12,15 @@ * This ActiveRecord interface helps to find Propel Object * * @author jaugustin + * + * @method array toArray(string $keyType = \Propel\Runtime\Map\TableMap::TYPE_FIELDNAME, bool $includeLazyLoadColumns = true, array $alreadyDumpedObjects = [], bool $includeForeignObjects = false): array */ interface ActiveRecordInterface { + /** + * Returns true if the primary key for this object is null. + * + * @return bool + */ + public function isPrimaryKeyNull(): bool; } diff --git a/src/Propel/Runtime/Formatter/AbstractFormatterWithHydration.php b/src/Propel/Runtime/Formatter/AbstractFormatterWithHydration.php new file mode 100644 index 0000000000..a8a872e1fe --- /dev/null +++ b/src/Propel/Runtime/Formatter/AbstractFormatterWithHydration.php @@ -0,0 +1,143 @@ + + */ + protected $alreadyHydratedObjects = []; + + /** + * @var array + */ + protected $emptyVariable = []; + + /** + * @param \Propel\Runtime\ActiveRecord\ActiveRecordInterface|null $record + * + * @return array The original record turned into an array + */ + public function formatRecord(?ActiveRecordInterface $record = null): array + { + return $record ? $record->toArray() : []; + } + + /** + * @return string|null + */ + public function getCollectionClassName(): ?string + { + return ArrayCollection::class; + } + + /** + * Hydrates a series of objects from a result row + * The first object to hydrate is the model of the Criteria + * The following objects (the ones added by way of ModelCriteria::with()) are linked to the first one + * + * @param array $row associative array indexed by column number, + * as returned by DataFetcher::fetch() + * + * @return array + */ + protected function &hydratePropelObjectCollection(array $row): array + { + $col = 0; + + // hydrate main object or take it from registry + $mainObjectIsNew = false; + $this->checkInit(); + /** @var \Propel\Runtime\Map\TableMap $tableMap */ + $tableMap = $this->tableMap; + $indexType = $this->getDataFetcher()->getIndexType(); + $mainKey = $tableMap::getPrimaryKeyHashFromRow($row, 0, $indexType); + // we hydrate the main object even in case of a one-to-many relationship + // in order to get the $col variable increased anyway + $obj = $this->getSingleObjectFromRow($row, $this->class, $col); + + if (!isset($this->alreadyHydratedObjects[$this->class][$mainKey])) { + $this->alreadyHydratedObjects[$this->class][$mainKey] = $obj->toArray(); + $mainObjectIsNew = true; + } + + $hydrationChain = []; + + // related objects added using with() + foreach ($this->getWith() as $relAlias => $modelWith) { + // determine class to use + if ($modelWith->isSingleTableInheritance()) { + $class = $modelWith->getTableMap()::getOMClass($row, $col, false); + $refl = new ReflectionClass($class); + if ($refl->isAbstract()) { + $tableMapClass = "Map\\{$class}TableMap"; + $col += $tableMapClass::NUM_COLUMNS; + + continue; + } + } else { + $class = $modelWith->getModelName(); + } + + // hydrate related object or take it from registry + $key = $modelWith->getTableMap()::getPrimaryKeyHashFromRow($row, $col, $indexType); + // we hydrate the main object even in case of a one-to-many relationship + // in order to get the $col variable increased anyway + $secondaryObject = $this->getSingleObjectFromRow($row, $class, $col); + if (!isset($this->alreadyHydratedObjects[$relAlias][$key])) { + if ($secondaryObject->isPrimaryKeyNull()) { + $this->alreadyHydratedObjects[$relAlias][$key] = []; + } else { + $this->alreadyHydratedObjects[$relAlias][$key] = $secondaryObject->toArray(); + } + } + + if ($modelWith->isPrimary()) { + $arrayToAugment = &$this->alreadyHydratedObjects[$this->class][$mainKey]; + } else { + $arrayToAugment = &$hydrationChain[$modelWith->getLeftPhpName()]; + } + + if ($modelWith->isAdd()) { + if ( + !isset($arrayToAugment[$modelWith->getRelationName()]) || + !in_array( + $this->alreadyHydratedObjects[$relAlias][$key], + $arrayToAugment[$modelWith->getRelationName()], + true, + ) + ) { + $arrayToAugment[$modelWith->getRelationName()][] = &$this->alreadyHydratedObjects[$relAlias][$key]; + } + } else { + $arrayToAugment[$modelWith->getRelationName()] = &$this->alreadyHydratedObjects[$relAlias][$key]; + } + + $hydrationChain[$modelWith->getRightPhpName()] = &$this->alreadyHydratedObjects[$relAlias][$key]; + } + + // columns added using withColumn() + foreach ($this->getAsColumns() as $alias => $clause) { + $this->alreadyHydratedObjects[$this->class][$mainKey][$alias] = $row[$col]; + $col++; + } + + if ($mainObjectIsNew) { + return $this->alreadyHydratedObjects[$this->class][$mainKey]; + } + + // we still need to return a reference to something to avoid a warning + return $this->emptyVariable; + } +} diff --git a/src/Propel/Runtime/Formatter/ArrayFormatter.php b/src/Propel/Runtime/Formatter/ArrayFormatter.php index 1ff32f2d44..0038b53cf7 100644 --- a/src/Propel/Runtime/Formatter/ArrayFormatter.php +++ b/src/Propel/Runtime/Formatter/ArrayFormatter.php @@ -11,7 +11,6 @@ use Propel\Runtime\ActiveRecord\ActiveRecordInterface; use Propel\Runtime\DataFetcher\DataFetcherInterface; use Propel\Runtime\Exception\LogicException; -use ReflectionClass; /** * Array formatter for Propel query @@ -19,18 +18,8 @@ * * @author Francois Zaninotto */ -class ArrayFormatter extends AbstractFormatter +class ArrayFormatter extends AbstractFormatterWithHydration { - /** - * @var array - */ - protected $alreadyHydratedObjects = []; - - /** - * @var array - */ - protected $emptyVariable = []; - /** * @param \Propel\Runtime\DataFetcher\DataFetcherInterface|null $dataFetcher * @@ -148,90 +137,8 @@ public function isObjectFormatter(): bool */ public function &getStructuredArrayFromRow(array $row): array { - $col = 0; - - // hydrate main object or take it from registry - $mainObjectIsNew = false; - $this->checkInit(); - /** @var \Propel\Runtime\Map\TableMap $tableMap */ - $tableMap = $this->tableMap; - $indexType = $this->getDataFetcher()->getIndexType(); - $mainKey = $tableMap::getPrimaryKeyHashFromRow($row, 0, $indexType); - // we hydrate the main object even in case of a one-to-many relationship - // in order to get the $col variable increased anyway - $obj = $this->getSingleObjectFromRow($row, $this->class, $col); - - if (!isset($this->alreadyHydratedObjects[$this->class][$mainKey])) { - $this->alreadyHydratedObjects[$this->class][$mainKey] = $obj->toArray(); - $mainObjectIsNew = true; - } - - $hydrationChain = []; - - // related objects added using with() - foreach ($this->getWith() as $relAlias => $modelWith) { - // determine class to use - if ($modelWith->isSingleTableInheritance()) { - $class = $modelWith->getTableMap()::getOMClass($row, $col, false); - $refl = new ReflectionClass($class); - if ($refl->isAbstract()) { - $tableMapClass = "Map\\{$class}TableMap"; - $col += $tableMapClass::NUM_COLUMNS; - - continue; - } - } else { - $class = $modelWith->getModelName(); - } - - // hydrate related object or take it from registry - $key = $modelWith->getTableMap()::getPrimaryKeyHashFromRow($row, $col, $indexType); - // we hydrate the main object even in case of a one-to-many relationship - // in order to get the $col variable increased anyway - $secondaryObject = $this->getSingleObjectFromRow($row, $class, $col); - if (!isset($this->alreadyHydratedObjects[$relAlias][$key])) { - if ($secondaryObject->isPrimaryKeyNull()) { - $this->alreadyHydratedObjects[$relAlias][$key] = []; - } else { - $this->alreadyHydratedObjects[$relAlias][$key] = $secondaryObject->toArray(); - } - } - - if ($modelWith->isPrimary()) { - $arrayToAugment = &$this->alreadyHydratedObjects[$this->class][$mainKey]; - } else { - $arrayToAugment = &$hydrationChain[$modelWith->getLeftPhpName()]; - } - - if ($modelWith->isAdd()) { - if ( - !isset($arrayToAugment[$modelWith->getRelationName()]) || - !in_array( - $this->alreadyHydratedObjects[$relAlias][$key], - $arrayToAugment[$modelWith->getRelationName()], - true, - ) - ) { - $arrayToAugment[$modelWith->getRelationName()][] = &$this->alreadyHydratedObjects[$relAlias][$key]; - } - } else { - $arrayToAugment[$modelWith->getRelationName()] = &$this->alreadyHydratedObjects[$relAlias][$key]; - } - - $hydrationChain[$modelWith->getRightPhpName()] = &$this->alreadyHydratedObjects[$relAlias][$key]; - } - - // columns added using withColumn() - foreach ($this->getAsColumns() as $alias => $clause) { - $this->alreadyHydratedObjects[$this->class][$mainKey][$alias] = $row[$col]; - $col++; - } + $result = &$this->hydratePropelObjectCollection($row); - if ($mainObjectIsNew) { - return $this->alreadyHydratedObjects[$this->class][$mainKey]; - } - - // we still need to return a reference to something to avoid a warning - return $this->emptyVariable; + return $result; } } diff --git a/src/Propel/Runtime/Map/ColumnMap.php b/src/Propel/Runtime/Map/ColumnMap.php index 2af741e88f..41d7130a44 100644 --- a/src/Propel/Runtime/Map/ColumnMap.php +++ b/src/Propel/Runtime/Map/ColumnMap.php @@ -114,11 +114,15 @@ class ColumnMap /** * @param string $name The name of the column. * @param \Propel\Runtime\Map\TableMap $containingTable TableMap of the table this column is in. + * @param string $phpName The php name of the column. + * @param string $type A string specifying the Propel type. */ - public function __construct(string $name, TableMap $containingTable) + public function __construct(string $name, TableMap $containingTable, string $phpName, string $type) { $this->columnName = $name; $this->table = $containingTable; + $this->phpName = $phpName; + $this->type = $type; } /** @@ -176,9 +180,9 @@ public function setPhpName(string $phpName): void /** * Get the name of a column. * - * @return string|null A String with the column name. + * @return string A String with the column name. */ - public function getPhpName(): ?string + public function getPhpName(): string { return $this->phpName; } @@ -198,9 +202,9 @@ public function setType(string $type): void /** * Get the Propel type of this column. * - * @return string|null A string representing the Propel type (e.g. PropelTypes::DATE). + * @return string A string representing the Propel type (e.g. PropelTypes::DATE). */ - public function getType(): ?string + public function getType(): string { return $this->type; } diff --git a/src/Propel/Runtime/Map/RelationMap.php b/src/Propel/Runtime/Map/RelationMap.php index abc1251ab0..0c53556504 100644 --- a/src/Propel/Runtime/Map/RelationMap.php +++ b/src/Propel/Runtime/Map/RelationMap.php @@ -113,10 +113,14 @@ class RelationMap /** * @param string $name Name of the relation. + * @param \Propel\Runtime\Map\TableMap $localTable Local table map. + * @param \Propel\Runtime\Map\TableMap $foreignTable Foreign table map. */ - public function __construct(string $name) + public function __construct(string $name, TableMap $localTable, TableMap $foreignTable) { $this->name = $name; + $this->localTable = $localTable; + $this->foreignTable = $foreignTable; } /** @@ -204,9 +208,9 @@ public function setLocalTable(TableMap $table): void /** * Get the local table * - * @return \Propel\Runtime\Map\TableMap|null The local table for this relationship + * @return \Propel\Runtime\Map\TableMap The local table for this relationship */ - public function getLocalTable(): ?TableMap + public function getLocalTable(): TableMap { return $this->localTable; } @@ -226,9 +230,9 @@ public function setForeignTable(TableMap $table): void /** * Get the foreign table * - * @return \Propel\Runtime\Map\TableMap|null The foreign table for this relationship + * @return \Propel\Runtime\Map\TableMap The foreign table for this relationship */ - public function getForeignTable(): ?TableMap + public function getForeignTable(): TableMap { return $this->foreignTable; } @@ -236,9 +240,9 @@ public function getForeignTable(): ?TableMap /** * Get the left table of the relation * - * @return \Propel\Runtime\Map\TableMap|null The left table for this relationship + * @return \Propel\Runtime\Map\TableMap The left table for this relationship */ - public function getLeftTable(): ?TableMap + public function getLeftTable(): TableMap { return $this->getType() === self::MANY_TO_ONE ? $this->getLocalTable() : $this->getForeignTable(); } @@ -246,9 +250,9 @@ public function getLeftTable(): ?TableMap /** * Get the right table of the relation * - * @return \Propel\Runtime\Map\TableMap|null The right table for this relationship + * @return \Propel\Runtime\Map\TableMap The right table for this relationship */ - public function getRightTable(): ?TableMap + public function getRightTable(): TableMap { return $this->getType() === self::MANY_TO_ONE ? $this->getForeignTable() : $this->getLocalTable(); } diff --git a/src/Propel/Runtime/Map/TableMap.php b/src/Propel/Runtime/Map/TableMap.php index e50d908fdc..ce10ddf1c5 100644 --- a/src/Propel/Runtime/Map/TableMap.php +++ b/src/Propel/Runtime/Map/TableMap.php @@ -11,6 +11,7 @@ use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Collection\Collection; use Propel\Runtime\Collection\ObjectCollection; +use Propel\Runtime\Exception\LogicException; use Propel\Runtime\Map\Exception\ColumnNotFoundException; use Propel\Runtime\Map\Exception\RelationNotFoundException; @@ -21,6 +22,9 @@ * @author John D. McNally (Torque) * @author Daniel Rall (Torque) * @author William Durand + * + * @method static string getOMClass(array $row, int $column, bool $withPrefix = true) + * @method static string|null getPrimaryKeyHashFromRow(array $row, int $offset = 0, string $indexType = \Propel\Runtime\Map\TableMap::TYPE_NUM): ?string;getPrimaryKeyHashFromRow(array $row, int $offset = 0, string $indexType = TableMap::TYPE_NUM) */ class TableMap { @@ -252,6 +256,24 @@ public function getName(): ?string return $this->tableName; } + /** + * Get the name of the Table. + * + * @throws \Propel\Runtime\Exception\LogicException + * + * @return string A String with the name of the table. + */ + public function getNameOrFail(): string + { + $name = $this->getName(); + + if ($name === null) { + throw new LogicException('Name is not defined.'); + } + + return $name; + } + /** * Set the PHP name of the Table. * @@ -274,6 +296,24 @@ public function getPhpName(): ?string return $this->phpName; } + /** + * Get the PHP name of the Table. + * + * @throws \Propel\Runtime\Exception\LogicException + * + * @return string A String with the name of the table. + */ + public function getPhpNameOrFail(): string + { + $phpName = $this->getPhpName(); + + if ($phpName === null) { + throw new LogicException('PHP name is not defined.'); + } + + return $phpName; + } + /** * Set the ClassName of the Table. Could be useful for calling * tableMap and Object methods dynamically. @@ -297,6 +337,24 @@ public function getClassName(): ?string return $this->classname; } + /** + * Get the ClassName of the Propel Class belonging to this table. + * + * @throws \Propel\Runtime\Exception\LogicException + * + * @return string + */ + public function getClassNameOrFail(): string + { + $className = $this->getClassName(); + + if ($className === null) { + throw new LogicException('Class name is not defined.'); + } + + return $className; + } + /** * Get the Collection ClassName to this table. * @@ -436,10 +494,8 @@ public function addColumn( ?string $fkTable = null, ?string $fkColumn = null ): ColumnMap { - $col = new ColumnMap($name, $this); - $col->setType($type); + $col = new ColumnMap($name, $this, $phpName, $type); $col->setSize($size); - $col->setPhpName($phpName); $col->setNotNull($isNotNull); $col->setDefaultValue($defaultValue); @@ -729,9 +785,18 @@ public function addRelation( ?string $pluralName = null, bool $polymorphic = false ): RelationMap { + // determine tables + if ($type === RelationMap::MANY_TO_ONE) { + $localTable = $this; + $foreignTable = $this->dbMap->getTableByPhpName($tablePhpName); + } else { + $localTable = $this->dbMap->getTableByPhpName($tablePhpName); + $foreignTable = $this; + } + // note: using phpName for the second table allows the use of DatabaseMap::getTableByPhpName() // and this method autoloads the TableMap if the table isn't loaded yet - $relation = new RelationMap($name); + $relation = new RelationMap($name, $localTable, $foreignTable); $relation->setType($type); $relation->setOnUpdate($onUpdate); $relation->setOnDelete($onDelete); @@ -740,14 +805,7 @@ public function addRelation( if ($pluralName !== null) { $relation->setPluralName($pluralName); } - // set tables - if ($type === RelationMap::MANY_TO_ONE) { - $relation->setLocalTable($this); - $relation->setForeignTable($this->dbMap->getTableByPhpName($tablePhpName)); - } else { - $relation->setLocalTable($this->dbMap->getTableByPhpName($tablePhpName)); - $relation->setForeignTable($this); - } + // set columns foreach ($joinConditionMapping as $map) { [$local, $foreign] = $map; diff --git a/src/Propel/Runtime/Util/PropelModelPager.php b/src/Propel/Runtime/Util/PropelModelPager.php index dfb3731b6d..7d5975fccb 100644 --- a/src/Propel/Runtime/Util/PropelModelPager.php +++ b/src/Propel/Runtime/Util/PropelModelPager.php @@ -166,7 +166,9 @@ public function getResults(): Collection ->find($this->con); } - return $this->results; + return is_array($this->results) + ? new Collection($this->results) + : $this->results; } /** @@ -359,7 +361,7 @@ public function getPage(): int */ public function setPage(int $page): void { - $this->page = (int)$page; + $this->page = $page; if ($this->page <= 0 && $this->nbResults > 0) { // set first page, which depends on a maximum set $this->page = $this->getMaxPerPage() ? 1 : 0; diff --git a/tests/Propel/Tests/FieldnameRelatedTest.php b/tests/Propel/Tests/FieldnameRelatedTest.php index db4fcd1911..2cb88af14d 100644 --- a/tests/Propel/Tests/FieldnameRelatedTest.php +++ b/tests/Propel/Tests/FieldnameRelatedTest.php @@ -462,7 +462,7 @@ public function testToArrayWithForeignObjects() 'Recommended' => true, 'Status' => null, 'BookId' => null, - 'Book' => '*RECURSION*', + 'Book' => ['*RECURSION*'], ], ], ], @@ -481,7 +481,7 @@ public function testToArrayWithForeignObjects() 'recommended' => true, 'status' => null, 'bookId' => null, - 'book' => '*RECURSION*', + 'book' => ['*RECURSION*'], ], ], ], @@ -500,7 +500,7 @@ public function testToArrayWithForeignObjects() 'review.recommended' => true, 'review.status' => null, 'review.book_id' => null, - 'Book' => '*RECURSION*', + 'Book' => ['*RECURSION*'], ], ], ], @@ -519,7 +519,7 @@ public function testToArrayWithForeignObjects() 'recommended' => true, 'status' => null, 'book_id' => null, - 'book' => '*RECURSION*', + 'book' => ['*RECURSION*'], ], ], ], @@ -538,7 +538,7 @@ public function testToArrayWithForeignObjects() '3' => 1, '4' => null, '5' => null, - 'Book' => '*RECURSION*', + 'Book' => ['*RECURSION*'], ], ], ], diff --git a/tests/Propel/Tests/Generator/Behavior/Versionable/VersionableBehaviorObjectBuilderModifierTest.php b/tests/Propel/Tests/Generator/Behavior/Versionable/VersionableBehaviorObjectBuilderModifierTest.php index 36d25d5f12..8b02cc808f 100644 --- a/tests/Propel/Tests/Generator/Behavior/Versionable/VersionableBehaviorObjectBuilderModifierTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Versionable/VersionableBehaviorObjectBuilderModifierTest.php @@ -234,6 +234,8 @@ public static function setUpBeforeClass(): void } /** + * @group testGetVersionExists + * * @return void */ public function testGetVersionExists() diff --git a/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectWithFixturesTest.php b/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectWithFixturesTest.php index 12038fd438..b0bcc8938e 100644 --- a/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectWithFixturesTest.php +++ b/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectWithFixturesTest.php @@ -383,6 +383,6 @@ public function testToArrayIncludesForeignReferrers() $this->assertEquals(2, count($arr['Books'])); $this->assertEquals('War and Peace', $arr['Books'][0]['Title']); $this->assertEquals('Anna Karenina', $arr['Books'][1]['Title']); - $this->assertEquals('*RECURSION*', $arr['Books'][0]['Author']); + $this->assertEquals(['*RECURSION*'], $arr['Books'][0]['Author']); } } diff --git a/tests/Propel/Tests/Generator/Config/GeneratorConfigTest.php b/tests/Propel/Tests/Generator/Config/GeneratorConfigTest.php index 82b1bf53ea..72cb319863 100644 --- a/tests/Propel/Tests/Generator/Config/GeneratorConfigTest.php +++ b/tests/Propel/Tests/Generator/Config/GeneratorConfigTest.php @@ -222,7 +222,9 @@ public function testGetConfiguredSchemaParserGivenBadClass() */ public function testGetConfiguredBuilder() { - $stubTable = $this->getMockBuilder('\\Propel\\Generator\\Model\\Table')->getMock(); + $stubTable = $this->getMockBuilder('\\Propel\\Generator\\Model\\Table') + ->setConstructorArgs(['foo']) + ->getMock(); $actual = $this->generatorConfig->getConfiguredBuilder($stubTable, 'query'); $this->assertInstanceOf('\\Propel\\Generator\\Builder\\Om\\QueryBuilder', $actual); @@ -235,7 +237,9 @@ public function testGetConfiguredBuilderWrongTypeThrowsException() { $this->expectException(InvalidArgumentException::class); - $stubTable = $this->getMockBuilder('\\Propel\\Generator\\Model\\Table')->getMock(); + $stubTable = $this->getMockBuilder('\\Propel\\Generator\\Model\\Table') + ->setConstructorArgs(['foo']) + ->getMock(); $actual = $this->generatorConfig->getConfiguredBuilder($stubTable, 'bad_type'); } diff --git a/tests/Propel/Tests/Generator/Config/QuickGeneratorConfigTest.php b/tests/Propel/Tests/Generator/Config/QuickGeneratorConfigTest.php index 5d31e5bd77..5929eeb0a9 100644 --- a/tests/Propel/Tests/Generator/Config/QuickGeneratorConfigTest.php +++ b/tests/Propel/Tests/Generator/Config/QuickGeneratorConfigTest.php @@ -29,7 +29,9 @@ public function setUp(): void */ public function testGetConfiguredBuilder() { - $stubTable = $this->getMockBuilder('\\Propel\\Generator\\Model\\Table')->getMock(); + $stubTable = $this->getMockBuilder('\\Propel\\Generator\\Model\\Table') + ->setConstructorArgs(['foo']) + ->getMock(); $actual = $this->generatorConfig->getConfiguredBuilder($stubTable, 'query'); $this->assertInstanceOf('\\Propel\\Generator\\Builder\\Om\\QueryBuilder', $actual); @@ -43,7 +45,9 @@ public function testGetConfiguredBuilderWrongTypeThrowsException() $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid data model builder type `bad_type`'); - $stubTable = $this->getMockBuilder('\\Propel\\Generator\\Model\\Table')->getMock(); + $stubTable = $this->getMockBuilder('\\Propel\\Generator\\Model\\Table') + ->setConstructorArgs(['foo']) + ->getMock(); $actual = $this->generatorConfig->getConfiguredBuilder($stubTable, 'bad_type'); } diff --git a/tests/Propel/Tests/Generator/Model/BehaviorTest.php b/tests/Propel/Tests/Generator/Model/BehaviorTest.php index 66d28fc012..72ca41b301 100644 --- a/tests/Propel/Tests/Generator/Model/BehaviorTest.php +++ b/tests/Propel/Tests/Generator/Model/BehaviorTest.php @@ -86,7 +86,7 @@ public function testTable() { $b = new Behavior(); $this->assertNull($b->getTable(), 'Behavior Table is null by default'); - $t = new Table(); + $t = new Table(''); $t->setCommonName('fooTable'); $b->setTable($t); $this->assertEquals($b->getTable(), $t, 'setTable() sets the name, and getTable() gets it'); diff --git a/tests/Propel/Tests/Generator/Model/ColumnTest.php b/tests/Propel/Tests/Generator/Model/ColumnTest.php index d6c4237b91..cbb2027cc6 100644 --- a/tests/Propel/Tests/Generator/Model/ColumnTest.php +++ b/tests/Propel/Tests/Generator/Model/ColumnTest.php @@ -59,7 +59,7 @@ public function testSetupObjectWithoutPlatformTypeAndDomain() $table = $this->getTableMock('books', ['database' => $database]); - $column = new Column(); + $column = new Column(''); $column->setTable($table); $column->loadMapping(['name' => 'title']); @@ -95,7 +95,7 @@ public function testSetupObjectWithPlatformOnly() ->method('getType') ->will($this->returnValue('VARCHAR')); - $column = new Column(); + $column = new Column(''); $column->setTable($table); $column->setDomain($domain); $column->loadMapping(['name' => 'title']); @@ -121,7 +121,7 @@ public function testSetupObjectWithPlatformAndType() 'platform' => $platform, ]); - $column = new Column(); + $column = new Column(''); $column->setTable($table); $column->setDomain($this->getDomainMock('VARCHAR')); $column->loadMapping([ @@ -147,7 +147,7 @@ public function testSetupObjectWithDomain() $table = $this->getTableMock('books', ['database' => $database]); - $column = new Column(); + $column = new Column(''); $column->setTable($table); $column->setDomain($this->getDomainMock('BOOLEAN')); $column->loadMapping([ @@ -195,7 +195,7 @@ public function testSetupObjectWithDomain() */ public function testSetPosition() { - $column = new Column(); + $column = new Column(''); $column->setPosition(2); $this->assertSame(2, $column->getPosition()); @@ -212,7 +212,7 @@ public function testGetNullDefaultValueString() ->method('getDefaultValue') ->will($this->returnValue(null)); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $this->assertSame('null', $column->getDefaultValueString()); @@ -248,7 +248,7 @@ public function testGetDefaultValueString($mappingType, $value, $expected) ->method('getType') ->will($this->returnValue($mappingType)); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $column->setDefaultValue('foo'); // Test with a scalar $column->setDefaultValue($defaultValue); // Test with an object @@ -273,7 +273,7 @@ public function provideDefaultValues() */ public function testAddInheritance() { - $column = new Column(); + $column = new Column(''); $inheritance = $this ->getMockBuilder('Propel\Generator\Model\Inheritance') @@ -298,7 +298,7 @@ public function testAddInheritance() */ public function testAddArrayInheritance() { - $column = new Column(); + $column = new Column(''); $column->addInheritance([ 'key' => 'baz', @@ -385,7 +385,7 @@ public function testIsDefaultSqlTypeFromDomain() ->method('getSqlType') ->will($this->returnValue('INTEGER')); - $column = new Column(); + $column = new Column(''); $column->setTable($this->getTableMock('books', [ 'platform' => $platform, ])); @@ -400,7 +400,7 @@ public function testIsDefaultSqlTypeFromDomain() */ public function testIsDefaultSqlType() { - $column = new Column(); + $column = new Column(''); $this->assertTrue($column->isDefaultSqlType()); } @@ -418,7 +418,7 @@ public function testGetNotNullString() $table = $this->getTableMock('books', ['platform' => $platform]); - $column = new Column(); + $column = new Column(''); $column->setTable($table); $column->setNotNull(true); @@ -438,7 +438,7 @@ public function testGetPdoType($mappingType, $pdoType) ->method('getType') ->will($this->returnValue($mappingType)); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $column->setType($mappingType); @@ -490,7 +490,7 @@ public function testEnumType() ->method('getType') ->will($this->returnValue('ENUM')); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $column->setType('ENUM'); $column->setValueSet(['FOO', 'BAR']); @@ -513,7 +513,7 @@ public function testSetType() ->method('getType') ->will($this->returnValue('SET')); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $column->setType('SET'); $column->setValueSet(['FOO', 'BAR']); @@ -530,7 +530,7 @@ public function testSetType() */ public function testSetStringValueSet() { - $column = new Column(); + $column = new Column(''); $column->setValueSet(' FOO , BAR , BAZ'); $this->assertContains('FOO', $column->getValueSet()); @@ -549,7 +549,7 @@ public function testPhpObjectType() ->method('getType') ->will($this->returnValue('OBJECT')); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $column->setType('OBJECT'); @@ -575,7 +575,7 @@ public function testTemporalType($mappingType) ->method('getType') ->will($this->returnValue($mappingType)); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $column->setType($mappingType); @@ -613,7 +613,7 @@ public function testLobType($mappingType, $phpType, $isPhpPrimitiveType) ->method('getType') ->will($this->returnValue($mappingType)); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $column->setType($mappingType); @@ -649,7 +649,7 @@ public function testBooleanType($mappingType) ->method('getType') ->will($this->returnValue($mappingType)); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $column->setType($mappingType); @@ -684,7 +684,7 @@ public function testNumericType($mappingType, $phpType, $isPrimitiveNumericType) ->method('getType') ->will($this->returnValue($mappingType)); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $column->setType($mappingType); @@ -727,7 +727,7 @@ public function testTextType($mappingType) ->method('getType') ->will($this->returnValue($mappingType)); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $column->setType($mappingType); @@ -762,7 +762,7 @@ public function testGetSizeDefinition() ->method('getSizeDefinition') ->will($this->returnValue('(10,2)')); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $this->assertSame('(10,2)', $column->getSizeDefinition()); @@ -816,7 +816,7 @@ public function testSetCustomPhpName() */ public function testSetDefaultMutatorAndAccessorMethodsVisibility() { - $column = new Column(); + $column = new Column(''); $column->setAccessorVisibility('foo'); $column->setMutatorVisibility('bar'); @@ -829,7 +829,7 @@ public function testSetDefaultMutatorAndAccessorMethodsVisibility() */ public function testSetMutatorAndAccessorMethodsVisibility() { - $column = new Column(); + $column = new Column(''); $column->setAccessorVisibility('private'); $column->setMutatorVisibility('private'); @@ -848,7 +848,7 @@ public function testGetPhpDefaultValue() ->method('getPhpDefaultValue') ->will($this->returnValue(true)); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $this->assertTrue($column->getPhpDefaultValue()); @@ -867,7 +867,7 @@ public function testGetAutoIncrementStringThrowsEngineException() ->method('getIdMethod') ->will($this->returnValue('none')); - $column = new Column(); + $column = new Column(''); $column->setTable($table); $column->setAutoIncrement(true); $column->getAutoIncrementString(); @@ -890,7 +890,7 @@ public function testGetNativeAutoIncrementString() ->method('getIdMethod') ->will($this->returnValue('native')); - $column = new Column(); + $column = new Column(''); $column->setAutoIncrement(true); $column->setTable($table); @@ -917,7 +917,7 @@ public function testHasPlatform() 'platform' => $this->getPlatformMock(), ]); - $column = new Column(); + $column = new Column(''); $column->setTable($table); $this->assertTrue($column->hasPlatform()); @@ -929,7 +929,7 @@ public function testHasPlatform() */ public function testIsPhpArrayType() { - $column = new Column(); + $column = new Column(''); $this->assertFalse($column->isPhpArrayType()); $column->setType(PropelTypes::PHP_ARRAY); @@ -951,7 +951,7 @@ public function testSetSize() ->method('getSize') ->will($this->returnValue(50)); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $column->setSize(50); @@ -973,7 +973,7 @@ public function testSetScale() ->method('getScale') ->will($this->returnValue(2)); - $column = new Column(); + $column = new Column(''); $column->setDomain($domain); $column->setScale(2); @@ -985,7 +985,7 @@ public function testSetScale() */ public function testGetDefaultDomain() { - $column = new Column(); + $column = new Column(''); $this->assertInstanceOf('Propel\Generator\Model\Domain', $column->getDomain()); } @@ -1006,7 +1006,7 @@ public function testGetSingularName() */ public function testSetTable() { - $column = new Column(); + $column = new Column(''); $column->setTable($this->getTableMock('books')); $this->assertInstanceOf('Propel\Generator\Model\Table', $column->getTable()); @@ -1018,7 +1018,7 @@ public function testSetTable() */ public function testSetDomain() { - $column = new Column(); + $column = new Column(''); $column->setDomain($this->getDomainMock()); $this->assertInstanceOf('Propel\Generator\Model\Domain', $column->getDomain()); @@ -1029,7 +1029,7 @@ public function testSetDomain() */ public function testSetDescription() { - $column = new Column(); + $column = new Column(''); $column->setDescription('Some description'); $this->assertSame('Some description', $column->getDescription()); @@ -1040,7 +1040,7 @@ public function testSetDescription() */ public function testSetNestedSetLeftKey() { - $column = new Column(); + $column = new Column(''); $column->setNestedSetLeftKey(true); $column->setNodeKeySep(','); $column->setNodeKey(true); @@ -1055,7 +1055,7 @@ public function testSetNestedSetLeftKey() */ public function testSetNestedSetRightKey() { - $column = new Column(); + $column = new Column(''); $column->setNestedSetRightKey(true); $this->assertTrue($column->isNestedSetRightKey()); @@ -1066,7 +1066,7 @@ public function testSetNestedSetRightKey() */ public function testSetTreeScopeKey() { - $column = new Column(); + $column = new Column(''); $column->setTreeScopeKey(true); $this->assertTrue($column->isTreeScopeKey()); @@ -1077,7 +1077,7 @@ public function testSetTreeScopeKey() */ public function testSetAutoIncrement() { - $column = new Column(); + $column = new Column(''); $column->setAutoIncrement(true); $this->assertTrue($column->isAutoIncrement()); @@ -1088,7 +1088,7 @@ public function testSetAutoIncrement() */ public function testSetPrimaryString() { - $column = new Column(); + $column = new Column(''); $column->setPrimaryString(true); $this->assertTrue($column->isPrimaryString()); @@ -1099,7 +1099,7 @@ public function testSetPrimaryString() */ public function testSetNotNull() { - $column = new Column(); + $column = new Column(''); $column->setNotNull(true); $this->assertTrue($column->isNotNull()); @@ -1110,13 +1110,13 @@ public function testSetNotNull() */ public function testPhpSingularName() { - $column = new Column(); + $column = new Column(''); $column->setPhpName('Aliases'); $this->assertEquals($column->getPhpName(), 'Aliases'); $this->assertEquals($column->getPhpSingularName(), 'Aliase'); - $column = new Column(); + $column = new Column(''); $column->setPhpName('Aliases'); $column->setPhpSingularName('Alias'); diff --git a/tests/Propel/Tests/Generator/Model/DatabaseTest.php b/tests/Propel/Tests/Generator/Model/DatabaseTest.php index 38eff37745..ac2871c5ce 100644 --- a/tests/Propel/Tests/Generator/Model/DatabaseTest.php +++ b/tests/Propel/Tests/Generator/Model/DatabaseTest.php @@ -606,7 +606,7 @@ public function testCombineNamespace($databaseNamespace, $tableNamespace, $expec $database->setNamespace($databaseNamespace); } - $table = new Table(); + $table = new Table(''); if ($tableNamespace !== null) { $table->setNamespace($tableNamespace); } diff --git a/tests/Propel/Tests/Generator/Model/Diff/ColumnComparatorTest.php b/tests/Propel/Tests/Generator/Model/Diff/ColumnComparatorTest.php index 8ff03afae2..5957981714 100644 --- a/tests/Propel/Tests/Generator/Model/Diff/ColumnComparatorTest.php +++ b/tests/Propel/Tests/Generator/Model/Diff/ColumnComparatorTest.php @@ -32,13 +32,13 @@ public function setUp(): void */ public function testCompareNoDifference() { - $c1 = new Column(); + $c1 = new Column(''); $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c1->getDomain()->replaceScale(2); $c1->getDomain()->replaceSize(3); $c1->setNotNull(true); $c1->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); - $c2 = new Column(); + $c2 = new Column(''); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); $c2->getDomain()->replaceSize(3); @@ -52,9 +52,9 @@ public function testCompareNoDifference() */ public function testCompareType() { - $c1 = new Column(); + $c1 = new Column(''); $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); - $c2 = new Column(); + $c2 = new Column(''); $c2->getDomain()->copy($this->platform->getDomainForType('LONGVARCHAR')); $expectedChangedProperties = [ 'type' => ['VARCHAR', 'LONGVARCHAR'], @@ -68,9 +68,9 @@ public function testCompareType() */ public function testCompareScale() { - $c1 = new Column(); + $c1 = new Column(''); $c1->getDomain()->replaceScale(2); - $c2 = new Column(); + $c2 = new Column(''); $c2->getDomain()->replaceScale(3); $expectedChangedProperties = ['scale' => [2, 3]]; $this->assertEquals($expectedChangedProperties, ColumnComparator::compareColumns($c1, $c2)); @@ -81,9 +81,9 @@ public function testCompareScale() */ public function testCompareSize() { - $c1 = new Column(); + $c1 = new Column(''); $c1->getDomain()->replaceSize(2); - $c2 = new Column(); + $c2 = new Column(''); $c2->getDomain()->replaceSize(3); $expectedChangedProperties = ['size' => [2, 3]]; $this->assertEquals($expectedChangedProperties, ColumnComparator::compareColumns($c1, $c2)); @@ -94,9 +94,9 @@ public function testCompareSize() */ public function testCompareSqlType() { - $c1 = new Column(); + $c1 = new Column(''); $c1->getDomain()->copy($this->platform->getDomainForType('INTEGER')); - $c2 = new Column(); + $c2 = new Column(''); $c2->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c2->getDomain()->setSqlType('INTEGER(10) UNSIGNED'); $expectedChangedProperties = ['sqlType' => ['INTEGER', 'INTEGER(10) UNSIGNED']]; @@ -108,9 +108,9 @@ public function testCompareSqlType() */ public function testCompareNotNull() { - $c1 = new Column(); + $c1 = new Column(''); $c1->setNotNull(true); - $c2 = new Column(); + $c2 = new Column(''); $c2->setNotNull(false); $expectedChangedProperties = ['notNull' => [true, false]]; $this->assertEquals($expectedChangedProperties, ColumnComparator::compareColumns($c1, $c2)); @@ -121,9 +121,9 @@ public function testCompareNotNull() */ public function testCompareDefaultValueToNull() { - $c1 = new Column(); + $c1 = new Column(''); $c1->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); - $c2 = new Column(); + $c2 = new Column(''); $expectedChangedProperties = [ 'defaultValueType' => [ColumnDefaultValue::TYPE_VALUE, null], 'defaultValueValue' => [123, null], @@ -136,8 +136,8 @@ public function testCompareDefaultValueToNull() */ public function testCompareDefaultValueFromNull() { - $c1 = new Column(); - $c2 = new Column(); + $c1 = new Column(''); + $c2 = new Column(''); $c2->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); $expectedChangedProperties = [ 'defaultValueType' => [null, ColumnDefaultValue::TYPE_VALUE], @@ -151,9 +151,9 @@ public function testCompareDefaultValueFromNull() */ public function testCompareDefaultValueValue() { - $c1 = new Column(); + $c1 = new Column(''); $c1->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); - $c2 = new Column(); + $c2 = new Column(''); $c2->getDomain()->setDefaultValue(new ColumnDefaultValue(456, ColumnDefaultValue::TYPE_VALUE)); $expectedChangedProperties = [ 'defaultValueValue' => [123, 456], @@ -166,9 +166,9 @@ public function testCompareDefaultValueValue() */ public function testCompareDefaultValueType() { - $c1 = new Column(); + $c1 = new Column(''); $c1->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); - $c2 = new Column(); + $c2 = new Column(''); $c2->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_EXPR)); $expectedChangedProperties = [ 'defaultValueType' => [ColumnDefaultValue::TYPE_VALUE, ColumnDefaultValue::TYPE_EXPR], @@ -183,9 +183,9 @@ public function testCompareDefaultValueType() */ public function testCompareDefaultExrpCurrentTimestamp() { - $c1 = new Column(); + $c1 = new Column(''); $c1->getDomain()->setDefaultValue(new ColumnDefaultValue('NOW()', ColumnDefaultValue::TYPE_EXPR)); - $c2 = new Column(); + $c2 = new Column(''); $c2->getDomain()->setDefaultValue(new ColumnDefaultValue('CURRENT_TIMESTAMP', ColumnDefaultValue::TYPE_EXPR)); $this->assertEquals([], ColumnComparator::compareColumns($c1, $c2)); } @@ -195,9 +195,9 @@ public function testCompareDefaultExrpCurrentTimestamp() */ public function testCompareAutoincrement() { - $c1 = new Column(); + $c1 = new Column(''); $c1->setAutoIncrement(true); - $c2 = new Column(); + $c2 = new Column(''); $c2->setAutoIncrement(false); $expectedChangedProperties = ['autoIncrement' => [true, false]]; $this->assertEquals($expectedChangedProperties, ColumnComparator::compareColumns($c1, $c2)); @@ -208,10 +208,10 @@ public function testCompareAutoincrement() */ public function testCompareMultipleDifferences() { - $c1 = new Column(); + $c1 = new Column(''); $c1->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c1->setNotNull(false); - $c2 = new Column(); + $c2 = new Column(''); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); $c2->getDomain()->replaceSize(3); diff --git a/tests/Propel/Tests/Generator/Model/Diff/PropelTableColumnComparatorTest.php b/tests/Propel/Tests/Generator/Model/Diff/PropelTableColumnComparatorTest.php index c5badad9fa..5bfa551084 100644 --- a/tests/Propel/Tests/Generator/Model/Diff/PropelTableColumnComparatorTest.php +++ b/tests/Propel/Tests/Generator/Model/Diff/PropelTableColumnComparatorTest.php @@ -35,7 +35,7 @@ public function setUp(): void */ public function testCompareSameColumns() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c1->getDomain()->replaceScale(2); @@ -43,7 +43,7 @@ public function testCompareSameColumns() $c1->setNotNull(true); $c1->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); $t1->addColumn($c1); - $t2 = new Table(); + $t2 = new Table(''); $c2 = new Column('Foo'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); @@ -60,10 +60,10 @@ public function testCompareSameColumns() */ public function testCompareNotSameColumns() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $t1->addColumn($c1); - $t2 = new Table(); + $t2 = new Table(''); $c2 = new Column('Bar'); $t2->addColumn($c2); @@ -76,10 +76,10 @@ public function testCompareNotSameColumns() */ public function testCompareCaseInsensitive() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $t1->addColumn($c1); - $t2 = new Table(); + $t2 = new Table(''); $c2 = new Column('fOO'); $t2->addColumn($c2); @@ -94,8 +94,8 @@ public function testCompareCaseInsensitive() */ public function testCompareAddedColumn() { - $t1 = new Table(); - $t2 = new Table(); + $t1 = new Table(''); + $t2 = new Table(''); $c2 = new Column('Foo'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); @@ -119,7 +119,7 @@ public function testCompareAddedColumn() */ public function testCompareRemovedColumn() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Bar'); $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c1->getDomain()->replaceScale(2); @@ -127,7 +127,7 @@ public function testCompareRemovedColumn() $c1->setNotNull(true); $c1->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); $t1->addColumn($c1); - $t2 = new Table(); + $t2 = new Table(''); $tc = new TableComparator(); $tc->setFromTable($t1); @@ -144,13 +144,13 @@ public function testCompareRemovedColumn() */ public function testCompareModifiedColumn() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c1->getDomain()->replaceSize(255); $c1->setNotNull(false); $t1->addColumn($c1); - $t2 = new Table(); + $t2 = new Table(''); $c2 = new Column('Foo'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); @@ -175,7 +175,7 @@ public function testCompareModifiedColumn() */ public function testCompareRenamedColumn() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c1->getDomain()->replaceScale(2); @@ -183,7 +183,7 @@ public function testCompareRenamedColumn() $c1->setNotNull(true); $c1->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); $t1->addColumn($c1); - $t2 = new Table(); + $t2 = new Table(''); $c2 = new Column('Bar'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); @@ -209,7 +209,7 @@ public function testCompareRenamedColumn() */ public function testCompareSeveralColumnDifferences() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('col1'); $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c1->getDomain()->replaceSize(255); @@ -224,7 +224,7 @@ public function testCompareSeveralColumnDifferences() $c3->getDomain()->replaceSize(255); $t1->addColumn($c3); - $t2 = new Table(); + $t2 = new Table(''); $c4 = new Column('col1'); $c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c4->getDomain()->replaceScale(2); @@ -260,7 +260,7 @@ public function testCompareSeveralColumnDifferences() */ public function testCompareSeveralRenamedSameColumns() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('col1'); $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c1->getDomain()->replaceSize(255); @@ -274,7 +274,7 @@ public function testCompareSeveralRenamedSameColumns() $c3->getDomain()->replaceSize(255); $t1->addColumn($c3); - $t2 = new Table(); + $t2 = new Table(''); $c4 = new Column('col4'); $c4->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c4->getDomain()->replaceSize(255); diff --git a/tests/Propel/Tests/Generator/Model/Diff/PropelTableIndexComparatorTest.php b/tests/Propel/Tests/Generator/Model/Diff/PropelTableIndexComparatorTest.php index e8d21349ec..ab161c75fe 100644 --- a/tests/Propel/Tests/Generator/Model/Diff/PropelTableIndexComparatorTest.php +++ b/tests/Propel/Tests/Generator/Model/Diff/PropelTableIndexComparatorTest.php @@ -36,7 +36,7 @@ public function setUp(): void */ public function testCompareSameIndices() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c1->getDomain()->replaceScale(2); @@ -47,7 +47,7 @@ public function testCompareSameIndices() $i1 = new Index('Foo_Index'); $i1->addColumn($c1); $t1->addIndex($i1); - $t2 = new Table(); + $t2 = new Table(''); $c2 = new Column('Foo'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); @@ -67,7 +67,7 @@ public function testCompareSameIndices() */ public function testCompareNotSameIndices() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c1->getDomain()->replaceScale(2); @@ -78,7 +78,7 @@ public function testCompareNotSameIndices() $i1 = new Index('Foo_Index'); $i1->addColumn($c1); $t1->addIndex($i1); - $t2 = new Table(); + $t2 = new Table(''); $c2 = new Column('Foo'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); @@ -99,7 +99,7 @@ public function testCompareNotSameIndices() */ public function testCompareCaseInsensitive() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c1->getDomain()->replaceScale(2); @@ -111,7 +111,7 @@ public function testCompareCaseInsensitive() $i1->addColumn($c1); $t1->addIndex($i1); - $t2 = new Table(); + $t2 = new Table(''); $c2 = new Column('fOO'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); @@ -132,8 +132,8 @@ public function testCompareCaseInsensitive() */ public function testCompareAddedIndices() { - $t1 = new Table(); - $t2 = new Table(); + $t1 = new Table(''); + $t2 = new Table(''); $c2 = new Column('Foo'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); @@ -160,7 +160,7 @@ public function testCompareAddedIndices() */ public function testCompareRemovedIndices() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Bar'); $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c1->getDomain()->replaceScale(2); @@ -171,7 +171,7 @@ public function testCompareRemovedIndices() $i1 = new Index('Bar_Index'); $i1->addColumn($c1); $t1->addIndex($i1); - $t2 = new Table(); + $t2 = new Table(''); $tc = new TableComparator(); $tc->setFromTable($t1); @@ -188,7 +188,7 @@ public function testCompareRemovedIndices() */ public function testCompareModifiedIndices() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c1->getDomain()->replaceSize(255); @@ -197,7 +197,7 @@ public function testCompareModifiedIndices() $i1 = new Index('Foo_Index'); $i1->addColumn($c1); $t1->addIndex($i1); - $t2 = new Table(); + $t2 = new Table(''); $c2 = new Column('Foo'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); diff --git a/tests/Propel/Tests/Generator/Model/Diff/PropelTablePkColumnComparatorTest.php b/tests/Propel/Tests/Generator/Model/Diff/PropelTablePkColumnComparatorTest.php index 23ff9954c0..a43373ea8d 100644 --- a/tests/Propel/Tests/Generator/Model/Diff/PropelTablePkColumnComparatorTest.php +++ b/tests/Propel/Tests/Generator/Model/Diff/PropelTablePkColumnComparatorTest.php @@ -34,12 +34,12 @@ public function setUp(): void */ public function testCompareSamePks() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c1->setPrimaryKey(true); $t1->addColumn($c1); - $t2 = new Table(); + $t2 = new Table(''); $c2 = new Column('Foo'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->setPrimaryKey(true); @@ -53,11 +53,11 @@ public function testCompareSamePks() */ public function testCompareNotSamePks() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $c1->setPrimaryKey(true); $t1->addColumn($c1); - $t2 = new Table(); + $t2 = new Table(''); $c2 = new Column('Foo'); $t2->addColumn($c2); @@ -70,8 +70,8 @@ public function testCompareNotSamePks() */ public function testCompareAddedPkColumn() { - $t1 = new Table(); - $t2 = new Table(); + $t1 = new Table(''); + $t2 = new Table(''); $c2 = new Column('Foo'); $c2->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c2->setPrimaryKey(true); @@ -95,7 +95,7 @@ public function testCompareAddedPkColumn() */ public function testCompareRemovedPkColumn() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c1->setPrimaryKey(true); @@ -103,7 +103,7 @@ public function testCompareRemovedPkColumn() $c2 = new Column('Bar'); $c2->getDomain()->copy($this->platform->getDomainForType('LONGVARCHAR')); $t1->addColumn($c2); - $t2 = new Table(); + $t2 = new Table(''); $tc = new TableComparator(); $tc->setFromTable($t1); @@ -120,7 +120,7 @@ public function testCompareRemovedPkColumn() */ public function testCompareRenamedPkColumn() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c1->getDomain()->replaceScale(2); @@ -129,7 +129,7 @@ public function testCompareRenamedPkColumn() $c1->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); $c1->setPrimaryKey(true); $t1->addColumn($c1); - $t2 = new Table(); + $t2 = new Table(''); $c2 = new Column('Bar'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); @@ -156,7 +156,7 @@ public function testCompareRenamedPkColumn() */ public function testCompareSeveralPrimaryKeyDifferences() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('col1'); $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c1->getDomain()->replaceSize(255); @@ -173,7 +173,7 @@ public function testCompareSeveralPrimaryKeyDifferences() $c3->setPrimaryKey(true); $t1->addColumn($c3); - $t2 = new Table(); + $t2 = new Table(''); $c4 = new Column('col1'); $c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c4->getDomain()->replaceScale(2); @@ -209,7 +209,7 @@ public function testCompareSeveralPrimaryKeyDifferences() */ public function testCompareSeveralRenamedSamePrimaryKeys() { - $t1 = new Table(); + $t1 = new Table(''); $c1 = new Column('col1'); $c1->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c1->setNotNull(true); @@ -226,7 +226,7 @@ public function testCompareSeveralRenamedSamePrimaryKeys() $c3->setPrimaryKey(true); $t1->addColumn($c3); - $t2 = new Table(); + $t2 = new Table(''); $c4 = new Column('col4'); $c4->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c4->setNotNull(true); diff --git a/tests/Propel/Tests/Generator/Model/Diff/TableDiffTest.php b/tests/Propel/Tests/Generator/Model/Diff/TableDiffTest.php index 951c590511..727292f343 100644 --- a/tests/Propel/Tests/Generator/Model/Diff/TableDiffTest.php +++ b/tests/Propel/Tests/Generator/Model/Diff/TableDiffTest.php @@ -224,7 +224,7 @@ public function testSetRenamedPkColumns() */ public function testSetAddedIndices() { - $table = new Table(); + $table = new Table(''); $table->setDatabase(new Database('foo', new DefaultPlatform())); $index = new Index('username_unique_idx'); @@ -242,7 +242,7 @@ public function testSetAddedIndices() */ public function testSetRemovedIndices() { - $table = new Table(); + $table = new Table(''); $table->setDatabase(new Database('foo', new DefaultPlatform())); $index = new Index('username_unique_idx'); @@ -478,7 +478,7 @@ public function testReverseDiffHasRenamedPkColumn() */ public function testReverseDiffHasAddedIndices() { - $table = new Table(); + $table = new Table(''); $table->setDatabase(new Database('foo', new DefaultPlatform())); $index = new Index('username_unique_idx'); @@ -497,7 +497,7 @@ public function testReverseDiffHasAddedIndices() */ public function testReverseDiffHasRemovedIndices() { - $table = new Table(); + $table = new Table(''); $table->setDatabase(new Database('foo', new DefaultPlatform())); $index = new Index('username_unique_idx'); @@ -516,7 +516,7 @@ public function testReverseDiffHasRemovedIndices() */ public function testReverseDiffHasModifiedIndices() { - $table = new Table(); + $table = new Table(''); $table->setDatabase(new Database('foo', new DefaultPlatform())); $fromIndex = new Index('i1'); diff --git a/tests/Propel/Tests/Generator/Model/TableTest.php b/tests/Propel/Tests/Generator/Model/TableTest.php index 4f055ecd03..5740b7fd97 100644 --- a/tests/Propel/Tests/Generator/Model/TableTest.php +++ b/tests/Propel/Tests/Generator/Model/TableTest.php @@ -49,7 +49,7 @@ public function testCreateNewTable() */ public function testSetNamespace($namespace, $expected) { - $table = new Table(); + $table = new Table(''); $table->setNamespace($namespace); $this->assertSame($expected, $table->getNamespace()); @@ -81,7 +81,7 @@ public function testGetGeneratorConfig() ->method('getGeneratorConfig') ->will($this->returnValue($config)); - $table = new Table(); + $table = new Table(''); $table->setDatabase($database); $this->assertSame($config, $table->getGeneratorConfig()); @@ -92,7 +92,7 @@ public function testGetGeneratorConfig() */ public function testGetBuildProperty() { - $table = new Table(); + $table = new Table(''); $this->assertEmpty($table->getBuildProperty('propel.foo.bar')); $database = $this->getDatabaseMock('bookstore'); @@ -131,7 +131,7 @@ public function testApplyBehaviors() ->method('setTableModified') ->with($this->equalTo(true)); - $table = new Table(); + $table = new Table(''); $table->addBehavior($behavior); $table->applyBehaviors(); } @@ -151,7 +151,7 @@ public function testGetAdditionalBuilders() 'additional_builders' => $additionalBehaviors, ]); - $table = new Table(); + $table = new Table(''); $table->addBehavior($behavior); $this->assertCount(3, $table->getAdditionalBuilders()); @@ -163,7 +163,7 @@ public function testGetAdditionalBuilders() */ public function testHasNoAdditionalBuilders() { - $table = new Table(); + $table = new Table(''); $table->addBehavior($this->getBehaviorMock('foo')); $this->assertCount(0, $table->getAdditionalBuilders()); @@ -181,7 +181,7 @@ public function testGetColumnList() $this->getColumnMock('baz'), ]; - $table = new Table(); + $table = new Table(''); $this->assertSame('foo|bar|baz', $table->getColumnList($columns, '|')); } @@ -256,7 +256,7 @@ public function testSetCustomPhpName() */ public function testSetDescription() { - $table = new Table(); + $table = new Table(''); $this->assertFalse($table->hasDescription()); @@ -272,7 +272,7 @@ public function testSetInvalidDefaultStringFormat() { $this->expectException(InvalidArgumentException::class); - $table = new Table(); + $table = new Table(''); $table->setDefaultStringFormat('FOO'); } @@ -287,7 +287,7 @@ public function testGetDefaultStringFormatFromDatabase() ->method('getDefaultStringFormat') ->will($this->returnValue('XML')); - $table = new Table(); + $table = new Table(''); $table->setDatabase($database); $this->assertSame('XML', $table->getDefaultStringFormat()); @@ -300,7 +300,7 @@ public function testGetDefaultStringFormatFromDatabase() */ public function testGetDefaultStringFormat($format) { - $table = new Table(); + $table = new Table(''); $table->setDefaultStringFormat($format); $this->assertSame($format, $table->getDefaultStringFormat()); @@ -404,7 +404,7 @@ public function testHasBehaviors() $behavior2 = $this->getBehaviorMock('Bar'); $behavior3 = $this->getBehaviorMock('Baz'); - $table = new Table(); + $table = new Table(''); $table->addBehavior($behavior1); $table->addBehavior($behavior2); $table->addBehavior($behavior3); @@ -556,7 +556,7 @@ public function testCantGetColumn() */ public function testSetAbstract() { - $table = new Table(); + $table = new Table(''); $this->assertFalse($table->isAbstract()); $table->setAbstract(true); @@ -568,7 +568,7 @@ public function testSetAbstract() */ public function testSetInterface() { - $table = new Table(); + $table = new Table(''); $table->setInterface('ActiveRecordInterface'); $this->assertSame('ActiveRecordInterface', $table->getInterface()); @@ -579,7 +579,7 @@ public function testSetInterface() */ public function testAddIndex() { - $table = new Table(); + $table = new Table(''); $index = new Index(); $index->addColumn(['name' => 'bla']); $table->addIndex($index); @@ -594,7 +594,7 @@ public function testAddEmptyIndex() { $this->expectException(InvalidArgumentException::class); - $table = new Table(); + $table = new Table(''); $table->addIndex(new Index()); $this->assertCount(1, $table->getIndices()); @@ -605,7 +605,7 @@ public function testAddEmptyIndex() */ public function testAddArrayIndex() { - $table = new Table(); + $table = new Table(''); $table->addIndex(['name' => 'author_idx', 'columns' => [['name' => 'bla']]]); $this->assertCount(1, $table->getIndices()); @@ -616,7 +616,7 @@ public function testAddArrayIndex() */ public function testIsIndex() { - $table = new Table(); + $table = new Table(''); $column1 = new Column('category_id'); $column2 = new Column('type'); $table->addColumn($column1); @@ -637,7 +637,7 @@ public function testIsIndex() */ public function testAddUniqueIndex() { - $table = new Table(); + $table = new Table(''); $table->addUnique($this->getUniqueIndexMock('author_unq')); $this->assertCount(1, $table->getUnices()); @@ -648,7 +648,7 @@ public function testAddUniqueIndex() */ public function testAddArrayUnique() { - $table = new Table(); + $table = new Table(''); $table->addUnique(['name' => 'author_unq']); $this->assertCount(1, $table->getUnices()); @@ -663,7 +663,7 @@ public function testGetCompositePrimaryKey() $column2 = $this->getColumnMock('author_id', ['primary' => true]); $column3 = $this->getColumnMock('rank'); - $table = new Table(); + $table = new Table(''); $table->setIdMethod('native'); $table->addColumn($column1); $table->addColumn($column2); @@ -686,7 +686,7 @@ public function testGetSinglePrimaryKey() $column2 = $this->getColumnMock('title'); $column3 = $this->getColumnMock('isbn'); - $table = new Table(); + $table = new Table(''); $table->setIdMethod('native'); $table->addColumn($column1); $table->addColumn($column2); @@ -709,7 +709,7 @@ public function testGetNoPrimaryKey() $column2 = $this->getColumnMock('title'); $column3 = $this->getColumnMock('isbn'); - $table = new Table(); + $table = new Table(''); $table->setIdMethod('none'); $table->addColumn($column1); $table->addColumn($column2); @@ -736,7 +736,7 @@ public function testGetAutoIncrementPrimaryKey() $column2 = $this->getColumnMock('title'); $column3 = $this->getColumnMock('isbn'); - $table = new Table(); + $table = new Table(''); $table->setIdMethod('native'); $table->addColumn($column1); $table->addColumn($column2); @@ -761,7 +761,7 @@ public function testAddIdMethodParameter() ->expects($this->once()) ->method('setTable'); - $table = new Table(); + $table = new Table(''); $table->addIdMethodParameter($parameter); $this->assertCount(1, $table->getIdMethodParameters()); @@ -772,7 +772,7 @@ public function testAddIdMethodParameter() */ public function testAddArrayIdMethodParameter() { - $table = new Table(); + $table = new Table(''); $table->addIdMethodParameter(['name' => 'foo', 'value' => 'bar']); $this->assertCount(1, $table->getIdMethodParameters()); @@ -838,7 +838,7 @@ public function testGetForeignKeysReferencingTable() $fk2 = $this->getForeignKeyMock('fk2', ['foreign_table_name' => 'categories']); $fk3 = $this->getForeignKeyMock('fk3', ['foreign_table_name' => 'authors']); - $table = new Table(); + $table = new Table(''); $table->addForeignKey($fk1); $table->addForeignKey($fk2); $table->addForeignKey($fk3); @@ -855,7 +855,7 @@ public function testGetForeignKeysReferencingTableMoreThenOnce() $fk2 = $this->getForeignKeyMock('fk2', ['foreign_table_name' => 'categories']); $fk3 = $this->getForeignKeyMock('fk1', ['foreign_table_name' => 'authors']); - $table = new Table(); + $table = new Table(''); $table->addForeignKey($fk1); $table->addForeignKey($fk2); @@ -877,7 +877,7 @@ public function testGetColumnForeignKeys() 'local_columns' => ['foo', 'bar'], ]); - $table = new Table(); + $table = new Table(''); $table->addForeignKey($fk1); $table->addForeignKey($fk2); @@ -904,7 +904,7 @@ public function baseClassDataProvider(): array */ public function testSetBaseClass(string $className, string $expectedClassName, string $message) { - $table = new Table(); + $table = new Table(''); $table->setBaseClass($className); $this->assertSame($expectedClassName, $table->getBaseClass(), $message); @@ -917,7 +917,7 @@ public function testSetBaseClass(string $className, string $expectedClassName, s */ public function testSetBaseQueryClass(string $className, string $expectedClassName, string $message) { - $table = new Table(); + $table = new Table(''); $table->setBaseQueryClass($className); $this->assertSame($expectedClassName, $table->getBaseQueryClass(), $message); @@ -934,7 +934,7 @@ public function testGetBaseClassesFromDatabase() ->method('getBaseClass') ->will($this->returnValue('BaseObject')); - $table = new Table(); + $table = new Table(''); $table->setDatabase($database); $this->assertSame('BaseObject', $table->getBaseClass()); @@ -979,7 +979,7 @@ public function testTablePrefix() 'defaultStringFormat' => 'XML', ]); - $table = new Table(); + $table = new Table(''); $database->addTable($table); $table->loadMapping([ 'name' => 'books', @@ -993,7 +993,7 @@ public function testTablePrefix() */ public function testSetContainsForeignPK() { - $table = new Table(); + $table = new Table(''); $table->setContainsForeignPK(true); $this->assertTrue($table->getContainsForeignPK()); diff --git a/tests/Propel/Tests/Generator/Platform/DefaultPlatformTest.php b/tests/Propel/Tests/Generator/Platform/DefaultPlatformTest.php index 91685f4967..5d9593fb2a 100644 --- a/tests/Propel/Tests/Generator/Platform/DefaultPlatformTest.php +++ b/tests/Propel/Tests/Generator/Platform/DefaultPlatformTest.php @@ -114,7 +114,7 @@ public function testQuote() protected function createColumn($type, $defaultValue) { - $column = new Column(); + $column = new Column(''); $column->setType($type); $column->setDefaultValue($defaultValue); @@ -123,7 +123,7 @@ protected function createColumn($type, $defaultValue) public function createEnumColumn($defaultValues, $defaultValue) { - $column = new Column(); + $column = new Column(''); $column->setType(PropelTypes::ENUM); $column->setValueSet($defaultValues); $column->setDefaultValue($defaultValue); @@ -133,7 +133,7 @@ public function createEnumColumn($defaultValues, $defaultValue) public function createSetColumn($defaultValues, $defaultValue) { - $column = new Column(); + $column = new Column(''); $column->setType(PropelTypes::SET); $column->setValueSet($defaultValues); $column->setDefaultValue($defaultValue); diff --git a/tests/Propel/Tests/Generator/Platform/PlatformMigrationTestProvider.php b/tests/Propel/Tests/Generator/Platform/PlatformMigrationTestProvider.php index 28c6ec934e..338195d04a 100644 --- a/tests/Propel/Tests/Generator/Platform/PlatformMigrationTestProvider.php +++ b/tests/Propel/Tests/Generator/Platform/PlatformMigrationTestProvider.php @@ -497,14 +497,14 @@ public function providerForTestGetModifyColumnRemoveDefaultValueDDL() { $t1 = new Table('test'); $t1->setIdentifierQuoting(true); - $c1 = new Column(); + $c1 = new Column(''); $c1->setName('test'); $c1->getDomain()->setType('INTEGER'); $c1->setDefaultValue(0); $t1->addColumn($c1); $t2 = new Table('test'); $t2->setIdentifierQuoting(true); - $c2 = new Column(); + $c2 = new Column(''); $c2->setName('test'); $c2->getDomain()->setType('INTEGER'); $t2->addColumn($c2); diff --git a/tests/Propel/Tests/Runtime/ActiveRecordConvertTest.php b/tests/Propel/Tests/Runtime/ActiveRecordConvertTest.php index d70ee4e487..b8c54b0d5b 100644 --- a/tests/Propel/Tests/Runtime/ActiveRecordConvertTest.php +++ b/tests/Propel/Tests/Runtime/ActiveRecordConvertTest.php @@ -61,7 +61,9 @@ public function toXmlDataProvider() 1234 - + + + @@ -71,7 +73,9 @@ public function toXmlDataProvider() - + + + @@ -126,7 +130,7 @@ public function toYamlDataProvider() Id: 1234 Name: Penguin Books: - - '*RECURSION*' + - ['*RECURSION*'] Author: Id: 5678 FirstName: George @@ -134,7 +138,7 @@ public function toYamlDataProvider() Email: null Age: null Books: - - '*RECURSION*' + - ['*RECURSION*'] EOF; @@ -176,18 +180,18 @@ public function testFromYAML($expected) public function toJsonDataProvider() { $phpName = << null, 'Age' => null, 'Books' => [ - 0 => '*RECURSION*', + 0 => ['*RECURSION*'], ], ], ]]; diff --git a/tests/Propel/Tests/Runtime/Collection/ObjectCollectionTest.php b/tests/Propel/Tests/Runtime/Collection/ObjectCollectionTest.php index 6bc5a8c906..9f3d6526a7 100644 --- a/tests/Propel/Tests/Runtime/Collection/ObjectCollectionTest.php +++ b/tests/Propel/Tests/Runtime/Collection/ObjectCollectionTest.php @@ -147,7 +147,7 @@ public function testToArrayDeep() 'Email' => null, 'Age' => null, 'Books' => [ - 0 => '*RECURSION*', + 0 => ['*RECURSION*'], ], ], ]]; diff --git a/tests/Propel/Tests/Runtime/Map/ColumnMapTest.php b/tests/Propel/Tests/Runtime/Map/ColumnMapTest.php index 666c0113e5..fac68d8634 100644 --- a/tests/Propel/Tests/Runtime/Map/ColumnMapTest.php +++ b/tests/Propel/Tests/Runtime/Map/ColumnMapTest.php @@ -23,6 +23,21 @@ */ class ColumnMapTest extends TestCaseFixtures { + /** + * @var string + */ + protected const COLUMN_NAME = 'bar'; + + /** + * @var string + */ + protected const PHP_NAME = 'php_bar'; + + /** + * @var string + */ + protected const TYPE = 'type'; + protected $databaseMap; /** @@ -33,8 +48,7 @@ protected function setUp(): void parent::setUp(); $this->dmap = new DatabaseMap('foodb'); $this->tmap = new TableMap('foo', $this->dmap); - $this->columnName = 'bar'; - $this->cmap = new ColumnMap($this->columnName, $this->tmap); + $this->cmap = new ColumnMap(static::COLUMN_NAME, $this->tmap, static::PHP_NAME, static::TYPE); } /** @@ -51,9 +65,10 @@ protected function tearDown(): void */ public function testConstructor() { - $this->assertEquals($this->columnName, $this->cmap->getName(), 'constructor sets the column name'); + $this->assertEquals(static::COLUMN_NAME, $this->cmap->getName(), 'constructor sets the column name'); $this->assertEquals($this->tmap, $this->cmap->getTable(), 'Constructor sets the table map'); - $this->assertNull($this->cmap->getType(), 'A new column map has no type'); + $this->assertEquals(static::PHP_NAME, $this->cmap->getPhpName(), 'constructor sets the php name'); + $this->assertEquals(static::TYPE, $this->cmap->getType(), 'constructor sets the type'); } /** @@ -61,7 +76,6 @@ public function testConstructor() */ public function testPhpName() { - $this->assertNull($this->cmap->getPhpName(), 'phpName is empty until set'); $this->cmap->setPhpName('FooBar'); $this->assertEquals('FooBar', $this->cmap->getPhpName(), 'phpName is set by setPhpName()'); } @@ -71,7 +85,6 @@ public function testPhpName() */ public function testType() { - $this->assertNull($this->cmap->getType(), 'type is empty until set'); $this->cmap->setType('FooBar'); $this->assertEquals('FooBar', $this->cmap->getType(), 'type is set by setType()'); } diff --git a/tests/Propel/Tests/Runtime/Map/RelationMapTest.php b/tests/Propel/Tests/Runtime/Map/RelationMapTest.php index abfd226343..34fea6f197 100644 --- a/tests/Propel/Tests/Runtime/Map/RelationMapTest.php +++ b/tests/Propel/Tests/Runtime/Map/RelationMapTest.php @@ -36,6 +36,16 @@ class RelationMapTest extends TestCase */ protected $rmap; + /** + * @var \Propel\Runtime\Map\RelationMap + */ + protected $defaultLocalTable; + + /** + * @var \Propel\Runtime\Map\RelationMap + */ + protected $defaultForeignTable; + /** * @return void */ @@ -44,7 +54,9 @@ protected function setUp(): void parent::setUp(); $this->databaseMap = new DatabaseMap('foodb'); $this->relationName = 'foo'; - $this->rmap = new RelationMap($this->relationName); + $this->defaultLocalTable = new TableMap('local'); + $this->defaultForeignTable = new TableMap('foreign'); + $this->rmap = new RelationMap($this->relationName, $this->defaultLocalTable, $this->defaultForeignTable); } /** @@ -60,7 +72,7 @@ public function testConstructor() */ public function testLocalTable() { - $this->assertNull($this->rmap->getLocalTable(), 'A new relation has no local table'); + $this->assertSame($this->defaultLocalTable, $this->rmap->getLocalTable(), 'constructor sets the local table'); $tmap1 = new TableMap('foo', $this->databaseMap); $this->rmap->setLocalTable($tmap1); $this->assertEquals($tmap1, $this->rmap->getLocalTable(), 'The local table is set by setLocalTable()'); @@ -71,7 +83,7 @@ public function testLocalTable() */ public function testForeignTable() { - $this->assertNull($this->rmap->getForeignTable(), 'A new relation has no foreign table'); + $this->assertSame($this->defaultForeignTable, $this->rmap->getForeignTable(), 'constructor sets the foreign table'); $tmap2 = new TableMap('bar', $this->databaseMap); $this->rmap->setForeignTable($tmap2); $this->assertEquals($tmap2, $this->rmap->getForeignTable(), 'The foreign table is set by setForeignTable()'); diff --git a/tests/Propel/Tests/Runtime/Map/TableMapTest.php b/tests/Propel/Tests/Runtime/Map/TableMapTest.php index 0e188133fd..bd6c793162 100644 --- a/tests/Propel/Tests/Runtime/Map/TableMapTest.php +++ b/tests/Propel/Tests/Runtime/Map/TableMapTest.php @@ -284,9 +284,7 @@ public function testPrimaryStringAddConfiguredColumn() { $this->assertFalse($this->tmap->hasPrimaryStringColumn(), 'hasPrimaryStringColumn() returns false while none set.'); - $column = new ColumnMap('BAR', $this->tmap); - $column->setPhpName('Bar'); - $column->setType('VARCHAR'); + $column = new ColumnMap('BAR', $this->tmap, 'Bar', 'VARCHAR'); $column->setPrimaryString(true); $this->tmap->addConfiguredColumn($column);