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 testApplyDeleteWithBadHydrator()
 {
     $ar = new ActiveRecordCriteria();
     $testId = 1;
     $this->model->setHydrator(new BadHydrator());
     $ar->setId($testId);
     $ar->applyDelete($this->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');
 }
 /**
  * {@inheritdoc}
  */
 public function delete(DeletableCriteriaInterface $criteria)
 {
     $event = $this->getEvent();
     $event->setCriteria($criteria);
     $results = $this->getEventManager()->trigger(ModelEvent::EVENT_DELETE_PRE, $event, function ($r) {
         return is_int($r);
     });
     if ($results->stopped()) {
         $last = $results->last();
         if (null === $last || is_int($last)) {
             $event->setResult($last);
             return $last;
         }
     }
     $event->setResult(parent::delete($event->getCriteria()));
     $results = $this->getEventManager()->trigger(ModelEvent::EVENT_DELETE_POST, $event, function ($r) {
         return is_int($r);
     });
     if ($results->stopped()) {
         $last = $results->last();
         if (null === $last || is_int($last)) {
             $event->setResult($last);
         }
     }
     return $event->getResult();
 }
 public function testConstructorDefaults()
 {
     $this->assertSame($this->resultSet, $this->model->getResultSetPrototype());
     $this->assertSame($this->mockDataGateway, $this->model->getDataGateway());
 }