Skip to content

Commit

Permalink
entity: fix setReadOnlyValue on IPropertyContainer [closes #130]
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikulas authored and hrach committed Oct 23, 2015
1 parent 8323893 commit 8f47862
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Relationships/OneHasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ protected function createCollection()
protected function updateRelationshipAdd(IEntity $entity)
{
$this->updatingReverseRelationship = TRUE;
$entity->setValue($this->metadata->relationship->property, $this->parent);
$entity->getProperty($this->metadata->relationship->property)->setInjectedValue($this->parent);
$this->updatingReverseRelationship = FALSE;
}


protected function updateRelationshipRemove(IEntity $entity)
{
$this->updatingReverseRelationship = TRUE;
$entity->setValue($this->metadata->relationship->property, NULL);
$entity->getProperty($this->metadata->relationship->property)->setInjectedValue(NULL);
$this->updatingReverseRelationship = FALSE;
}

Expand Down
41 changes: 41 additions & 0 deletions tests/cases/integration/Entity/entity.setReadOnlyValue().phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* @testCase
* @dataProvider ../../../sections.ini
*/

namespace NextrasTests\Orm\Integration\Entity;

use Mockery;
use NextrasTests\Orm\DataTestCase;
use NextrasTests\Orm\Ean;
use NextrasTests\Orm\TagFollower;
use Tester\Assert;

$dic = require_once __DIR__ . '/../../../bootstrap.php';


class EntitySetReadOnlyValueTest extends DataTestCase
{

public function testWithIPropertyContainer()
{
$tagA = $this->orm->tags->getById(1);
$tagB = $this->orm->tags->getById(2);

$follower = new TagFollower();
$follower->tag = $tagA;

$follower->getMetadata()->getProperty('tag')->isReadonly = TRUE;

$follower->setReadOnlyValue('tag', $tagB);

Assert::same($tagB, $follower->tag);
}

}


$test = new EntitySetReadOnlyValueTest($dic);
$test->run();

0 comments on commit 8f47862

Please sign in to comment.