diff --git a/.docker/php74_81/Dockerfile b/.docker/php74_82/Dockerfile similarity index 100% rename from .docker/php74_81/Dockerfile rename to .docker/php74_82/Dockerfile diff --git a/.gitattributes b/.gitattributes index 884d89b58..bf85d2fd1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,8 @@ +/.docker export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/.travis.yml export-ignore -/build.properties.dev export-ignore -/build.xml export-ignore +/.github export-ignore + +/docker-compose.yml /tests export-ignore /tools export-ignore diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 000000000..f35e4be3c --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,61 @@ +name: "Continuous Integration" + +on: + pull_request: + branches: + - php82 + paths: + - .github/workflows/continuous-integration.yml + - composer.* + - lib/** + - tests/** + + push: + branches: + - php82 + paths: + - .github/workflows/continuous-integration.yml + - composer.* + - lib/** + - tests/** + +env: + fail-fast: true + +jobs: + tests: + name: "Doctrine1 Tests" + runs-on: "ubuntu-latest" + strategy: + matrix: + php-version: + - "8.2" + - "8.3" + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: "true" + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php-version }}" + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist + + - name: Run Tests + run: cd tests && php run.php diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index cfd880464..000000000 --- a/.travis.yml +++ /dev/null @@ -1,49 +0,0 @@ -os: linux -dist: focal -language: php - -php: - - 7.4 - - 8.0 - - 8.1 - - nightly - -cache: - directories: - - $HOME/.composer/cache - -jobs: - fast_finish: true - allow_failures: - - php: nightly - - php: 5.3 - include: - - php: 5.3 - dist: precise - - php: 5.4 - dist: trusty - - php: 5.5 - dist: trusty - - php: 5.6 - dist: trusty - - php: 7.0 - dist: xenial - - php: 7.1 - dist: xenial - - php: 7.2 - dist: xenial - - php: 7.3 - dist: xenial - - -services: - - mysql - -before_install: - - mysql -e 'CREATE DATABASE IF NOT EXISTS test;' - -install: - - composer install --prefer-dist --no-progress --no-suggest -o - -script: - - "cd tests && php -dshort_open_tag=Off -dmagic_quotes_gpc=Off run.php" diff --git a/README.md b/README.md index eede636ae..27f085e1b 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Installation Using [Composer](http://getcomposer.org/doc/00-intro.md) as dependency management: - composer require friendsofsymfony1/doctrine1 "1.5.*" + composer require friendsofsymfony1/doctrine1 "1.4.*" composer install diff --git a/build.properties.dev b/build.properties.dev deleted file mode 100644 index e7f708229..000000000 --- a/build.properties.dev +++ /dev/null @@ -1,11 +0,0 @@ -version=1.2.3 -stability=stable -build.dir=build -dist.dir=dist -report.dir=reports -log.archive.dir=logs -test.phpunit_configuration_file= -test.phpunit_generate_coverage=0 -test.pmd_reports=0 -test.pdepend_exec= -test.phpmd_exec= \ No newline at end of file diff --git a/build.xml b/build.xml deleted file mode 100644 index 5ff0aea54..000000000 --- a/build.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Doctrine - PHP5 Database ORM - pear.doctrine-project.org - -Doctrine is an ORM (object relational mapper) for PHP 5.2.x+ that sits on top of -a powerful DBAL (database abstraction layer). One of its key features is the -ability to optionally write database queries in an OO (object oriented) -SQL-dialect called DQL inspired by Hibernates HQL. This provides developers with -a powerful alternative to SQL that maintains a maximum of flexibility without -requiring needless code duplication. - - - LGPL - - - - - - - - - - - - - \ No newline at end of file diff --git a/composer.json b/composer.json index 5e5a429cb..6a264bcfd 100644 --- a/composer.json +++ b/composer.json @@ -20,9 +20,10 @@ } ], "require": { - "php": ">=8.1", + "php": ">=8.2", "ext-mbstring": "*", - "ext-pdo": "*" + "ext-pdo": "*", + "ext-zlib": "*" }, "support": { "issues": "https://github.com/JamesAndJamesFulfilment/doctrine1/issues", @@ -37,5 +38,8 @@ "branch-alias": { "dev-php81": "1.5-dev" } + }, + "config": { + "sort-packages": true } } diff --git a/docker-compose.yml b/docker-compose.yml index b2c8c194b..1fbd34ef8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,30 +15,12 @@ services: - | exec tail -f /dev/null - php81: + php82: + <<: *services_php8x build: - context: .docker/php74_81 + context: .docker/php74_82 args: - PHP_VERSION: '8.1' - working_dir: /app/tests - volumes: - - .:/app - - db_socket:/var/run/mysqld - entrypoint: - - sh - - -c - - | - { - echo 'pdo_mysql.default_socket = /var/run/mysqld/mysql.sock' - echo 'memory_limit = -1' - echo 'short_open_tag = off' - echo 'magic_quotes_gpc = off' - echo 'date.timezone = "UTC"' - } | tee -a /usr/local/etc/php/php.ini - - exec tail -f /dev/null - depends_on: - - db + PHP_VERSION: '8.2' db: image: mysql:5.5.62 diff --git a/lib/Doctrine/Access.php b/lib/Doctrine/Access.php index 82204abc9..f066e7f4a 100644 --- a/lib/Doctrine/Access.php +++ b/lib/Doctrine/Access.php @@ -96,10 +96,7 @@ public function __unset($name) } /** - * Check if an offset axists - * - * @param mixed $offset - * @return boolean Whether or not this object contains $offset + * @return bool */ #[\ReturnTypeWillChange] public function offsetExists($offset) @@ -108,10 +105,6 @@ public function offsetExists($offset) } /** - * An alias of get() - * - * @see get, __get - * @param mixed $offset * @return mixed */ #[\ReturnTypeWillChange] @@ -127,11 +120,6 @@ public function offsetGet($offset) } /** - * Sets $offset to $value - * - * @see set, __set - * @param mixed $offset - * @param mixed $value * @return void */ #[\ReturnTypeWillChange] @@ -145,22 +133,19 @@ public function offsetSet($offset, $value) } /** - * Unset a given offset - * - * @see set, offsetSet, __set - * @param mixed $offset + * @return void */ #[\ReturnTypeWillChange] public function offsetUnset($offset) { - return $this->remove($offset); + $this->remove($offset); } /** * Remove the element with the specified offset * * @param mixed $offset The offset to remove - * @return boolean True if removed otherwise false + * @return bool True if removed otherwise false */ public function remove($offset) { @@ -191,8 +176,8 @@ public function set($offset, $value) } /** - * Check if the specified offset exists - * + * Check if the specified offset exists + * * @param mixed $offset The offset to check * @return boolean True if exists otherwise false */ @@ -202,9 +187,9 @@ public function contains($offset) } /** - * Add the value - * - * @param mixed $value The value to add + * Add the value + * + * @param mixed $value The value to add * @return void */ public function add($value) diff --git a/lib/Doctrine/Cli/AnsiColorFormatter.php b/lib/Doctrine/Cli/AnsiColorFormatter.php index b3d1aa444..cca3afb7d 100644 --- a/lib/Doctrine/Cli/AnsiColorFormatter.php +++ b/lib/Doctrine/Cli/AnsiColorFormatter.php @@ -115,7 +115,7 @@ public function formatSection($section, $text, $size = null) { $width = 9 + strlen($this->format('', 'INFO')); - return sprintf(">> %-${width}s %s", $this->format($section, 'INFO'), $this->excerpt($text, $size)); + return sprintf(">> %-{$width}s %s", $this->format($section, 'INFO'), $this->excerpt($text, $size)); } /** diff --git a/lib/Doctrine/Collection.php b/lib/Doctrine/Collection.php index f2657bf61..610d5e025 100644 --- a/lib/Doctrine/Collection.php +++ b/lib/Doctrine/Collection.php @@ -142,6 +142,7 @@ public function setData(array $data) $this->data = $data; } + /** * This method is automatically called when this Doctrine_Collection is serialized * @@ -197,7 +198,6 @@ public function __unserialize($data) $manager = Doctrine_Manager::getInstance(); $connection = $manager->getCurrentConnection(); - foreach ($data as $name => $values) { $this->$name = $values; } @@ -810,12 +810,11 @@ public function toHierarchy() /** * Populate a Doctrine_Collection from an array of data * - * @param string $array + * @param array $array * @return void */ public function fromArray($array, $deep = true) { - $data = array(); foreach ($array as $rowKey => $row) { $this[$rowKey]->fromArray($row, $deep); } diff --git a/lib/Doctrine/Collection/Iterator/Expandable.php b/lib/Doctrine/Collection/Iterator/Expandable.php index 7c18c5c58..3bfab7dd5 100644 --- a/lib/Doctrine/Collection/Iterator/Expandable.php +++ b/lib/Doctrine/Collection/Iterator/Expandable.php @@ -32,6 +32,7 @@ */ class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterator { + #[\ReturnTypeWillChange] public function valid() { if ($this->index < $this->count) { diff --git a/lib/Doctrine/Collection/Iterator/Normal.php b/lib/Doctrine/Collection/Iterator/Normal.php index 540bdad63..c256bd6fb 100644 --- a/lib/Doctrine/Collection/Iterator/Normal.php +++ b/lib/Doctrine/Collection/Iterator/Normal.php @@ -35,6 +35,7 @@ class Doctrine_Collection_Iterator_Normal extends Doctrine_Collection_Iterator /** * @return boolean whether or not the iteration will continue */ + #[\ReturnTypeWillChange] public function valid() { return ($this->index < $this->count); diff --git a/lib/Doctrine/Collection/Iterator/Offset.php b/lib/Doctrine/Collection/Iterator/Offset.php index 181b73f21..128b1ef10 100644 --- a/lib/Doctrine/Collection/Iterator/Offset.php +++ b/lib/Doctrine/Collection/Iterator/Offset.php @@ -32,6 +32,7 @@ */ class Doctrine_Collection_Iterator_Offset extends Doctrine_Collection_Iterator { + #[\ReturnTypeWillChange] public function valid() { } } \ No newline at end of file diff --git a/lib/Doctrine/Column.php b/lib/Doctrine/Column.php index 18e081c33..fafb97adb 100644 --- a/lib/Doctrine/Column.php +++ b/lib/Doctrine/Column.php @@ -146,6 +146,7 @@ public function enumIndex($field, $value) * * @return integer */ + #[\ReturnTypeWillChange] public function count() { return count($this->_definition); @@ -156,6 +157,7 @@ public function count() * * @return ArrayIterator */ + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_definition); diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index c05e2061e..73a7e5fa7 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -188,6 +188,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun */ protected $_tableCache; protected $_tableCacheTTL; + protected $exported; /** * the constructor @@ -1608,6 +1609,7 @@ public function __toString() return Doctrine_Lib::getConnectionAsString($this); } + /** * Serialize. Remove database connection(pdo) since it cannot be serialized * diff --git a/lib/Doctrine/Connection/Common.php b/lib/Doctrine/Connection/Common.php index 1f1aa21b6..36f7e286c 100644 --- a/lib/Doctrine/Connection/Common.php +++ b/lib/Doctrine/Connection/Common.php @@ -38,12 +38,13 @@ class Doctrine_Connection_Common extends Doctrine_Connection * @param string $query * @param mixed $limit * @param mixed $offset + * @return string */ public function modifyLimitQuery($query, $limit = false,$offset = false,$isManip=false) { $limit = (int) $limit; $offset = (int) $offset; - + if ($limit && $offset) { $query .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; } elseif ($limit && ! $offset) { @@ -54,4 +55,4 @@ public function modifyLimitQuery($query, $limit = false,$offset = false,$isManip return $query; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Core.php b/lib/Doctrine/Core.php index 1487ad782..8662d3284 100644 --- a/lib/Doctrine/Core.php +++ b/lib/Doctrine/Core.php @@ -564,7 +564,7 @@ public static function setPath($path) public static function getPath() { if ( ! self::$_path) { - self::$_path = realpath(__DIR__ . '/..'); + self::$_path = dirname(__DIR__); } return self::$_path; diff --git a/lib/Doctrine/Export/Reporter.php b/lib/Doctrine/Export/Reporter.php index fb3c43a96..742f39fac 100644 --- a/lib/Doctrine/Export/Reporter.php +++ b/lib/Doctrine/Export/Reporter.php @@ -44,6 +44,7 @@ public function pop() return array_pop($this->messages); } + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->messages); diff --git a/lib/Doctrine/Hydrator.php b/lib/Doctrine/Hydrator.php index 05ab94599..129743e32 100644 --- a/lib/Doctrine/Hydrator.php +++ b/lib/Doctrine/Hydrator.php @@ -51,7 +51,7 @@ public function __construct() /** * Set the hydration mode * - * @param mixed $hydrationMode One of the Doctrine_Core::HYDRATE_* constants or + * @param mixed $hydrationMode One of the Doctrine_Core::HYDRATE_* constants or * a string representing the name of the hydration mode or * or an instance of the hydration class */ @@ -112,9 +112,9 @@ public function getHydratorDriverClassName($mode = null) /** * Get an instance of the hydration driver for the passed hydration mode * - * @param string $mode - * @param array $tableAliases - * @return object Doctrine_Hydrator_Abstract + * @param string $mode + * @param array $tableAliases + * @return Doctrine_Hydrator_Abstract */ public function getHydratorDriver($mode, $tableAliases) { @@ -138,8 +138,8 @@ public function getHydratorDriver($mode, $tableAliases) * Hydrate the query statement in to its final data structure by one of the * hydration drivers. * - * @param object $stmt - * @param array $tableAliases + * @param object $stmt + * @param array $tableAliases * @return mixed $result */ public function hydrateResultSet($stmt, $tableAliases) @@ -149,4 +149,4 @@ public function hydrateResultSet($stmt, $tableAliases) return $result; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/Abstract.php b/lib/Doctrine/Hydrator/Abstract.php index a603e5fd7..3a4dc7dc4 100644 --- a/lib/Doctrine/Hydrator/Abstract.php +++ b/lib/Doctrine/Hydrator/Abstract.php @@ -97,11 +97,11 @@ public function onDemandReset() * (I.e. ORACLE limit/offset emulation adds doctrine_rownum to the result set). * * @param string $name - * @return boolean + * @return bool */ protected function _isIgnoredName($name) { - return $name == 'DOCTRINE_ROWNUM'; + return $name === 'DOCTRINE_ROWNUM'; } /** @@ -114,8 +114,7 @@ protected function _isIgnoredName($name) * The key idea is the loop over the rowset only once doing all the needed operations * within this massive loop. * - * @param mixed $stmt * @return mixed */ abstract public function hydrateResultSet($stmt); -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/ArrayHierarchyDriver.php b/lib/Doctrine/Hydrator/ArrayHierarchyDriver.php index ae281eb47..731ad0090 100644 --- a/lib/Doctrine/Hydrator/ArrayHierarchyDriver.php +++ b/lib/Doctrine/Hydrator/ArrayHierarchyDriver.php @@ -32,6 +32,9 @@ */ class Doctrine_Hydrator_ArrayHierarchyDriver extends Doctrine_Hydrator_ArrayDriver { + /** + * @return array + */ public function hydrateResultSet($stmt) { $collection = parent::hydrateResultSet($stmt); @@ -80,4 +83,4 @@ public function hydrateResultSet($stmt) } return $trees; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/ArrayShallowDriver.php b/lib/Doctrine/Hydrator/ArrayShallowDriver.php index cad4a3424..b595122b6 100644 --- a/lib/Doctrine/Hydrator/ArrayShallowDriver.php +++ b/lib/Doctrine/Hydrator/ArrayShallowDriver.php @@ -32,6 +32,9 @@ */ class Doctrine_Hydrator_ArrayShallowDriver extends Doctrine_Hydrator_ScalarDriver { + /** + * @return array + */ public function hydrateResultSet($stmt) { $cache = array(); @@ -41,4 +44,4 @@ public function hydrateResultSet($stmt) } return $result; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/Graph.php b/lib/Doctrine/Hydrator/Graph.php index 1284fe88b..01921a4ef 100644 --- a/lib/Doctrine/Hydrator/Graph.php +++ b/lib/Doctrine/Hydrator/Graph.php @@ -35,7 +35,9 @@ */ abstract class Doctrine_Hydrator_Graph extends Doctrine_Hydrator_Abstract { - protected $_tables = array(); + protected + $_tables = array(), + $_rootAlias = null; /** * Gets the custom field used for indexing for the specified component alias. @@ -48,6 +50,9 @@ protected function _getCustomIndexField($alias) return isset($this->_queryComponents[$alias]['map']) ? $this->_queryComponents[$alias]['map'] : null; } + /** + * @return Doctrine_Collection|mixed + */ public function hydrateResultSet($stmt) { // Used variables during hydration @@ -306,11 +311,17 @@ protected function _gatherRowData(&$data, &$cache, &$id, &$nonemptyComponents) $table = $this->_queryComponents[$cache[$key]['dqlAlias']]['table']; $fieldName = $table->getFieldName($last); $cache[$key]['fieldName'] = $fieldName; + + if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg_field'][$last])) { + $fieldName = $this->_queryComponents[$cache[$key]['dqlAlias']]['agg_field'][$last]; + } + if ($table->isIdentifier($fieldName)) { $cache[$key]['isIdentifier'] = true; } else { $cache[$key]['isIdentifier'] = false; } + $type = $table->getTypeOfColumn($last); if ($type == 'integer' || $type == 'string') { $cache[$key]['isSimpleType'] = true; diff --git a/lib/Doctrine/Hydrator/NoneDriver.php b/lib/Doctrine/Hydrator/NoneDriver.php index d4ed09dd7..6da15a6d6 100644 --- a/lib/Doctrine/Hydrator/NoneDriver.php +++ b/lib/Doctrine/Hydrator/NoneDriver.php @@ -33,8 +33,11 @@ */ class Doctrine_Hydrator_NoneDriver extends Doctrine_Hydrator_Abstract { + /** + * @return mixed + */ public function hydrateResultSet($stmt) { return $stmt->fetchAll(PDO::FETCH_NUM); } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/RecordDriver.php b/lib/Doctrine/Hydrator/RecordDriver.php index b4944428b..a028645d4 100644 --- a/lib/Doctrine/Hydrator/RecordDriver.php +++ b/lib/Doctrine/Hydrator/RecordDriver.php @@ -118,7 +118,7 @@ public function flush() $coll->takeSnapshot(); } $this->_initializedRelations = null; - $this->_collections = null; + $this->_collections = array(); $this->_tables = null; } } \ No newline at end of file diff --git a/lib/Doctrine/Hydrator/RecordHierarchyDriver.php b/lib/Doctrine/Hydrator/RecordHierarchyDriver.php index f32055d0f..28c54e20e 100644 --- a/lib/Doctrine/Hydrator/RecordHierarchyDriver.php +++ b/lib/Doctrine/Hydrator/RecordHierarchyDriver.php @@ -32,8 +32,11 @@ */ class Doctrine_Hydrator_RecordHierarchyDriver extends Doctrine_Hydrator_RecordDriver { + /** + * @return Doctrine_Collection + */ public function hydrateResultSet($stmt) { return parent::hydrateResultSet($stmt)->toHierarchy(); } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/ScalarDriver.php b/lib/Doctrine/Hydrator/ScalarDriver.php index 894ff3f50..d3ce87e66 100644 --- a/lib/Doctrine/Hydrator/ScalarDriver.php +++ b/lib/Doctrine/Hydrator/ScalarDriver.php @@ -32,6 +32,9 @@ */ class Doctrine_Hydrator_ScalarDriver extends Doctrine_Hydrator_Abstract { + /** + * @return array + */ public function hydrateResultSet($stmt) { $cache = array(); @@ -55,7 +58,7 @@ protected function _gatherRowData($data, &$cache, $aliasPrefix = true) } // cache general information like the column name <-> field name mapping $e = explode('__', $key); - $columnName = strtolower(array_pop($e)); + $columnName = strtolower(array_pop($e)); $cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))]; $table = $this->_queryComponents[$cache[$key]['dqlAlias']]['table']; // check whether it's an aggregate value or a regular field @@ -84,7 +87,7 @@ protected function _gatherRowData($data, &$cache, $aliasPrefix = true) $fieldName = $cache[$key]['fieldName']; $rowDataKey = $aliasPrefix ? $dqlAlias . '_' . $fieldName:$fieldName; - + if ($cache[$key]['isSimpleType'] || $cache[$key]['isAgg']) { $rowData[$rowDataKey] = $value; } else { @@ -94,4 +97,4 @@ protected function _gatherRowData($data, &$cache, $aliasPrefix = true) } return $rowData; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/SingleScalarDriver.php b/lib/Doctrine/Hydrator/SingleScalarDriver.php index ebcad6230..bf7589522 100644 --- a/lib/Doctrine/Hydrator/SingleScalarDriver.php +++ b/lib/Doctrine/Hydrator/SingleScalarDriver.php @@ -32,6 +32,10 @@ */ class Doctrine_Hydrator_SingleScalarDriver extends Doctrine_Hydrator_Abstract { + /** + * @param mixed $stmt + * @return array|mixed + */ public function hydrateResultSet($stmt) { $result = array(); @@ -44,4 +48,4 @@ public function hydrateResultSet($stmt) return $result; } } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Import/Builder.php b/lib/Doctrine/Import/Builder.php index 1ab6ec3c7..eafabaa1c 100644 --- a/lib/Doctrine/Import/Builder.php +++ b/lib/Doctrine/Import/Builder.php @@ -36,6 +36,7 @@ * @author Nicolas Bérard-Nault * @author Jonathan H. Wage */ +#[\AllowDynamicProperties] class Doctrine_Import_Builder extends Doctrine_Builder { /** @@ -178,6 +179,25 @@ class Doctrine_Import_Builder extends Doctrine_Builder */ protected $_phpDocEmail = '##EMAIL##'; + + /** + * Contains the actAs columns after running buildSetUp + * + * @var array + */ + private $actAsColumns = array(); + /** * _tpl * @@ -395,9 +415,7 @@ public function buildTableDefinition(array $definition) /** * buildSetUp * - * @param array $options - * @param array $columns - * @param array $relations + * @param array $definition * @return string */ public function buildSetUp(array $definition) @@ -782,7 +800,7 @@ public function buildPhpDocs(array $definition) if (isset($definition['relations']) && ! empty($definition['relations'])) { foreach ($definition['relations'] as $relation) { $type = (isset($relation['type']) && $relation['type'] == Doctrine_Relation::MANY) ? 'Doctrine_Collection' : $this->_classPrefix . $relation['class']; - if ($relation["type"] == Doctrine_Relation::ONE) { + if ((isset($relation['type']) ? $relation['type'] : null) == Doctrine_Relation::ONE) { $properties[] = array($relation['class'], $relation['alias'], ""); $getters[] = array($relation['class'], $relation['alias'], ""); $setters[] = array($definition['topLevelClassName'], $relation['alias'], $relation['class'], ""); @@ -856,21 +874,33 @@ public function buildPhpDocs(array $definition) return $ret; } + /** + * find class matching $name + * + * @param $name + * @return class-string + */ + private function findTemplateClassMatchingName($name) + { + $classname = $name; + if (class_exists("Doctrine_Template_$name", true)) { + $classname = "Doctrine_Template_$name"; + } + + return $classname; + } + /** * emit a behavior assign * * @param int $level * @param string $name * @param string $option + * @param class-string $classname * @return string assignation code */ - private function emitAssign($level, $name, $option) + private function emitAssign($level, $name, $option, $classname) { - // find class matching $name - $classname = $name; - if (class_exists("Doctrine_Template_$name", true)) { - $classname = "Doctrine_Template_$name"; - } return " \$" . strtolower($name) . "$level = new $classname($option);". PHP_EOL; } @@ -942,6 +972,7 @@ private function innerBuildActAs($actAs, $level = 0, $parent = null, array &$emi $currentParent = $parent; if (is_array($actAs)) { foreach ($actAs as $template => $options) { + $className = $this->findTemplateClassMatchingName($template); if ($template == 'actAs') { // found another actAs $build .= $this->innerBuildActAs($options, $level + 1, $parent, $emittedActAs); @@ -958,7 +989,8 @@ private function innerBuildActAs($actAs, $level = 0, $parent = null, array &$emi } $optionPHP = $this->varExport($realOptions); - $build .= $this->emitAssign($level, $template, $optionPHP); + $build .= $this->emitAssign($level, $template, $optionPHP, $className); + $this->determineActAsColumns($className, $realOptions); if ($level == 0) { $emittedActAs[] = $this->emitActAs($level, $template); } else { @@ -968,7 +1000,8 @@ private function innerBuildActAs($actAs, $level = 0, $parent = null, array &$emi $parent = $template; $build .= $this->innerBuildActAs($leftActAs, $level, $template, $emittedActAs); } else { - $build .= $this->emitAssign($level, $template, null); + $build .= $this->emitAssign($level, $template, null, $className); + $this->determineActAsColumns($className, array($options)); if ($level == 0) { $emittedActAs[] = $this->emitActAs($level, $template); } else { @@ -978,7 +1011,9 @@ private function innerBuildActAs($actAs, $level = 0, $parent = null, array &$emi } } } else { - $build .= $this->emitAssign($level, $actAs, null); + $className = $this->findTemplateClassMatchingName($actAs); + $build .= $this->emitAssign($level, $actAs, null, $className); + $this->determineActAsColumns($className, array()); if ($level == 0) { $emittedActAs[] = $this->emitActAs($level, $actAs); } else { @@ -989,6 +1024,87 @@ private function innerBuildActAs($actAs, $level = 0, $parent = null, array &$emi return $build; } + /** + * Adds the columns of the used actAs behaviors to the comment block. + * + * @param class-string $className + * @param array $instanceOptions + * + * @throws Doctrine_Import_Builder_Exception + */ + private function determineActAsColumns($className, $instanceOptions) + { + // No class specified or class does not exist. + if (!$className || !class_exists($className)) { + return; + } + + // PHP >= 7.4 is planned as a minimum version for the upcoming release of doctrine1, + // therefore we simply skip the generation of actAs columns if run below 7.0, as + // instantiation exceptions are not supported before PHP 7 + if (PHP_VERSION_ID <= 70000) { + return; + } + + try { + $actAsInstance = new $className($instanceOptions); + } catch (Error $e) { + // The class can't be instantiated, skipping it + return; + } + + if (!$actAsInstance || !method_exists($actAsInstance, 'getOptions')) { + return; + } + + $options = $actAsInstance->getOptions(); + + // Some behaviors do not contain an array of columns, e.g. SoftDelete. + if (!is_array(reset($options))) { + $options = array($options); + } + + foreach ($options as $name => $column) { + if (!is_array($column) || !array_key_exists('name', $column) || !array_key_exists('type', $column)) { + // 'name' or 'type' not found. + continue; + } + + if (array_key_exists('disabled', $column) && $column['disabled']) { + // Column has been disabled. + continue; + } + + // Add field, if it does not exist already. + if (array_key_exists($name, $this->actAsColumns)) { + continue; + } + + $this->actAsColumns[$name] = $column; + } + } + + private function mergeDefinitionAndActAsColumns(array $definitionColumns, array $actAsColumns) + { + $result = $definitionColumns; + + foreach ($actAsColumns as $actAsOptionName => $actAsColumn) { + $actAsColumnName = isset($actAsColumn['name']) ? $actAsColumn['name'] : $actAsOptionName; + + foreach ($result as $optionName => $column) { + $name = isset($column['name']) ? $column['name'] : $optionName; + if ($name === $actAsColumnName) { + continue 2; + } + } + + $result[$actAsOptionName] = $actAsColumn; + } + + return $result; + } + + /** * Build php code for adding record listeners * @@ -1121,6 +1237,8 @@ public function buildDefinition(array $definition) $className = $definition['className']; $extends = isset($definition['inheritance']['extends']) ? $definition['inheritance']['extends']:$this->_baseClassName; + // Clear actAsColumns + $this->actAsColumns = array(); if ( ! (isset($definition['no_definition']) && $definition['no_definition'] === true)) { $tableDefinitionCode = $this->buildTableDefinition($definition); $setUpCode = $this->buildSetUp($definition); @@ -1135,6 +1253,7 @@ public function buildDefinition(array $definition) $setUpCode.= $this->buildToString($definition); + $definition['columns'] = $this->mergeDefinitionAndActAsColumns($definition['columns'], $this->actAsColumns); $docs = PHP_EOL . $this->buildPhpDocs($definition); $content = sprintf(self::$_tpl, $docs, $abstract, @@ -1428,7 +1547,7 @@ public function writeDefinition(array $definition) $code .= "Doctrine_Manager::getInstance()->bindComponent('" . $definition['connectionClassName'] . "', '" . $definition['connection'] . "');" . PHP_EOL; } - $code .= PHP_EOL . $definitionCode; + $code .= PHP_EOL . $definitionCode . PHP_EOL; if ($this->_eolStyle) { $code = str_replace(PHP_EOL, $this->_eolStyle, $code); diff --git a/lib/Doctrine/Locator.php b/lib/Doctrine/Locator.php index 70d1998d6..8b4d2817f 100644 --- a/lib/Doctrine/Locator.php +++ b/lib/Doctrine/Locator.php @@ -178,6 +178,7 @@ public function locate($name) * @see Countable interface * @return integer the number of resources */ + #[\ReturnTypeWillChange] public function count() { return count($this->_resources); @@ -191,6 +192,7 @@ public function count() * @return ArrayIterator an iterator for iterating through * all bound resources */ + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_resources); diff --git a/lib/Doctrine/Locator/Injectable.php b/lib/Doctrine/Locator/Injectable.php index 884042dcd..b32ccf404 100644 --- a/lib/Doctrine/Locator/Injectable.php +++ b/lib/Doctrine/Locator/Injectable.php @@ -66,7 +66,7 @@ public function setLocator(Doctrine_Locator $locator) /** * getLocator * returns the locator associated with this object - * + * * if there are no locator locally associated then * this method tries to fetch the current global locator * @@ -101,7 +101,7 @@ public function locate($name) } else { // get the name of the concrete implementation $concreteImpl = $this->_resources[$name]; - + return $this->getLocator()->locate($concreteImpl); } } else { @@ -115,13 +115,13 @@ public function locate($name) * * @param string $name the name of the resource to bind * @param mixed $value the value of the resource - * @return Doctrine_Locator this object + * @return static this object */ - public function bind($name, $resource) + public function bind($name, $value) { - $this->_resources[$name] = $resource; - - return $this; + $this->_resources[$name] = $value; + + return $this; } /** @@ -146,4 +146,4 @@ public static function getNullObject() { return self::$_null; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index fe7560b4c..a2b08944d 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -411,6 +411,10 @@ protected function _buildDsnPartsArray($dsn) // silence any warnings $parts = @parse_url($dsn); + if ($parts === false) { + $parts = array(); + } + $names = array('dsn', 'scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment'); foreach ($names as $name) { diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index bd1093e76..2724cea31 100755 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -160,11 +160,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable */ protected $_parsers = array(); - /** - * @var array $_pendingJoinConditions an array containing pending joins - */ - protected $_pendingJoinConditions = array(); - /** * @var array */ @@ -485,7 +480,7 @@ public function processPendingFields($componentAlias) } $sql = array(); - foreach ($fields as $fieldAlias => $fieldName) { + foreach ($fields as $fieldName) { $columnName = $table->getColumnName($fieldName); if (($owner = $table->getColumnOwner($columnName)) !== null && $owner !== $table->getComponentName()) { @@ -497,17 +492,10 @@ public function processPendingFields($componentAlias) . ' AS ' . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); } else { - // Fix for http://www.doctrine-project.org/jira/browse/DC-585 - // Take the field alias if available - if (isset($this->_aggregateAliasMap[$fieldAlias])) { - $aliasSql = $this->_aggregateAliasMap[$fieldAlias]; - } else { - $columnName = $table->getColumnName($fieldName); - $aliasSql = $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); - } + $columnName = $table->getColumnName($fieldName); $sql[] = $this->_conn->quoteIdentifier($tableAlias) . '.' . $this->_conn->quoteIdentifier($columnName) . ' AS ' - . $aliasSql; + . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); } } @@ -660,14 +648,11 @@ public function parseSelect($dql) $this->_queryComponents[$componentAlias]['agg'][$index] = $alias; - $this->_neededTables[] = $tableAlias; - - // Fix for http://www.doctrine-project.org/jira/browse/DC-585 - // Add selected columns to pending fields if (preg_match('/^([^\(]+)\.(\'?)(.*?)(\'?)$/', $expression, $field)) { - $this->_pendingFields[$componentAlias][$alias] = $field[3]; + $this->_queryComponents[$componentAlias]['agg_field'][$index] = $field[3]; } + $this->_neededTables[] = $tableAlias; } else { $e = explode('.', $terms[0]); diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index 5fef51a3c..821de85ad 100755 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -218,6 +218,16 @@ abstract class Doctrine_Query_Abstract * * map the name of the column / aggregate value this * component is mapped to a collection + * + * agg_field the field names for each aggregates + * Example: + * DQL: COMPONENT.FIELD as ALIAS + * SQL: TABLE.COLUMN as TABLE__0 + * $_queryComponents + * agg: + * 0: ALIAS + * agg_field: + * 0: FIELD */ protected $_queryComponents = array(); @@ -279,6 +289,11 @@ abstract class Doctrine_Query_Abstract */ protected $_preQueried = false; + /** + * @var array $_pendingJoinConditions an array containing pending joins + */ + protected $_pendingJoinConditions = array(); + /** * Fix for http://www.doctrine-project.org/jira/browse/DC-701 * @@ -1334,6 +1349,9 @@ protected function _constructQueryFromCache($cached) if (isset($components['agg'])) { $queryComponents[$alias]['agg'] = $components['agg']; } + if (isset($components['agg_field'])) { + $queryComponents[$alias]['agg_field'] = $components['agg_field']; + } if (isset($components['map'])) { $queryComponents[$alias]['map'] = $components['map']; } @@ -1364,6 +1382,9 @@ public function getCachedForm($customComponent = null) if (isset($components['agg'])) { $componentInfo[$alias]['agg'] = $components['agg']; } + if (isset($components['agg_field'])) { + $componentInfo[$alias]['agg_field'] = $components['agg_field']; + } if (isset($components['map'])) { $componentInfo[$alias]['map'] = $components['map']; } diff --git a/lib/Doctrine/RawSql.php b/lib/Doctrine/RawSql.php index 10f844f3c..82810d38d 100755 --- a/lib/Doctrine/RawSql.php +++ b/lib/Doctrine/RawSql.php @@ -59,7 +59,7 @@ function __construct(Doctrine_Connection $connection = null, Doctrine_Hydrator_A protected function clear() { - $this->_preQuery = false; + $this->_preQueried = false; $this->_pendingJoinConditions = array(); } diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index dc2316a25..ba1cbbc96 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -151,7 +151,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count * @var string */ protected $_pendingDeletes = []; - + /** * Array of pending un links in format alias => keys to be executed after save * @@ -259,7 +259,7 @@ public function __construct($table = null, $isNewEntry = false) } $repository = $this->_table->getRepository(); - + // Fix for #1682 and #1841. // Doctrine_Table does not have the repository yet during dummy record creation. if ($repository) { @@ -399,9 +399,9 @@ public function isValid($deep = false, $hooks = true) $event = new Doctrine_Event($this, Doctrine_Event::RECORD_VALIDATE); $this->preValidate($event); $this->getTable()->getRecordListener()->preValidate($event); - + if ( ! $event->skipOperation) { - + $validator = new Doctrine_Validator(); $validator->validateRecord($this); $this->validate(); @@ -553,7 +553,7 @@ public function postInsert($event) /** * Empty template method to provide concrete Record classes with the possibility - * to hook into the validation procedure. Useful for cleaning up data before + * to hook into the validation procedure. Useful for cleaning up data before * validating it. */ public function preValidate($event) @@ -587,14 +587,14 @@ public function preDqlDelete($event) { } /** - * Empty template method to provide Record classes with the ability to alter hydration + * Empty template method to provide Record classes with the ability to alter hydration * before it runs */ public function preHydrate($event) { } /** - * Empty template method to provide Record classes with the ability to alter hydration + * Empty template method to provide Record classes with the ability to alter hydration * after it runs */ public function postHydrate($event) @@ -633,7 +633,7 @@ public function getErrorStack() if ( ! $this->_errorStack) { $this->_errorStack = new Doctrine_Validator_ErrorStack(get_class($this)); } - + return $this->_errorStack; } @@ -944,7 +944,7 @@ public function state($state = null) if ($state == null) { return $this->_state; } - + $err = false; if (is_integer($state)) { if ($state >= 1 && $state <= 7) { @@ -1090,7 +1090,7 @@ public function clearRelated($name = null) * in order to check. If the reference didn't already exist and it doesn't * exist in the database, the related reference will be cleared immediately. * - * @param string $name + * @param string $name * @return boolean Whether or not the related relationship exists */ public function relatedExists($name) @@ -1170,18 +1170,18 @@ public function load(array $data = array()) // only load the data from database if the Doctrine_Record is in proxy state if ($this->exists() && $this->isInProxyState()) { $id = $this->identifier(); - + if ( ! is_array($id)) { $id = array($id); } - + if (empty($id)) { return false; } $table = $this->getTable(); $data = empty($data) ? $table->find($id, Doctrine_Core::HYDRATE_ARRAY) : $data; - + if (is_array($data)) { foreach ($data as $field => $value) { if ($table->hasField($field) && ( ! array_key_exists($field, $this->_data) || $this->_data[$field] === self::$_null)) { @@ -1189,19 +1189,19 @@ public function load(array $data = array()) } } } - + if ($this->isModified()) { $this->_state = Doctrine_Record::STATE_DIRTY; } else if (!$this->isInProxyState()) { $this->_state = Doctrine_Record::STATE_CLEAN; } - + return true; } - + return false; } - + /** * indicates whether record has any not loaded fields * @@ -1225,8 +1225,8 @@ public function isInProxyState() * sets a fieldname to have a custom accessor or check if a field has a custom * accessor defined (when called without $accessor parameter). * - * @param string $fieldName - * @param string $accessor + * @param string $fieldName + * @param string $accessor * @return boolean */ public function hasAccessor($fieldName, $accessor = null) @@ -1242,7 +1242,7 @@ public function hasAccessor($fieldName, $accessor = null) /** * clears the accessor for a field name * - * @param string $fieldName + * @param string $fieldName * @return void */ public function clearAccessor($fieldName) @@ -1254,7 +1254,7 @@ public function clearAccessor($fieldName) /** * gets the custom accessor for a field name * - * @param string $fieldName + * @param string $fieldName * @return string $accessor */ public function getAccessor($fieldName) @@ -1280,8 +1280,8 @@ public function getAccessors() * sets a fieldname to have a custom mutator or check if a field has a custom * mutator defined (when called without the $mutator parameter) * - * @param string $fieldName - * @param string $mutator + * @param string $fieldName + * @param string $mutator * @return boolean */ public function hasMutator($fieldName, $mutator = null) @@ -1297,7 +1297,7 @@ public function hasMutator($fieldName, $mutator = null) /** * gets the custom mutator for a field name * - * @param string $fieldname + * @param string $fieldname * @return string */ public function getMutator($fieldName) @@ -1311,7 +1311,7 @@ public function getMutator($fieldName) /** * clears the custom mutator for a field name * - * @param string $fieldName + * @param string $fieldName * @return void */ public function clearMutator($fieldName) @@ -1357,7 +1357,7 @@ public function get($fieldName, $load = true) if ($this->_table->getAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE) || $this->hasAccessor($fieldName)) { $componentName = $this->_table->getComponentName(); - $accessor = $this->hasAccessor($fieldName) + $accessor = $this->hasAccessor($fieldName) ? $this->getAccessor($fieldName) : 'get' . Doctrine_Inflector::classify($fieldName); @@ -1388,10 +1388,10 @@ protected function _get($fieldName, $load = true) } else { $value = $this->_data[$fieldName]; } - + return $value; } - + try { if ( ! isset($this->_references[$fieldName])) { if ($load) { @@ -1494,10 +1494,10 @@ protected function _set($fieldName, $value, $load = true) } else { $old = $this->_data[$fieldName]; } - + if ($this->_isValueModified($type, $old, $value)) { if ($value === null) { - $value = $this->_table->getDefaultValueOf($fieldName); + $value = $this->_table->getDefaultValueOf($fieldName); } $this->_data[$fieldName] = $value; $this->_modified[] = $fieldName; @@ -1558,7 +1558,7 @@ protected function _isValueModified($type, $old, $new) if ($type == 'boolean' && (is_bool($old) || is_numeric($old)) && (is_bool($new) || is_numeric($new)) && $old == $new) { return false; - } else if (in_array($type, array('decimal', 'float')) && is_numeric($old) && is_numeric($new)) { + } else if (in_array($type, array('decimal', 'float', 'double')) && is_numeric($old) && is_numeric($new)) { return $old * 100 != $new * 100; } else if (in_array($type, array('integer', 'int')) && is_numeric($old) && is_numeric($new)) { return $old != $new; @@ -1578,7 +1578,7 @@ protected function _isValueModified($type, $old, $new) /** * Places a related component in the object graph. * - * This method inserts a related component instance in this record + * This method inserts a related component instance in this record * relations, populating the foreign keys accordingly. * * @param string $name related component alias in the relation @@ -1588,11 +1588,11 @@ protected function _isValueModified($type, $old, $new) public function coreSetRelated($name, $value) { $rel = $this->_table->getRelation($name); - + if ($value === null) { $value = self::$_null; } - + // one-to-many or one-to-one relation if ($rel instanceof Doctrine_Relation_ForeignKey || $rel instanceof Doctrine_Relation_LocalKey) { if ( ! $rel->isOneToOne()) { @@ -1782,7 +1782,7 @@ public function replace(Doctrine_Connection $conn = null) /** * retrieves an array of modified fields and associated new values. - * + * * @param boolean $old pick the old values (instead of the new ones) * @param boolean $last pick only lastModified values (@see getLastModified()) * @return array $a @@ -1794,8 +1794,8 @@ public function getModified($old = false, $last = false) $modified = $last ? $this->_lastModified:$this->_modified; foreach ($modified as $fieldName) { if ($old) { - $a[$fieldName] = isset($this->_oldValues[$fieldName]) - ? $this->_oldValues[$fieldName] + $a[$fieldName] = isset($this->_oldValues[$fieldName]) + ? $this->_oldValues[$fieldName] : $this->getTable()->getDefaultValueOf($fieldName); } else { $a[$fieldName] = $this->_data[$fieldName]; @@ -1819,7 +1819,7 @@ public function getLastModified($old = false) * Retrieves data prepared for a sql transaction. * * Returns an array of modified fields and values with data preparation; - * adds column aggregation inheritance and converts Records into primary + * adds column aggregation inheritance and converts Records into primary * key values. * * @param array $array @@ -1914,10 +1914,10 @@ public function toArray($deep = true, $prefixKey = false) if ($this->_state == self::STATE_LOCKED || $this->_state == self::STATE_TLOCKED) { return false; } - + $stateBeforeLock = $this->_state; $this->_state = $this->exists() ? self::STATE_LOCKED : self::STATE_TLOCKED; - + $a = array(); foreach ($this as $column => $value) { @@ -2635,8 +2635,8 @@ public function linkInDb($alias, $ids) } /** - * Reset the modified array and store the old array in lastModified so it - * can be accessed by users after saving a record, since the modified array + * Reset the modified array and store the old array in lastModified so it + * can be accessed by users after saving a record, since the modified array * is reset after the object is saved. * * @return void @@ -2689,7 +2689,7 @@ public function deleteNode() { $this->getNode()->delete(); } - + /** * Helps freeing the memory occupied by the entity. * Cuts all references the entity has to other entities and removes the entity diff --git a/lib/Doctrine/Record/Filter/Compound.php b/lib/Doctrine/Record/Filter/Compound.php index 6c26f1c6d..0fe769bc0 100644 --- a/lib/Doctrine/Record/Filter/Compound.php +++ b/lib/Doctrine/Record/Filter/Compound.php @@ -59,62 +59,61 @@ public function init() /** * Provides a way for setting property or relation value to the given record. * - * @param string $property_or_relation + * @param string $propertyOrRelation * * @return Doctrine_Record the given record * * @thrown Doctrine_Record_UnknownPropertyException when this way is not available */ - public function filterSet(Doctrine_Record $record, $property_or_relation, $value) + public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value) { foreach ($this->_aliases as $alias) { // The relationship must be fetched in order to check the field existence. // Related to PHP-7.0 compatibility so an explicit call to method get is required. $record[$alias]; - if (!$record->exists()) { - if (isset($record[$alias][$property_or_relation])) { - $record[$alias][$property_or_relation] = $value; + if ( ! $record->exists()) { + if (isset($record[$alias][$propertyOrRelation])) { + $record[$alias][$propertyOrRelation] = $value; return $record; } } else { - if (isset($record[$alias][$property_or_relation])) { - $record[$alias][$property_or_relation] = $value; + if (isset($record[$alias][$propertyOrRelation])) { + $record[$alias][$propertyOrRelation] = $value; } return $record; } } - throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $property_or_relation, get_class($record))); + throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record))); } /** * Provides a way for getting property or relation value from the given record. * - * @param string $property_or_relation + * @param string $propertyOrRelation * * @return mixed * * @thrown Doctrine_Record_UnknownPropertyException when this way is not available */ - public function filterGet(Doctrine_Record $record, $property_or_relation) + public function filterGet(Doctrine_Record $record, $propertyOrRelation) { foreach ($this->_aliases as $alias) { // The relationship must be fetched in order to check the field existence. // Related to PHP-7.0 compatibility so an explicit call to method get is required. $record[$alias]; - if (!$record->exists()) { - if (isset($record[$alias][$property_or_relation])) { - return $record[$alias][$property_or_relation]; + if ( ! $record->exists()) { + if (isset($record[$alias][$propertyOrRelation])) { } } else { - if (isset($record[$alias][$property_or_relation])) { - return $record[$alias][$property_or_relation]; + if (isset($record[$alias][$propertyOrRelation])) { + return $record[$alias][$propertyOrRelation]; } } } - throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $property_or_relation, get_class($record))); + throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record))); } } diff --git a/lib/Doctrine/Record/Filter/Standard.php b/lib/Doctrine/Record/Filter/Standard.php index f16d73e9f..f2a665358 100644 --- a/lib/Doctrine/Record/Filter/Standard.php +++ b/lib/Doctrine/Record/Filter/Standard.php @@ -34,22 +34,22 @@ class Doctrine_Record_Filter_Standard extends Doctrine_Record_Filter { /** - * @param string $property_or_relation + * @param string $propertyOrRelation * * @thrown Doctrine_Record_UnknownPropertyException */ - public function filterSet(Doctrine_Record $record, $property_or_relation, $value) + public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value) { - throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $property_or_relation, get_class($record))); + throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record))); } /** - * @param string $property_or_relation + * @param string $propertyOrRelation * * @thrown Doctrine_Record_UnknownPropertyException */ - public function filterGet(Doctrine_Record $record, $property_or_relation) + public function filterGet(Doctrine_Record $record, $propertyOrRelation) { - throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $property_or_relation, get_class($record))); + throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record))); } } diff --git a/lib/Doctrine/Relation.php b/lib/Doctrine/Relation.php index df83c3aa5..cbdcb6ff2 100644 --- a/lib/Doctrine/Relation.php +++ b/lib/Doctrine/Relation.php @@ -41,12 +41,12 @@ abstract class Doctrine_Relation implements ArrayAccess * constant for ONE_TO_ONE and MANY_TO_ONE relationships */ const ONE = 0; - + /** * constant for MANY_TO_MANY and ONE_TO_MANY relationships */ const MANY = 1; - + // TRUE => mandatory, everything else is just a default value. this should be refactored // since TRUE can bot be used as a default value this way. All values should be default values. /** @@ -93,10 +93,10 @@ abstract class Doctrine_Relation implements ArrayAccess * refTable the reference table object (if any) * * onDelete referential delete action - * + * * onUpdate referential update action * - * deferred deferred constraint checking + * deferred deferred constraint checking * * alias relation alias * @@ -114,10 +114,10 @@ abstract class Doctrine_Relation implements ArrayAccess * in the parent table or in the child table. * * SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the - * child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier + * child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier * specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported. * - * NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary + * NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary * key value is not allowed to proceed if there is a related foreign key value in the referenced table. * * RESTRICT: Rejects the delete or update operation for the parent table. NO ACTION and RESTRICT are the same as @@ -135,7 +135,7 @@ public function __construct(array $definition) if (isset($definition[$key])) { $def[$key] = $definition[$key]; } else { - $def[$key] = $this->definition[$key]; + $def[$key] = $this->definition[$key]; } } $this->definition = $def; @@ -169,22 +169,31 @@ public function isEqual() return $this->definition['equal']; } + /** + * @return bool + */ #[\ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->definition[$offset]); } + /** + * @return mixed + */ #[\ReturnTypeWillChange] public function offsetGet($offset) { if (isset($this->definition[$offset])) { return $this->definition[$offset]; } - + return null; } + /** + * @return void + */ #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { @@ -193,6 +202,9 @@ public function offsetSet($offset, $value) } } + /** + * @return void + */ #[\ReturnTypeWillChange] public function offsetUnset($offset) { @@ -204,7 +216,7 @@ public function offsetUnset($offset) * * @return array */ - public function toArray() + public function toArray() { return $this->definition; } @@ -231,7 +243,7 @@ final public function getType() { return $this->definition['type']; } - + /** * Checks whether this relation cascades deletions to the related objects * on the application level. @@ -277,7 +289,7 @@ final public function getLocal() { return $this->definition['local']; } - + /** * getLocalFieldName * returns the field name of the local column @@ -309,7 +321,7 @@ final public function getForeign() { return $this->definition['foreign']; } - + /** * getLocalFieldName * returns the field name of the foreign column diff --git a/lib/Doctrine/Sequence/Mssql.php b/lib/Doctrine/Sequence/Mssql.php index 5b786560a..fff760886 100644 --- a/lib/Doctrine/Sequence/Mssql.php +++ b/lib/Doctrine/Sequence/Mssql.php @@ -32,6 +32,8 @@ */ class Doctrine_Sequence_Mssql extends Doctrine_Sequence { + protected $warnings; + /** * Returns the next free id of a sequence * diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index c289b29ba..eb9454647 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -963,7 +963,7 @@ public function bind($args, $type) * @param string $componentName the name of the related component * @param string $options relation options * @see Doctrine_Relation::_$definition - * @return Doctrine_Record this object + * @return void */ public function hasOne() { @@ -976,7 +976,7 @@ public function hasOne() * @param string $componentName the name of the related component * @param string $options relation options * @see Doctrine_Relation::_$definition - * @return Doctrine_Record this object + * @return void */ public function hasMany() { @@ -992,7 +992,7 @@ public function hasMany() * side. * * @param string $alias the relation alias to search for. - * @return boolean true if the relation exists. Otherwise false. + * @return bool true if the relation exists. Otherwise false. */ public function hasRelation($alias) { @@ -1180,7 +1180,7 @@ public function getColumnName($fieldName) } if (is_null($fieldName)) { - return; + return ''; } return strtolower($fieldName); @@ -1708,7 +1708,7 @@ public function findByDql($dql, $params = array(), $hydrationMode = null) * Find records basing on a field. * * @param string $column field for the WHERE clause - * @param string $value prepared statement parameter + * @param string|array $value prepared statement parameter * @param int $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD * @return Doctrine_Collection|array */ @@ -1723,7 +1723,7 @@ public function findBy($fieldName, $value, $hydrationMode = null) * Finds the first record that satisfy the clause. * * @param string $column field for the WHERE clause - * @param string $value prepared statement parameter + * @param string|array $value prepared statement parameter * @param int $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD * @return Doctrine_Record */ diff --git a/lib/Doctrine/Table/Repository/None.php b/lib/Doctrine/Table/Repository/None.php index da421ec74..fe651cae6 100644 --- a/lib/Doctrine/Table/Repository/None.php +++ b/lib/Doctrine/Table/Repository/None.php @@ -62,6 +62,7 @@ public function get($oid) * * @return integer the number of records this registry has */ + #[\ReturnTypeWillChange] public function count() { return 0; diff --git a/lib/Doctrine/Task/BuildAll.php b/lib/Doctrine/Task/BuildAll.php index 2d5a4bb9d..07d07e216 100644 --- a/lib/Doctrine/Task/BuildAll.php +++ b/lib/Doctrine/Task/BuildAll.php @@ -37,6 +37,7 @@ class Doctrine_Task_BuildAll extends Doctrine_Task $optionalArguments = array(); protected $models, + $createDb, $tables; public function __construct($dispatcher = null) diff --git a/lib/Doctrine/Task/BuildAllLoad.php b/lib/Doctrine/Task/BuildAllLoad.php index 6b6d2fc5a..90e685a01 100644 --- a/lib/Doctrine/Task/BuildAllLoad.php +++ b/lib/Doctrine/Task/BuildAllLoad.php @@ -35,6 +35,9 @@ class Doctrine_Task_BuildAllLoad extends Doctrine_Task public $description = 'Calls build-all, and load-data', $requiredArguments = array(), $optionalArguments = array(); + + protected $buildAll, + $loadData; public function __construct($dispatcher = null) { diff --git a/lib/Doctrine/Task/BuildAllReload.php b/lib/Doctrine/Task/BuildAllReload.php index f06475cf2..1cd3c1aba 100644 --- a/lib/Doctrine/Task/BuildAllReload.php +++ b/lib/Doctrine/Task/BuildAllReload.php @@ -35,6 +35,9 @@ class Doctrine_Task_BuildAllReload extends Doctrine_Task public $description = 'Calls rebuild-db and load-data', $requiredArguments = array(), $optionalArguments = array(); + + protected $rebuildDb, + $loadData; public function __construct($dispatcher = null) { diff --git a/lib/Doctrine/Task/RebuildDb.php b/lib/Doctrine/Task/RebuildDb.php index 4a3e66581..ad9623f6d 100644 --- a/lib/Doctrine/Task/RebuildDb.php +++ b/lib/Doctrine/Task/RebuildDb.php @@ -35,6 +35,10 @@ class Doctrine_Task_RebuildDb extends Doctrine_Task public $description = 'Drops and re-creates databases', $requiredArguments = array(), $optionalArguments = array(); + + protected $dropDb, + $createDb, + $createTables; public function __construct($dispatcher = null) { diff --git a/lib/Doctrine/Transaction/Mysql.php b/lib/Doctrine/Transaction/Mysql.php index 412e729a8..eb097ca03 100644 --- a/lib/Doctrine/Transaction/Mysql.php +++ b/lib/Doctrine/Transaction/Mysql.php @@ -113,4 +113,28 @@ public function getIsolation() { return $this->conn->fetchOne('SELECT @@tx_isolation'); } -} \ No newline at end of file + + /** + * Performs the rollback. + */ + protected function _doRollback() + { + $this->conn->getDbh()->exec('ROLLBACK'); + } + + /** + * Performs the commit. + */ + protected function _doCommit() + { + $this->conn->getDbh()->exec('COMMIT'); + } + + /** + * Begins a database transaction. + */ + protected function _doBeginTransaction() + { + $this->conn->getDbh()->exec('START TRANSACTION'); + } +} diff --git a/package.xml b/package.xml deleted file mode 100644 index 056831624..000000000 --- a/package.xml +++ /dev/null @@ -1,1625 +0,0 @@ - - - Doctrine - pear.doctrine-project.org - PHP5 Database ORM - Doctrine is an ORM (object relational mapper) for PHP 5.2.x+ that sits on top of -a powerful DBAL (database abstraction layer). One of its key features is the -ability to optionally write database queries in an OO (object oriented) -SQL-dialect called DQL inspired by Hibernates HQL. This provides developers with -a powerful alternative to SQL that maintains a maximum of flexibility without -requiring needless code duplication. - - Konsta Vesterinen - zYne- - kvesteri@cc.hut.fi - yes - - - Jonathan H. Wage - jwage - jonwage@gmail.com - yes - - 2010-03-29 - - - 1.2.2 - 1.2.2 - - - stable - stable - - LGPL license - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5.2.3 - - - 1.4.0b1 - - - PEAR - pear.php.net - 1.3.6 - - - pdo - - - - - pdo_dblib - - - pdo_mysql - - - pdo_odbc - - - pdo_sqlite - - - pdo_oci - - - pdo_pgsql - - - - - - - - 1.2.2 - 1.2.2 - - - stable - stable - - 2010-03-29 - LGPL license - -- - - - - - 1.2.1 - 1.2.1 - - - stable - stable - - 2009-12-07 - LGPL license - -- - - - - - 1.2.0 - 1.2.0 - - - stable - stable - - 2009-11-30 - LGPL license - -- - - - - - 1.1.2 - 1.1.2 - - - stable - stable - - 2009-06-15 - LGPL license - -- - - - - - 1.1.1 - 1.1.1 - - - stable - stable - - 2009-05-11 - LGPL license - -- - - - - - 1.1.0 - 1.1.0 - - - stable - stable - - 2009-03-16 - LGPL license - -- - - - - - 1.0.2 - 1.0.2 - - - stable - stable - - 2008-09-11 - LGPL license - -- - - - - - 1.0.1 - 1.0.1 - - - stable - stable - - 2008-09-09 - LGPL license - -- - - - - - 1.0.0 - 1.0.0 - - - stable - stable - - 2008-09-01 - LGPL license - -- - - - - - 0.11.0 - 0.11.0 - - - stable - stable - - 2008-06-23 - LGPL license - -- - - - - - 0.10.4 - 0.10.4 - - - beta - beta - - 2008-03-28 - LGPL license - -- - - - - - 0.10.3 - 0.10.3 - - - beta - beta - - 2008-03-18 - LGPL license - -- - - - - - 0.10.2 - 0.10.2 - - - beta - beta - - 2008-03-01 - LGPL license - -- - - - - - 0.10.1 - 0.10.1 - - - beta - beta - - 2008-02-29 - LGPL license - -- - - - - - 0.10.0 - 0.10.0 - - - beta - beta - - 2008-02-13 - LGPL license - -- - - - - - 0.9 - 0.9 - - - beta - beta - - 2008-02-06 - MIT license - -barfoo - - - - diff --git a/tests/Cache/DbTestCase.php b/tests/Cache/DbTestCase.php index 91dc4563a..594103662 100644 --- a/tests/Cache/DbTestCase.php +++ b/tests/Cache/DbTestCase.php @@ -33,6 +33,8 @@ */ class Doctrine_Cache_Db_TestCase extends Doctrine_Cache_Abstract_TestCase { + protected $cache; + public function setUp() { parent::setUp(); diff --git a/tests/CliTestCase/cli-default.php b/tests/CliTestCase/cli-default.php index 95218bd6f..e293915a0 100644 --- a/tests/CliTestCase/cli-default.php +++ b/tests/CliTestCase/cli-default.php @@ -5,10 +5,10 @@ * @author Dan Bettles */ -require_once(dirname(dirname(__DIR__)) . '/lib/Doctrine/Core.php'); +require_once dirname(__DIR__, 2) . '/lib/Doctrine/Core.php'; spl_autoload_register(array('Doctrine_Core', 'autoload')); -require_once(__DIR__ . '/TestTask02.php'); +require_once __DIR__ . '/TestTask02.php'; $cli = new Doctrine_Cli(); $cli->run($_SERVER['argv']); diff --git a/tests/CliTestCase/cli-with-custom-tasks.php b/tests/CliTestCase/cli-with-custom-tasks.php index f4e3666f7..590835a70 100644 --- a/tests/CliTestCase/cli-with-custom-tasks.php +++ b/tests/CliTestCase/cli-with-custom-tasks.php @@ -5,12 +5,12 @@ * @author Dan Bettles */ -require_once(dirname(dirname(__DIR__)) . '/lib/Doctrine/Core.php'); +require_once dirname(__DIR__, 2) . '/lib/Doctrine/Core.php'; spl_autoload_register(array('Doctrine_Core', 'autoload')); $cli = new Doctrine_Cli(); -require_once(__DIR__ . '/TestTask02.php'); +require_once __DIR__ . '/TestTask02.php'; //Either...: $cli->registerTaskClass('Doctrine_Cli_TestCase_TestTask02'); diff --git a/tests/CliTestCase/cli-without-autoregistered-custom-tasks.php b/tests/CliTestCase/cli-without-autoregistered-custom-tasks.php index 35908f4bf..403005e8c 100644 --- a/tests/CliTestCase/cli-without-autoregistered-custom-tasks.php +++ b/tests/CliTestCase/cli-without-autoregistered-custom-tasks.php @@ -5,10 +5,10 @@ * @author Dan Bettles */ -require_once(dirname(dirname(__DIR__)) . '/lib/Doctrine/Core.php'); +require_once dirname(__DIR__, 2) . '/lib/Doctrine/Core.php'; spl_autoload_register(array('Doctrine_Core', 'autoload')); -require_once(__DIR__ . '/TestTask02.php'); +require_once __DIR__ . '/TestTask02.php'; $cli = new Doctrine_Cli(array('autoregister_custom_tasks' => false)); $cli->run($_SERVER['argv']); diff --git a/tests/Connection/CustomTestCase.php b/tests/Connection/CustomTestCase.php index 815599ed9..6fd75b448 100644 --- a/tests/Connection/CustomTestCase.php +++ b/tests/Connection/CustomTestCase.php @@ -32,6 +32,9 @@ */ class Doctrine_Connection_Custom_TestCase extends Doctrine_UnitTestCase { + protected $_conn; + protected $_dbh; + public function setUp() { $manager = Doctrine_Manager::getInstance(); diff --git a/tests/DoctrineTest/Doctrine_UnitTestCase.php b/tests/DoctrineTest/Doctrine_UnitTestCase.php index 4883d28d7..a1f0fb2f7 100644 --- a/tests/DoctrineTest/Doctrine_UnitTestCase.php +++ b/tests/DoctrineTest/Doctrine_UnitTestCase.php @@ -53,7 +53,11 @@ class Doctrine_UnitTestCase extends UnitTestCase protected $dataDict; protected $transaction; protected $_name; - + protected $query; + protected $profiler; + protected $import; + protected $sequence; + protected $exc; protected $init = false; diff --git a/tests/DoctrineTest/GroupTest.php b/tests/DoctrineTest/GroupTest.php index 5e826c048..b17f5e37e 100644 --- a/tests/DoctrineTest/GroupTest.php +++ b/tests/DoctrineTest/GroupTest.php @@ -6,6 +6,8 @@ class GroupTest extends UnitTestCase protected $_title; protected $_onlyRunFailed = false; + protected $_formatter; + public function __construct($title, $name) { $this->_title = $title; diff --git a/tests/Export/PgsqlTestCase.php b/tests/Export/PgsqlTestCase.php index ed86437f9..d2a393fea 100644 --- a/tests/Export/PgsqlTestCase.php +++ b/tests/Export/PgsqlTestCase.php @@ -175,4 +175,4 @@ public function testAlterTableSqlIdentifierQuoting() 1 => 'ALTER TABLE "mytable" DROP "oldfield"' )); } -} \ No newline at end of file +} diff --git a/tests/Export/RecordTestCase.php b/tests/Export/RecordTestCase.php index 7da241740..95b7783b4 100644 --- a/tests/Export/RecordTestCase.php +++ b/tests/Export/RecordTestCase.php @@ -96,12 +96,12 @@ public function testExportSupportsForeignKeysForManyToManyRelations() public function testExportModelFromDirectory() { - - Doctrine_Core::createTablesFromModels(__DIR__ . DIRECTORY_SEPARATOR .'..' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'export'); + Doctrine_Core::createTablesFromModels(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'export'); + $this->assertEqual($this->adapter->pop(), 'COMMIT'); $this->assertEqual($this->adapter->pop(), 'ALTER TABLE cms__category_languages ADD CONSTRAINT cms__category_languages_category_id_cms__category_id FOREIGN KEY (category_id) REFERENCES cms__category(id) ON DELETE CASCADE'); $this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category_languages (id BIGINT AUTO_INCREMENT, name TEXT, category_id BIGINT, language_id BIGINT, INDEX index_category_idx (category_id), INDEX index_language_idx (language_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB'); - $this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category (id BIGINT AUTO_INCREMENT, created DATETIME, parent BIGINT, position MEDIUMINT, active BIGINT, INDEX index_parent_idx (parent), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB'); + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category (id BIGINT AUTO_INCREMENT, created DATETIME, parent BIGINT, position MEDIUMINT, active BIGINT, INDEX index_parent_idx (parent), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB'); $this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION'); } diff --git a/tests/Import/BuilderTestCase.php b/tests/Import/BuilderTestCase.php index 930c856da..84f0804c5 100644 --- a/tests/Import/BuilderTestCase.php +++ b/tests/Import/BuilderTestCase.php @@ -122,4 +122,4 @@ public function testBaseTableClass() $class = $builder->buildTableClassDefinition('MyTestTable', array('className' => 'MyTest')); $this->assertTrue(strpos($class, 'class MyTestTable extends MyBaseTable')); } -} \ No newline at end of file +} diff --git a/tests/Import/PluginHierarchyTestCase.php b/tests/Import/PluginHierarchyTestCase.php index 6e14c73dd..26df10f42 100644 --- a/tests/Import/PluginHierarchyTestCase.php +++ b/tests/Import/PluginHierarchyTestCase.php @@ -83,4 +83,4 @@ public function testImportOfHieriarchyOfPluginGeneration() Doctrine_Lib::removeDirectories($path); unlink('wiki.yml'); } -} \ No newline at end of file +} diff --git a/tests/Import/SchemaTestCase.php b/tests/Import/SchemaTestCase.php index 7c7c1a5f6..c47a30358 100644 --- a/tests/Import/SchemaTestCase.php +++ b/tests/Import/SchemaTestCase.php @@ -110,4 +110,4 @@ protected function _verifyMultiDirectionalRelationship($class, $relationAlias, $ return false; } } -} \ No newline at end of file +} diff --git a/tests/ManagerTestCase.php b/tests/ManagerTestCase.php index 780926147..752ce6a3f 100644 --- a/tests/ManagerTestCase.php +++ b/tests/ManagerTestCase.php @@ -32,6 +32,12 @@ */ class Doctrine_Manager_TestCase extends Doctrine_UnitTestCase { + protected $conn1_database; + protected $conn2_database; + + protected $conn1; + protected $conn2; + public function testGetInstance() { $this->assertTrue(Doctrine_Manager::getInstance() instanceOf Doctrine_Manager); } diff --git a/tests/Migration/DiffTestCase.php b/tests/Migration/DiffTestCase.php index 0885b3b5b..7f6eb78d8 100644 --- a/tests/Migration/DiffTestCase.php +++ b/tests/Migration/DiffTestCase.php @@ -76,4 +76,4 @@ public function testTest() Doctrine_Lib::removeDirectories($migrationsPath); } -} \ No newline at end of file +} diff --git a/tests/QueryTestCase.php b/tests/QueryTestCase.php index 7c48a32c9..bf349c31b 100644 --- a/tests/QueryTestCase.php +++ b/tests/QueryTestCase.php @@ -307,11 +307,11 @@ public function testParseTableAliasesWithBetweenInWhereClause() $q1 = Doctrine_Query::create() ->select('u.id') ->from('QueryTest_User u') - ->where("CURRENT_DATE() BETWEEN u.QueryTest_Subscription.begin AND u.QueryTest_Subscription.begin") + ->where("now() BETWEEN u.QueryTest_Subscription.begin AND u.QueryTest_Subscription.begin") ->addWhere( 'u.id != 5' ) ; - $expected = 'SELECT q.id AS q__id FROM query_test__user q LEFT JOIN query_test__subscription q2 ON q.subscriptionid = q2.id WHERE (CURRENT_DATE() BETWEEN q2.begin AND q2.begin AND q.id != 5)'; + $expected = 'SELECT q.id AS q__id FROM query_test__user q LEFT JOIN query_test__subscription q2 ON q.subscriptionid = q2.id WHERE (datetime(\'now\') BETWEEN q2.begin AND q2.begin AND q.id != 5)'; $this->assertEqual( $q1->getSqlQuery(), $expected ); diff --git a/tests/Record/FromArrayTestCase.php b/tests/Record/FromArrayTestCase.php index bf0617dae..ee6922545 100755 --- a/tests/Record/FromArrayTestCase.php +++ b/tests/Record/FromArrayTestCase.php @@ -32,6 +32,8 @@ */ class Doctrine_Record_FromArray_TestCase extends Doctrine_UnitTestCase { + protected $previous_group; + public function prepareTables() { parent::prepareTables(); diff --git a/tests/Record/SynchronizeTestCase.php b/tests/Record/SynchronizeTestCase.php index 67027c15a..76457457b 100644 --- a/tests/Record/SynchronizeTestCase.php +++ b/tests/Record/SynchronizeTestCase.php @@ -32,6 +32,8 @@ */ class Doctrine_Record_Synchronize_TestCase extends Doctrine_UnitTestCase { + private $previous_group; + public function prepareTables() { parent::prepareTables(); diff --git a/tests/RecordTestCase.php b/tests/RecordTestCase.php index b0b06efb5..dc818570b 100644 --- a/tests/RecordTestCase.php +++ b/tests/RecordTestCase.php @@ -41,6 +41,7 @@ public function prepareTables() $this->tables[] = 'Book'; $this->tables[] = 'EntityAddress'; $this->tables[] = 'UnderscoreColumn'; + $this->tables[] = 'Location2'; parent::prepareTables(); } @@ -1022,4 +1023,15 @@ public function testDeleteReturnBooleanAndThrowsException() $this->fail(); } } + + public function testDoubleIsModified() + { + $location = new Location2(); + $location->lat = '12.345'; + + $location->save(); + $location->lat = 12.345; + + $this->assertFalse($location->isModified()); + } } diff --git a/tests/Search/FileTestCase.php b/tests/Search/FileTestCase.php index aa5c1de1f..849626d6f 100644 --- a/tests/Search/FileTestCase.php +++ b/tests/Search/FileTestCase.php @@ -32,6 +32,8 @@ */ class Doctrine_Search_File_TestCase extends Doctrine_UnitTestCase { + protected $_search; + public function prepareData() { } public function prepareTables() diff --git a/tests/SearchTestCase.php b/tests/SearchTestCase.php index c73245565..7a291b7b3 100644 --- a/tests/SearchTestCase.php +++ b/tests/SearchTestCase.php @@ -229,7 +229,7 @@ public function testUtf8AnalyzerKnowsToHandleOtherEncodingsWorks() $analyzer = new Doctrine_Search_Analyzer_Utf8(); // convert our test string to iso8859-15 - $iso = iconv('UTF-8','ISO8859-15', 'un éléphant ça trompe énormément'); + $iso = mb_convert_encoding('un éléphant ça trompe énormément', 'ISO-8859-15', 'UTF-8'); $words = $analyzer->analyze($iso, 'ISO8859-15'); $this->assertEqual($words[1], 'éléphant'); diff --git a/tests/TableTestCase.php b/tests/TableTestCase.php index 793e9672e..3de7b5ce9 100644 --- a/tests/TableTestCase.php +++ b/tests/TableTestCase.php @@ -153,9 +153,9 @@ public function testGetData() public function testSetSequenceName() { - $this->objTable->sequenceName = 'test-seq'; + $this->objTable->setOption('sequenceName', 'test-seq'); $this->assertEqual($this->objTable->sequenceName, 'test-seq'); - $this->objTable->sequenceName = null; + $this->objTable->setOption('sequenceName', null); } public function testCreate() diff --git a/tests/Ticket/1106TestCase.php b/tests/Ticket/1106TestCase.php index 7468852f4..8bc5d6f8d 100644 --- a/tests/Ticket/1106TestCase.php +++ b/tests/Ticket/1106TestCase.php @@ -32,6 +32,8 @@ */ class Doctrine_Ticket_1106_TestCase extends Doctrine_UnitTestCase { + protected $user_id; + public function prepareTables() { parent::prepareTables(); diff --git a/tests/Ticket/1131TestCase.php b/tests/Ticket/1131TestCase.php index 2a90ebcb3..9291329d2 100644 --- a/tests/Ticket/1131TestCase.php +++ b/tests/Ticket/1131TestCase.php @@ -32,6 +32,8 @@ */ class Doctrine_Ticket_1131_TestCase extends Doctrine_UnitTestCase { + private $role_one, $role_two; + public function prepareTables() { //$this->tables = array(); diff --git a/tests/Ticket/1325TestCase.php b/tests/Ticket/1325TestCase.php index d1847e46e..2b230a269 100644 --- a/tests/Ticket/1325TestCase.php +++ b/tests/Ticket/1325TestCase.php @@ -41,6 +41,8 @@ public function prepareTables() public function testShouldInsertWithoutAlias() { + $now = time(); + $elem = new Ticket_1325_TableName_NoAlias(); $elem->id = 1; $elem->save(); @@ -49,13 +51,14 @@ public function testShouldInsertWithoutAlias() ->from('Ticket_1325_TableName_NoAlias') ->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY); - $now = time(); $time = strtotime($res['event_date']); $this->assertTrue(($now + 5 >= $time) && ($time >= $now)); } public function testShouldInsertWithAlias() { + $now = time(); + $elem = new Ticket_1325_TableName_Aliased(); $elem->id = 1; $elem->save(); @@ -64,9 +67,8 @@ public function testShouldInsertWithAlias() ->from('Ticket_1325_TableName_Aliased') ->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY); - $now = time(); $time = strtotime($res['eventDate']); - $this->assertTrue(strtotime($res['eventDate']) > 0); + $this->assertTrue(($now + 5 >= $time) && ($time >= $now)); } } diff --git a/tests/Ticket/1436TestCase.php b/tests/Ticket/1436TestCase.php index db30bd4b7..43ce87771 100644 --- a/tests/Ticket/1436TestCase.php +++ b/tests/Ticket/1436TestCase.php @@ -32,6 +32,10 @@ */ class Doctrine_Ticket_1436_TestCase extends Doctrine_UnitTestCase { + protected $group_one; + protected $group_two; + protected $group_three; + public function prepareTables() { parent::prepareTables(); diff --git a/tests/Ticket/1527TestCase.php b/tests/Ticket/1527TestCase.php index 13717c51a..2935039a2 100644 --- a/tests/Ticket/1527TestCase.php +++ b/tests/Ticket/1527TestCase.php @@ -50,12 +50,12 @@ public function testTest() $schema = $import->buildSchema($yml, 'yml'); $this->assertEqual($schema['Ticket_1527_User']['columns']['username']['extra']['test'], '123'); - $path = __DIR__ . '/../tmp'; + $path = dirname(__DIR__) . '/tmp'; $import->importSchema($yml, 'yml', $path); - + require_once($path . '/generated/BaseTicket_1527_User.php'); require_once($path . '/Ticket_1527_User.php'); $username = Doctrine_Core::getTable('Ticket_1527_User')->getDefinitionOf('username'); $this->assertEqual($username['extra']['test'], '123'); } -} \ No newline at end of file +} diff --git a/tests/Ticket/1727TestCase.php b/tests/Ticket/1727TestCase.php index ff99c735c..5be1f3de1 100644 --- a/tests/Ticket/1727TestCase.php +++ b/tests/Ticket/1727TestCase.php @@ -66,4 +66,4 @@ public function testTest() $models2 = Doctrine_Core::loadModels(array(__DIR__ . '/1727/models1', __DIR__ . '/1727/models2'), Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); } -} \ No newline at end of file +} diff --git a/tests/Ticket/1992TestCase.php b/tests/Ticket/1992TestCase.php index 7da049494..c7691df8f 100644 --- a/tests/Ticket/1992TestCase.php +++ b/tests/Ticket/1992TestCase.php @@ -32,6 +32,10 @@ */ class Doctrine_Ticket_1992_TestCase extends Doctrine_UnitTestCase { + protected $person; + protected $profile1; + protected $profile2; + public function prepareTables() { $this->tables[] = 'Ticket_1992_Person'; diff --git a/tests/Ticket/2158TestCase.php b/tests/Ticket/2158TestCase.php index 7531719c9..02d40cdd0 100644 --- a/tests/Ticket/2158TestCase.php +++ b/tests/Ticket/2158TestCase.php @@ -2,6 +2,8 @@ class Doctrine_Ticket_2158_TestCase extends Doctrine_UnitTestCase { + protected $myModel; + public function prepareTables() { $this->tables[] = "T2158_Model1"; diff --git a/tests/Ticket/2355TestCase.php b/tests/Ticket/2355TestCase.php index 47c7616b1..c661703ca 100644 --- a/tests/Ticket/2355TestCase.php +++ b/tests/Ticket/2355TestCase.php @@ -32,6 +32,12 @@ */ class Doctrine_Ticket_2355_TestCase extends Doctrine_UnitTestCase { + public function setUp() + { + Doctrine_Manager::getInstance()->reset(); + parent::setUp(); + } + public function prepareTables() { $this->tables[] = 'News'; diff --git a/tests/Ticket/2375TestCase.php b/tests/Ticket/2375TestCase.php index 6d57a83f9..0eb85c36c 100644 --- a/tests/Ticket/2375TestCase.php +++ b/tests/Ticket/2375TestCase.php @@ -96,4 +96,4 @@ public function testTest() $this->assertEqual($loadedModels['Ticket_2375_Model5'], $models2Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model5.php'); $this->assertEqual($loadedModels['Ticket_2375_Model6'], $models2Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model5.php'); } -} \ No newline at end of file +} diff --git a/tests/Ticket/585TestCase.php b/tests/Ticket/585TestCase.php new file mode 100644 index 000000000..9c2ed8f5c --- /dev/null +++ b/tests/Ticket/585TestCase.php @@ -0,0 +1,70 @@ +. + */ + +class Doctrine_Ticket_585_TestCase extends Doctrine_UnitTestCase +{ + private function doTestWithAllColumnsAliased($hydrateType, $expectedKeys) + { + try { + $query = Doctrine_Query::create() + ->select('u.id as aliasId, u.name as aliasName') + ->from('User u') + ->leftJoin('u.Email e') + ; + + $results = $query->execute(array(), $hydrateType); + + $expectedSql = 'SELECT e.id AS e__0, e.name AS e__1 FROM entity e LEFT JOIN email e2 ON e.email_id = e2.id WHERE (e.type = 0)'; + + $this->assertEqual($expectedSql, $query->getSqlQuery()); + $this->assertEqual($expectedKeys, array_keys($results[0])); + $this->assertEqual(count($this->users), count($results)); + + $this->pass(); + } catch (Exception $e) { + $this->fail($e->getMessage()); + } + } + + public function test_hydrateScalar_withAllColumnsAliased_thenResultsHasAllRecords() + { + $hydrateType = Doctrine_Core::HYDRATE_SCALAR; + $expectedKeys = array('u_aliasId', 'u_aliasName'); + + $this->doTestWithAllColumnsAliased($hydrateType, $expectedKeys); + } + + public function test_hydrateArrayShallow_withAllColumnsAliased_thenResultsHasAllRecords() + { + $hydrateType = Doctrine_Core::HYDRATE_ARRAY_SHALLOW; + $expectedKeys = array('aliasId', 'aliasName'); + + $this->doTestWithAllColumnsAliased($hydrateType, $expectedKeys); + } + + public function test_hydrateArray_withAllColumnsAliased_thenResultsHasAllRecords() + { + $hydrateType = Doctrine_Core::HYDRATE_ARRAY; + $expectedKeys = array('aliasId', 'aliasName'); + + $this->doTestWithAllColumnsAliased($hydrateType, $expectedKeys); + } +} diff --git a/tests/Ticket/982TestCase.php b/tests/Ticket/982TestCase.php index 781b305a1..d541ccd11 100644 --- a/tests/Ticket/982TestCase.php +++ b/tests/Ticket/982TestCase.php @@ -3,7 +3,10 @@ * Test to ensure LocalKey Relations allow 0 for id value */ class Doctrine_Ticket_982_TestCase extends Doctrine_UnitTestCase -{ +{ + protected $myModelOne; + protected $myModelTwo; + public function prepareTables() { $this->tables = array(); diff --git a/tests/Ticket/DC221TestCase.php b/tests/Ticket/DC221TestCase.php index 161ffe38f..0ce9074cd 100644 --- a/tests/Ticket/DC221TestCase.php +++ b/tests/Ticket/DC221TestCase.php @@ -38,4 +38,4 @@ public function testTest() $migration2 = new Doctrine_Migration(__DIR__ . '/DC221'); $this->assertEqual($migration1->getMigrationClasses(), $migration2->getMigrationClasses()); } -} \ No newline at end of file +} diff --git a/tests/Ticket/DC292TestCase.php b/tests/Ticket/DC292TestCase.php index 32627b5ea..73822f1c3 100644 --- a/tests/Ticket/DC292TestCase.php +++ b/tests/Ticket/DC292TestCase.php @@ -45,4 +45,4 @@ public function testTest() $this->assertTrue(isset($changes['created_columns']['article']['created_at'])); $this->assertTrue(isset($changes['created_columns']['article']['updated_at'])); } -} \ No newline at end of file +} diff --git a/tests/Ticket/DC95TestCase.php b/tests/Ticket/DC95TestCase.php index 7744fb1c4..f09d31f2d 100644 --- a/tests/Ticket/DC95TestCase.php +++ b/tests/Ticket/DC95TestCase.php @@ -65,4 +65,4 @@ public function testClassExistsAfterImport() Doctrine_Core::setModelsDirectory(null); Doctrine_Lib::removeDirectories(__DIR__ . '/DC95/models'); } -} \ No newline at end of file +} diff --git a/tests/Ticket/gh110/Ticket_gh110_TestRecord.snapshot b/tests/Ticket/gh110/Ticket_gh110_TestRecord.snapshot new file mode 100644 index 000000000..a6b440b47 --- /dev/null +++ b/tests/Ticket/gh110/Ticket_gh110_TestRecord.snapshot @@ -0,0 +1,66 @@ +/** + * Ticket_gh110_TestRecord + * + * This class has been auto-generated by the Doctrine ORM Framework + * + * @property int $id Type: integer(4) + * @property my_custom_type $created_at Type: my_custom_type + * @property string $deleted_at Type: timestamp, Timestamp in ISO-8601 format (YYYY-MM-DD HH:MI:SS) + * + * @method int getId() Type: integer(4) + * @method my_custom_type getCreatedAt() Type: my_custom_type + * @method string getDeletedAt() Type: timestamp, Timestamp in ISO-8601 format (YYYY-MM-DD HH:MI:SS) + * + * @method Ticket_gh110_TestRecord setId(int $val) Type: integer(4) + * @method Ticket_gh110_TestRecord setCreatedAt(my_custom_type $val) Type: my_custom_type + * @method Ticket_gh110_TestRecord setDeletedAt(string $val) Type: timestamp, Timestamp in ISO-8601 format (YYYY-MM-DD HH:MI:SS) + * + * @package ##PACKAGE## + * @subpackage ##SUBPACKAGE## + * @author ##NAME## <##EMAIL##> + * @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $ + */ +class Ticket_gh110_TestRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('id', 'integer', 4, array( + 'type' => 'integer', + 'length' => 4, + )); + $this->hasColumn('created_at', 'my_custom_type', null, array( + 'type' => 'my_custom_type', + 'length' => '', + )); + } + + public function setUp() + { + parent::setUp(); + $softdelete0 = new Doctrine_Template_SoftDelete(array( + )); + $timestampable0 = new Doctrine_Template_Timestampable(array( + 'updated' => + array( + 'disabled' => true, + ), + 'unknown_column' => + array( + ), + )); + $unknownactas0 = new UnknownActAs(array( + )); + $gh110_template0 = new Doctrine_Template_gh110_Template(array( + )); + $gh110_invalid_template0 = new gh110_Invalid_Template(array( + )); + $gh110_abstract_template0 = new gh110_Abstract_Template(array( + )); + $this->actAs($softdelete0); + $this->actAs($timestampable0); + $this->actAs($unknownactas0); + $this->actAs($gh110_template0); + $this->actAs($gh110_invalid_template0); + $this->actAs($gh110_abstract_template0); + } +} \ No newline at end of file diff --git a/tests/Ticket/gh110TestCase.php b/tests/Ticket/gh110TestCase.php new file mode 100644 index 000000000..f140d88ed --- /dev/null +++ b/tests/Ticket/gh110TestCase.php @@ -0,0 +1,81 @@ +buildDefinition( + array( + 'className' => 'Ticket_gh110_TestRecord', + 'topLevelClassName' => 'Ticket_gh110_TestRecord', + 'is_base_class' => true, + 'columns' => array( + 'id' => array( + 'type' => 'integer', + 'length' => 4, + ), + 'my_custom_created_at' => array( + 'name' => 'created_at', + 'type' => 'my_custom_type', + 'length' => '', + ) + ), + 'actAs' => array( + 'SoftDelete' => array(), + 'Timestampable' => array( + 'updated' => array( + 'disabled' => true, + ), + 'unknown_column' => array() + ), + 'UnknownActAs' => array(), + // This template brings an already defined column + 'gh110_Template' => array(), + 'gh110_Invalid_Template' => array(), + 'gh110_Abstract_Template' => array(), + ) + ) + ); + + // Can be used to update the snapshot. + //file_put_contents(__DIR__ . '/gh110/Ticket_gh110_TestRecord.snapshot', $class); + $this->assertEqual($class, file_get_contents(__DIR__ . '/gh110/Ticket_gh110_TestRecord.snapshot')); + } +} + +abstract class gh110_Abstract_Template {} + +/** This is just a simple class without the required getOptions()-Method */ +class gh110_Invalid_Template {} + +class Doctrine_Template_gh110_Template extends Doctrine_Template +{ + protected $_options = array( + 'created' => array( + 'name' => 'created_at', + 'alias' => null, + 'type' => 'timestamp', + 'format' => 'Y-m-d H:i:s', + 'disabled' => false, + 'expression' => false, + 'options' => array('notnull' => true) + ) + ); + + /** + * Set table definition for Timestampable behavior + * + * @return void + */ + public function setTableDefinition() + { + if ( ! $this->_options['created']['disabled']) { + $name = $this->_options['created']['name']; + if ($this->_options['created']['alias']) { + $name .= ' as ' . $this->_options['created']['alias']; + } + $this->hasColumn($name, $this->_options['created']['type'], null, $this->_options['created']['options']); + } + } +} diff --git a/tests/models/Location2.php b/tests/models/Location2.php new file mode 100644 index 000000000..80ad551cf --- /dev/null +++ b/tests/models/Location2.php @@ -0,0 +1,10 @@ +hasColumn('id', 'integer', 10, array('primary' => true)); + $this->hasColumn('lat', 'double', 10); + $this->hasColumn('lon', 'double', 10); + } +} diff --git a/tests/run.php b/tests/run.php index 538c7b4d1..d1dd2c7ee 100644 --- a/tests/run.php +++ b/tests/run.php @@ -1,6 +1,6 @@ ";