diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 5c222be6557..72218a65267 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -439,19 +439,7 @@ private function gatherColumn($class, array $mapping, Table $table) $options['columnDefinition'] = $mapping['columnDefinition']; } - if (isset($mapping['options'])) { - $knownOptions = array('comment', 'unsigned', 'fixed', 'default'); - - foreach ($knownOptions as $knownOption) { - if (array_key_exists($knownOption, $mapping['options'])) { - $options[$knownOption] = $mapping['options'][$knownOption]; - - unset($mapping['options'][$knownOption]); - } - } - - $options['customSchemaOptions'] = $mapping['options']; - } + $this->gatherColumnOptions($options, $mapping); if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() == array($mapping['fieldName'])) { $options['autoincrement'] = true; @@ -661,9 +649,7 @@ private function gatherRelationJoinColumns( $columnOptions['notnull'] = !$joinColumn['nullable']; } - if (isset($fieldMapping['options'])) { - $columnOptions['options'] = $fieldMapping['options']; - } + $this->gatherColumnOptions($columnOptions, $fieldMapping); if ($fieldMapping['type'] == "string" && isset($fieldMapping['length'])) { $columnOptions['length'] = $fieldMapping['length']; @@ -871,4 +857,21 @@ public function getUpdateSchemaSql(array $classes, $saveMode = false) return $schemaDiff->toSql($this->platform); } + + private function gatherColumnOptions(array &$options, array $mapping) + { + if (isset($mapping['options'])) { + $knownOptions = array('comment', 'unsigned', 'fixed', 'default'); + + foreach ($knownOptions as $knownOption) { + if (array_key_exists($knownOption, $mapping['options'])) { + $options[$knownOption] = $mapping['options'][$knownOption]; + + unset($mapping['options'][$knownOption]); + } + } + + $options['customSchemaOptions'] = $mapping['options']; + } + } } diff --git a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php index 5930db12c70..731afa7e919 100644 --- a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php +++ b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php @@ -34,7 +34,7 @@ public function __construct(array $resultSet) * * @return array */ - public function fetchAll($fetchStyle = null, $columnIndex = null, array $ctorArgs = null) + public function fetchAll($fetchStyle = null, $columnIndex = null, $ctorArgs = null) { return $this->_resultSet; } @@ -53,7 +53,7 @@ public function fetchColumn($columnNumber = 0) /** * {@inheritdoc} */ - public function fetch($fetchStyle = null) + public function fetch($fetchStyle = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { $current = current($this->_resultSet); next($this->_resultSet); diff --git a/tests/Doctrine/Tests/Mocks/StatementMock.php b/tests/Doctrine/Tests/Mocks/StatementMock.php index 40ad1f3e5f7..902b473acf0 100644 --- a/tests/Doctrine/Tests/Mocks/StatementMock.php +++ b/tests/Doctrine/Tests/Mocks/StatementMock.php @@ -73,14 +73,14 @@ public function setFetchMode($fetchStyle, $arg2 = null, $arg3 = null) /** * {@inheritdoc} */ - public function fetch($fetchStyle = null) + public function fetch($fetchStyle = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { } /** * {@inheritdoc} */ - public function fetchAll($fetchStyle = null) + public function fetchAll($fetchStyle = null, $fetchArgument = null, $ctorArgs = null) { } diff --git a/tests/Doctrine/Tests/Models/Forum/ForumCategory.php b/tests/Doctrine/Tests/Models/Forum/ForumCategory.php index f04f128dce8..d4b03cef9a4 100644 --- a/tests/Doctrine/Tests/Models/Forum/ForumCategory.php +++ b/tests/Doctrine/Tests/Models/Forum/ForumCategory.php @@ -9,7 +9,7 @@ class ForumCategory { /** - * @Column(type="integer") + * @Column(type="guid", options={"fixed":true, "collation":"latin1_bin", "foo":"bar"}) * @Id */ private $id; diff --git a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php index 849f579fa0a..2bae31329e6 100644 --- a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php +++ b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php @@ -54,13 +54,18 @@ public function getMethodParameters() */ public function testAllMethodCallsAreDelegatedToTheWrappedInstance($method, array $parameters) { + $returnedValue = null; + $stub = $this->wrapped ->expects($this->once()) ->method($method) - ->will($this->returnValue('INNER VALUE FROM ' . $method)); + ->willReturnCallback(function () use ($method, &$returnedValue) { + $returnedValue = 'INNER VALUE FROM '.$method; + }); call_user_func_array(array($stub, 'with'), $parameters); + call_user_func_array(array($this->decorator, $method), $parameters); - $this->assertSame('INNER VALUE FROM ' . $method, call_user_func_array(array($this->decorator, $method), $parameters)); + $this->assertSame('INNER VALUE FROM ' . $method, $returnedValue); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index c8b23960c37..fb94c3acafa 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -72,6 +72,39 @@ public function testPassColumnDefinitionToJoinColumn() $this->assertEquals($customColumnDef, $table->getColumn('avatar_id')->getColumnDefinition()); } + public function testPassColumnOptionsToJoinColumn() + { + $em = $this->_getTestEntityManager(); + $schemaTool = new SchemaTool($em); + + $category = $em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumCategory'); + $board = $em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumBoard'); + + $classes = array($category, $board); + + $schema = $schemaTool->getSchemaFromMetadata($classes); + + $this->assertTrue($schema->hasTable('forum_categories')); + $this->assertTrue($schema->hasTable('forum_boards')); + + $tableCategory = $schema->getTable('forum_categories'); + $tableBoard = $schema->getTable('forum_boards'); + + $this->assertTrue($tableBoard->hasColumn('category_id')); + + $this->assertSame( + $tableCategory->getColumn('id')->getFixed(), + $tableBoard->getColumn('category_id')->getFixed(), + 'Target and source columns have different value of option `fixed`' + ); + + $this->assertEquals( + $tableCategory->getColumn('id')->getCustomSchemaOptions(), + $tableBoard->getColumn('category_id')->getCustomSchemaOptions(), + 'Target and source columns have different schema options' + ); + } + /** * @group DDC-283 */