/** * @expectedException \Matryoshka\Model\Exception\RuntimeException */ public function testApplyDeleteWithBadHydrator() { $ar = new ActiveRecordCriteria(); $testId = 1; $this->model->setHydrator(new BadHydrator()); $ar->setId($testId); $ar->applyDelete($this->model); }
public function setUp() { $mongoCollectionMock = $this->getMockBuilder('\\MongoCollection')->disableOriginalConstructor()->setMethods(['save', 'find', 'remove', 'insert', 'update', 'getName'])->getMock(); $mongoCollectionMock->expects($this->any())->method('getName')->will($this->returnValue('testCollection')); self::$sharedDataGateway->__MongoCollectionMockProxy__setMock($mongoCollectionMock); $this->mongoCollectionMock = $mongoCollectionMock; $this->criteria = new ActiveRecordCriteria(); $rs = new ArrayObjectResultSet(); $model = new Model(self::$sharedDataGateway, $rs); $hyd = new ObjectProperty(); $model->setHydrator($hyd); $this->model = $model; }
/** * @expectedException \Matryoshka\Model\Exception\RuntimeException */ public function testExtractValue() { $key = 'foo'; $value = 'baz'; $obj = new \stdClass(); $extratedValue = 'bar'; $criteria = new FindAllCriteria(); $reflection = new \ReflectionClass($criteria); $reflMethod = $reflection->getMethod('extractValue'); $reflMethod->setAccessible(true); $rs = new ArrayObjectResultSet(); $model = new Model($this->mongoCollectionMock, $rs); $hydratorMock = $this->getMock('\\Zend\\Stdlib\\Hydrator\\ObjectProperty', ['extractValue']); $hydratorMock->expects($this->atMost(1))->method('extractValue')->with($this->equalTo($key), $this->equalTo($value), $this->identicalTo($obj))->willReturn($extratedValue); $model->setHydrator($hydratorMock); $this->assertEquals($extratedValue, $reflMethod->invoke($criteria, $model, $key, $value, $obj)); //Test invalid hydrator $rs = new ArrayObjectResultSet(); $model = new Model($this->mongoCollectionMock, $rs); $hyd = new BadHydrator(); $model->setHydrator($hyd); $reflMethod->invoke($criteria, $model, 'foo', 'bar'); }