New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapping test improvements #144
Changes from 25 commits
ba511e6
b92b6b2
a197b02
0120fd5
97c90b6
fe8050a
1b0ed9c
84c4c14
f1f6ec7
c42d5d0
3e46d76
5ea8cd3
381ce08
514205d
e06ef56
766ef00
40aae5a
3bbd585
82e6dc8
fec02f4
41039a4
fb0cce4
b6bf172
5e9c90c
35b9990
1c5bbd9
9d594c1
6207513
b1adc86
bd15c45
55bc9fc
d747570
1a4e99b
f30153b
516f928
be92b27
4162a4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -581,9 +581,13 @@ protected function validateAndCompleteReferrersMapping($mapping) | |
|
||
protected function validateAndCompleteFieldMapping($mapping, $isField = true) | ||
{ | ||
if (!isset($mapping['fieldName'])) { | ||
if (!isset($mapping['fieldName']) || empty($mapping['fieldName'])) { | ||
throw new MappingException("Mapping a property requires to specify the fieldName."); | ||
} | ||
|
||
if (!is_string($mapping['fieldName'])) { | ||
throw new MappingException("fieldName must be of type string."); | ||
} | ||
|
||
if ($isField && !isset($mapping['name'])) { | ||
$mapping['name'] = $mapping['fieldName']; | ||
|
@@ -919,6 +923,10 @@ public function mapField(array $mapping) | |
if ($mapping['type'] === 'int') { | ||
$mapping['type'] = 'long'; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be an |
||
if ($mapping['type'] === 'float') { | ||
$mapping['type'] = 'double'; | ||
} | ||
|
||
// Add the field to the list of translatable fields | ||
if (isset($mapping['translated']) && $mapping['translated']) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,14 @@ public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENS | |
*/ | ||
public function loadMetadataForClass($className, ClassMetadata $class) | ||
{ | ||
$xmlRoot = $this->getElement($className); | ||
try { | ||
$xmlRoot = $this->getElement($className); | ||
} | ||
catch(\Doctrine\Common\Persistence\Mapping\MappingException $e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing a space after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh and we usually try to add a use statement to avoid fully qualified names inside the class code |
||
// Convert Exception type for consistency with other drivers | ||
throw new MappingException($e->getMessage(), $e->getCode(), $e->getPrevious()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, you should keep the common MappingException as previous exception instead of stripping it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK.. I added it because the AnnotationDriver throws the specific exception, whereas the XML and YAML drivers throw the common one. I thought it'd be more consistent and easier to test if they all threw the same type, but happy to go with the consensus. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just talking about what you put as previous exception here. But anyway, throwing the common exception is a better idea IMO (or making the MappingException extend the common one) so that some code can catch the common one if it wants to work for any Doctrine project There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I misunderstood. Yep - ATM There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any good reason to have a phpcr specific MappingException? i would assume that it is just that at the time of writing, the exception was not yet moved into the doctrine common but copied for each odm and the orm. @stof i see the orm still has its own MappingException https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Mapping/MappingException.php and it extends from ORMException rather than the common MappingException - is that subject to change? is the exception concept to have a specific tree for each of the backends or should we push that all into common and eliminate the impl specific exceptions? (unless there is some additional info to track in an exception, where you would extend the common exception rather than some sort of base implemenation exception) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improving the ORM exceptions is in the roadmap. Currently, they all extend from the ORMException class, which should probably be changed to an interface instead to be able to extend from other exceptions too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stof is there a jira issue or something describing what you want to do? i guess we should do the same with phpcr-odm. i created http://www.doctrine-project.org/jira/browse/PHPCR-71 to track this further - i think we should not block this pull request by it. having the same behaviour over all 3 mappers is definitively better than having diverging behaviour. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure. |
||
} | ||
|
||
if (!$xmlRoot) { | ||
return; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,14 @@ public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENS | |
*/ | ||
public function loadMetadataForClass($className, ClassMetadata $class) | ||
{ | ||
$element = $this->getElement($className); | ||
try { | ||
$element = $this->getElement($className); | ||
} | ||
catch(\Doctrine\Common\Persistence\Mapping\MappingException $e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above notes |
||
// Convert Exception type for consistency with other drivers | ||
throw new MappingException($e->getMessage(), $e->getCode(), $e->getPrevious()); | ||
} | ||
|
||
if (!$element) { | ||
return; | ||
} | ||
|
@@ -84,7 +91,18 @@ public function loadMetadataForClass($className, ClassMetadata $class) | |
} | ||
} | ||
if (isset($element['id'])) { | ||
$mapping = array('fieldName' => $element['id'], 'id' => true); | ||
if(is_array($element['id'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here again a few CS issues with missing spaces and code that should be on the same line as the closing curly bracket |
||
if(!isset($element['id']['fieldName'])) { | ||
throw new MappingException("Missing fieldName property for id field"); | ||
} | ||
else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, you don't need to use |
||
$fieldName = $element['id']['fieldName']; | ||
} | ||
} | ||
else { | ||
$fieldName = $element['id']; | ||
} | ||
$mapping = array('fieldName' => $fieldName, 'id' => true); | ||
if (isset($element['id']['generator']['strategy'])) { | ||
$mapping['strategy'] = $element['id']['generator']['strategy']; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes
!isset()
redundant .. but did you really mean to also ignore0
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally blank strings were being accepted here, and I assume that's not a valid case. Maybe strlen($mapping['fieldName']) === 0 is better? I'm not really sure what the valid cases are to be honest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah ..
0
probably also doesn't make sense .. so i am fine if you just remove the!isset()
part since its redundant now