Skip to content

Commit

Permalink
Merge pull request #19 from matryoshka-model/hotfix-issue-17
Browse files Browse the repository at this point in the history
Fixes #17 AbstractActiveRecord::save() doesn't work on update
  • Loading branch information
leogr committed Oct 21, 2014
2 parents 21ac331 + 8226d2e commit ed46b1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions library/Matryoshka/Model/Object/AbstractActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function save()
}

$criteria = clone $this->activeRecordCriteriaPrototype;
$criteria->setId($this->getId());
$result = $this->getModel()->save($criteria, $this);
return $result;
}
Expand Down
13 changes: 11 additions & 2 deletions tests/MatryoshkaTest/Model/Object/AbstractActiveRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class AbstractActiveRecordTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
$this->object = new ActiveRecordObject();
$this->object->setActiveRecordCriteriaPrototype(new ConcreteCriteria());
$this->criteria = new ConcreteCriteria();
$this->object->setActiveRecordCriteriaPrototype($this->criteria);
}

public function testGetSetModel()
Expand All @@ -38,19 +39,27 @@ public function testGetSetModel()

public function testSave()
{
$id = 'id';
$criteria = clone $this->criteria;
$criteria->setId($id);


$abstractModelMock = $this->getMockBuilder('Matryoshka\Model\AbstractModel')
->disableOriginalConstructor()
->setMethods(['save'])
->getMock();
$result = null;


$abstractModelMock->expects($this->atLeastOnce())
->method('save')
->with($this->isInstanceOf('Matryoshka\Model\Criteria\ActiveRecord\AbstractCriteria'), $this->identicalTo($this->object))
->with($this->equalTo($criteria), $this->identicalTo($this->object))
->will($this->returnValue($result));

$this->object->setModel($abstractModelMock);

//Test with ID
$this->object->setId($id);
$this->assertSame($result, $this->object->save());
}

Expand Down

0 comments on commit ed46b1a

Please sign in to comment.