public function testInterleavedDelete2() { $modelA = $this->serviceManager->get('IsolatedModelA'); $modelB = $this->serviceManager->get('IsolatedModelB'); // ensure document $obj = new IsolatedActiveRecordObject(); $obj->setModel($modelA); $obj->setName('foo'); $obj->save(); //Read from A $criteria = new ActiveRecordCriteria(); $criteria->setId($obj->getId()); $objA = $modelA->find($criteria)->current(); $this->assertInstanceOf('\\MatryoshkaModelWrapperMongoTest\\Integration\\Isolation\\TestAsset\\IsolatedActiveRecordObject', $objA); //Read from B $criteria = new ActiveRecordCriteria(); $criteria->setId($obj->getId()); $objB = $modelB->find($criteria)->current(); $this->assertInstanceOf('\\MatryoshkaModelWrapperMongoTest\\Integration\\Isolation\\TestAsset\\IsolatedActiveRecordObject', $objB); //Delete from A $objA->setName('A'); $this->assertEquals(1, $objA->delete()); //Write from B $this->setExpectedException('\\Matryoshka\\Model\\Wrapper\\Mongo\\Exception\\DocumentModifiedException'); $objB->setName('B'); $objB->delete(); }
/** * @dataProvider getDeletableStatesDataProvider * @param string $state */ public function testDelete($state) { $transaction = $this->createTransactionEntityAsset(); $transaction->setState($state); $transaction->setHydrator(new TransactionHydrator()); $criteria = new ActiveRecordCriteria(); $expectedData = $this->exampleTransactionData; // Insert will inject _id into $expectedData DocumentStore::getSharedInstance()->isolatedUpsert($this->mockProxy, $expectedData); // Populate the object $this->transactionModel->getHydrator()->hydrate($expectedData, $transaction); $criteria->setId($transaction->getId()); $expectedReturn = 1; $this->expectsFindById($expectedData['_id'], $expectedData, $this->at(0)); $this->expectsRemove($expectedData, $this->at(1)); $this->assertSame($expectedReturn, $this->transactionModel->delete($criteria)); }
/** * @param TransactionInterface $transaction * @param $fromState * @param $toState * @param $eventName * @throws DomainException * @throws \Exception */ protected function switchState(TransactionInterface $transaction, $fromState, $toState, $eventName) { try { if (!$transaction->getId()) { throw new DomainException(sprintf('%s: cannot change state from "%s" to "%s" because transaction ID is not present', $eventName, $fromState, $toState)); } if ($transaction->getState() != $fromState) { throw new DomainException(sprintf('%s(%s): cannot change state from "%s" to "%s" because transaction current state is "%s"', $eventName, $transaction->getId(), $fromState, $toState, $transaction->getState())); } $criteria = new ActiveRecordCriteria(); $criteria->setId($transaction->getId()); $event = $this->getEvent(); $event->setCriteria($criteria); $event->setParam('data', $transaction); $event->setTransaction($transaction); $this->getEventManager()->trigger($eventName . '.pre', $event); // TODO: understand what happens if event propagation is stopped $transaction->setState($toState); //FIXME: mismatching type from $criteria to parameter needed from method isolatedSave $this->isolatedSave($criteria, $transaction); $this->getEventManager()->trigger($eventName . '.post', $event); } catch (\Exception $e) { $transaction->setError(new ErrorObject($e)); throw $e; } }
/** * @expectedException \Matryoshka\Model\Exception\RuntimeException */ public function testApplyDeleteWithoutId() { $this->criteria->applyDelete($this->model); }