Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions lib/Doctrine/Common/Persistence/PersistentObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ public function injectObjectManager(ObjectManager $objectManager, ClassMetadata
*/
private function set($field, $args)
{
$this->initializeDoctrine();

if ($this->cm->hasField($field) && !$this->cm->isIdentifier($field)) {
$this->$field = $args[0];
} else if ($this->cm->hasAssociation($field) && $this->cm->isSingleValuedAssociation($field)) {
Expand All @@ -146,13 +144,11 @@ private function set($field, $args)
*/
private function get($field)
{
$this->initializeDoctrine();

if ( $this->cm->hasField($field) || $this->cm->hasAssociation($field) ) {
return $this->$field;
} else {
throw new \BadMethodCallException("no field with name '".$field."' exists on '".$this->cm->getName()."'");
}

throw new \BadMethodCallException("no field with name '".$field."' exists on '".$this->cm->getName()."'");
}

/**
Expand Down Expand Up @@ -190,8 +186,6 @@ private function completeOwningSide($field, $targetClass, $targetObject)
*/
private function add($field, $args)
{
$this->initializeDoctrine();

if ($this->cm->hasAssociation($field) && $this->cm->isCollectionValuedAssociation($field)) {
$targetClass = $this->cm->getAssociationTargetClass($field);
if (!($args[0] instanceof $targetClass)) {
Expand Down Expand Up @@ -239,6 +233,8 @@ private function initializeDoctrine()
*/
public function __call($method, $args)
{
$this->initializeDoctrine();

$command = substr($method, 0, 3);
$field = lcfirst(substr($method, 3));
if ($command == "set") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public function testGetUnknownField()
$this->object->getUnknown();
}

public function testUndefinedMethod()
{
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage("There is no method");
(new TestObject)->undefinedMethod();
}

public function testGetToOneAssociation()
{
$this->assertNull($this->object->getParent());
Expand Down