Skip to content

Commit

Permalink
Merge pull request #2905 from jeremy-smith-maco/custom-type-comment-r…
Browse files Browse the repository at this point in the history
…egex

Fixes custom type comment regex

Fixes: #2596
Replaces: #2679
  • Loading branch information
lcobucci authored Nov 19, 2017
2 parents 51bf0ae + 22844d3 commit ea968df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ public function getSchemaSearchPaths()
*/
public function extractDoctrineTypeFromComment($comment, $currentType)
{
if (preg_match("(\(DC2Type:([a-zA-Z0-9_]+)\))", $comment, $match)) {
if (preg_match("(\(DC2Type:(((?!\)).)+)\))", $comment, $match)) {
$currentType = $match[1];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1334,4 +1334,30 @@ public function testComparatorShouldNotAddCommentToJsonTypeSinceItIsTheDefaultNo

self::assertFalse($tableDiff);
}

/**
* @dataProvider commentsProvider
*
* @group 2596
*/
public function testExtractDoctrineTypeFromComment(string $comment, string $expected, string $currentType) : void
{
$result = $this->_sm->extractDoctrineTypeFromComment($comment, $currentType);

self::assertSame($expected, $result);
}

public function commentsProvider() : array
{
$currentType = 'current type';

return [
'invalid custom type comments' => ['should.return.current.type', $currentType, $currentType],
'valid doctrine type' => ['(DC2Type:guid)', 'guid', $currentType],
'valid with dots' => ['(DC2Type:type.should.return)', 'type.should.return', $currentType],
'valid with namespace' => ['(DC2Type:Namespace\Class)', 'Namespace\Class', $currentType],
'valid with extra closing bracket' => ['(DC2Type:should.stop)).before)', 'should.stop', $currentType],
'valid with extra opening brackets' => ['(DC2Type:should((.stop)).before)', 'should((.stop', $currentType],
];
}
}

0 comments on commit ea968df

Please sign in to comment.